Class | Sequel::TinyTDS::Database |
In: |
lib/sequel/adapters/tinytds.rb
|
Parent: | Sequel::Database |
Choose whether to use unicode strings on initialization
# File lib/sequel/adapters/tinytds.rb, line 11 11: def initialize(*) 12: super 13: set_mssql_unicode_strings 14: end
Transfer the :user option to the :username option.
# File lib/sequel/adapters/tinytds.rb, line 17 17: def connect(server) 18: opts = server_opts(server) 19: opts[:username] = opts[:user] 20: c = TinyTds::Client.new(opts) 21: 22: if (ts = opts[:textsize]) 23: sql = "SET TEXTSIZE #{typecast_value_integer(ts)}" 24: log_yield(sql){c.execute(sql)} 25: end 26: 27: c 28: end
Execute the given sql on the server. If the :return option is present, its value should be a method symbol that is called on the TinyTds::Result object returned from executing the sql. The value of such a method is returned to the caller. Otherwise, if a block is given, it is yielded the result object. If no block is given and a :return is not present, nil is returned.
# File lib/sequel/adapters/tinytds.rb, line 36 36: def execute(sql, opts={}) 37: synchronize(opts[:server]) do |c| 38: begin 39: m = opts[:return] 40: r = nil 41: if (args = opts[:arguments]) && !args.empty? 42: types = [] 43: values = [] 44: args.each_with_index do |(k, v), i| 45: v, type = ps_arg_type(v) 46: types << "@#{k} #{type}" 47: values << "@#{k} = #{v}" 48: end 49: case m 50: when :do 51: sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows" 52: single_value = true 53: when :insert 54: sql = "#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident" 55: single_value = true 56: end 57: sql = "EXEC sp_executesql N'#{c.escape(sql)}', N'#{c.escape(types.join(', '))}', #{values.join(', ')}" 58: log_yield(sql) do 59: r = c.execute(sql) 60: r.each{|row| return row.values.first} if single_value 61: end 62: else 63: log_yield(sql) do 64: r = c.execute(sql) 65: return r.send(m) if m 66: end 67: end 68: yield(r) if block_given? 69: rescue TinyTds::Error => e 70: raise_error(e, :disconnect=>!c.active?) 71: ensure 72: r.cancel if r && c.sqlsent? 73: end 74: end 75: end
Execute the DDL sql on the database and return nil.
# File lib/sequel/adapters/tinytds.rb, line 89 89: def execute_ddl(sql, opts={}) 90: execute(sql, opts.merge(:return=>:each)) 91: nil 92: end
Return the number of rows modified by the given sql.
# File lib/sequel/adapters/tinytds.rb, line 78 78: def execute_dui(sql, opts={}) 79: execute(sql, opts.merge(:return=>:do)) 80: end