Transfer the :user option to the :username option.
# File lib/sequel/adapters/tinytds.rb, line 11 11: def connect(server) 12: opts = server_opts(server) 13: opts[:username] = opts[:user] 14: set_mssql_unicode_strings 15: TinyTds::Client.new(opts) 16: 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 24 24: def execute(sql, opts={}) 25: synchronize(opts[:server]) do |c| 26: begin 27: m = opts[:return] 28: r = nil 29: if (args = opts[:arguments]) && !args.empty? 30: types = [] 31: values = [] 32: args.each_with_index do |(k, v), i| 33: v, type = ps_arg_type(v) 34: types << "@#{k} #{type}" 35: values << "@#{k} = #{v}" 36: end 37: case m 38: when :do 39: sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows" 40: single_value = true 41: when :insert 42: sql = "#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident" 43: single_value = true 44: end 45: sql = "EXEC sp_executesql N'#{c.escape(sql)}', N'#{c.escape(types.join(', '))}', #{values.join(', ')}" 46: log_yield(sql) do 47: r = c.execute(sql) 48: r.each{|row| return row.values.first} if single_value 49: end 50: else 51: log_yield(sql) do 52: r = c.execute(sql) 53: return r.send(m) if m 54: end 55: end 56: yield(r) if block_given? 57: rescue TinyTds::Error => e 58: raise_error(e, :disconnect=>!c.active?) 59: ensure 60: r.cancel if r && c.sqlsent? 61: end 62: end 63: end
Execute the DDL sql on the database and return nil.
# File lib/sequel/adapters/tinytds.rb, line 77 77: def execute_ddl(sql, opts={}) 78: execute(sql, opts.merge(:return=>:each)) 79: nil 80: end
For some reason, unless you specify a column can be NULL, it assumes NOT NULL, so turn NULL on by default unless the column is a primary key column.
# File lib/sequel/adapters/tinytds.rb, line 87 87: def column_list_sql(g) 88: pks = [] 89: g.constraints.each{|c| pks = c[:columns] if c[:type] == :primary_key} 90: g.columns.each{|c| c[:null] = true if !pks.include?(c[:name]) && !c[:primary_key] && !c.has_key?(:null) && !c.has_key?(:allow_null)} 91: super 92: end
tiny_tds uses TinyTds::Error as the base error class.
# File lib/sequel/adapters/tinytds.rb, line 95 95: def database_error_classes 96: [TinyTds::Error] 97: end
Close the TinyTds::Client object.
# File lib/sequel/adapters/tinytds.rb, line 100 100: def disconnect_connection(c) 101: c.close 102: end
Return true if the :conn argument is present and not active.
# File lib/sequel/adapters/tinytds.rb, line 105 105: def disconnect_error?(e, opts) 106: super || (opts[:conn] && !opts[:conn].active?) 107: end
Return a 2 element array with the literal value and type to use in the prepared statement call for the given value and connection.
# File lib/sequel/adapters/tinytds.rb, line 111 111: def ps_arg_type(v) 112: case v 113: when Fixnum 114: [v, 'int'] 115: when Bignum 116: [v, 'bigint'] 117: when Float 118: [v, 'double precision'] 119: when Numeric 120: [v, 'numeric'] 121: when Time 122: if v.is_a?(SQLTime) 123: [literal(v), 'time'] 124: else 125: [literal(v), 'datetime'] 126: end 127: when DateTime 128: [literal(v), 'datetime'] 129: when Date 130: [literal(v), 'date'] 131: when nil 132: ['NULL', 'nvarchar(max)'] 133: when true 134: ['1', 'int'] 135: when false 136: ['0', 'int'] 137: when SQL::Blob 138: [literal(v), 'varbinary(max)'] 139: else 140: [literal(v), 'nvarchar(max)'] 141: end 142: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.