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

Methods

Included Modules

Sequel::MSSQL::DatabaseMethods

Public Instance methods

Transfer the :host and :user options to the :dataserver and :username options.

[Source]

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

Execute the DDL sql on the database and return nil.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 78
78:       def execute_ddl(sql, opts={})
79:         execute(sql, opts.merge(:return=>:each))
80:         nil
81:       end

Return the number of rows modified by the given sql.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 67
67:       def execute_dui(sql, opts={})
68:         execute(sql, opts.merge(:return=>:do))
69:       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 73
73:       def execute_insert(sql, opts={})
74:         execute(sql, opts.merge(:return=>:insert))
75:       end

[Validate]