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:         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.

[Source]

    # 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.

[Source]

    # 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

Return the number of rows modified by the given sql.

[Source]

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

[Validate]