Class Sequel::TinyTDS::Database
In: lib/sequel/adapters/tinytds.rb
Parent: Sequel::Database

Methods

Included Modules

Sequel::MSSQL::DatabaseMethods

Public Instance methods

Transfer the :user option to the :username option.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 11
11:       def connect(server)
12:         opts = server_opts(server)
13:         opts[:username] = opts[:user]
14:         c = TinyTds::Client.new(opts)
15:         c.query_options.merge!(:cache_rows=>false)
16: 
17:         if (ts = opts[:textsize])
18:           sql = "SET TEXTSIZE #{typecast_value_integer(ts)}"
19:           log_yield(sql){c.execute(sql)}
20:         end
21:       
22:         c
23:       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.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 31
31:       def execute(sql, opts=OPTS)
32:         synchronize(opts[:server]) do |c|
33:           begin
34:             m = opts[:return]
35:             r = nil
36:             if (args = opts[:arguments]) && !args.empty?
37:               types = []
38:               values = []
39:               args.each_with_index do |(k, v), i|
40:                 v, type = ps_arg_type(v)
41:                 types << "@#{k} #{type}"
42:                 values << "@#{k} = #{v}"
43:               end
44:               case m
45:               when :do
46:                 sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows"
47:                 single_value = true
48:               when :insert
49:                 sql = "#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
50:                 single_value = true
51:               end
52:               sql = "EXEC sp_executesql N'#{c.escape(sql)}', N'#{c.escape(types.join(', '))}', #{values.join(', ')}"
53:               log_yield(sql) do
54:                 r = c.execute(sql)
55:                 r.each{|row| return row.values.first} if single_value
56:               end
57:             else
58:               log_yield(sql) do
59:                 r = c.execute(sql)
60:                 return r.send(m) if m
61:               end
62:             end
63:             yield(r) if block_given?
64:           rescue TinyTds::Error => e
65:             raise_error(e, :disconnect=>!c.active?)
66:           ensure
67:            r.cancel if r && c.sqlsent?
68:           end
69:         end
70:       end

Execute the DDL sql on the database and return nil.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 84
84:       def execute_ddl(sql, opts=OPTS)
85:         execute(sql, opts.merge(:return=>:each))
86:         nil
87:       end

Return the number of rows modified by the given sql.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 73
73:       def execute_dui(sql, opts=OPTS)
74:         execute(sql, opts.merge(:return=>:do))
75:       end

Return the value of the autogenerated primary key (if any) for the row inserted by the given sql.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 79
79:       def execute_insert(sql, opts=OPTS)
80:         execute(sql, opts.merge(:return=>:insert))
81:       end

[Validate]