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

Methods

Included Modules

Sequel::MSSQL::DatabaseMethods

Constants

TINYTDS_DISCONNECT_ERRORS = /\A(Attempt to initiate a new Adaptive Server operation with results pending|The request failed to run because the batch is aborted, this can be caused by abort signal sent from client|Adaptive Server connection timed out)/

Public Instance methods

Transfer the :user option to the :username option.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 13
13:       def connect(server)
14:         opts = server_opts(server)
15:         opts[:username] = opts[:user]
16:         c = TinyTds::Client.new(opts)
17:         c.query_options.merge!(:cache_rows=>false)
18: 
19:         if (ts = opts[:textsize])
20:           sql = "SET TEXTSIZE #{typecast_value_integer(ts)}"
21:           log_connection_yield(sql, c){c.execute(sql)}
22:         end
23:       
24:         c
25:       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 33
33:       def execute(sql, opts=OPTS)
34:         synchronize(opts[:server]) do |c|
35:           begin
36:             m = opts[:return]
37:             r = nil
38:             if (args = opts[:arguments]) && !args.empty?
39:               types = []
40:               values = []
41:               args.each_with_index do |(k, v), i|
42:                 v, type = ps_arg_type(v)
43:                 types << "@#{k} #{type}"
44:                 values << "@#{k} = #{v}"
45:               end
46:               case m
47:               when :do
48:                 sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows"
49:                 single_value = true
50:               when :insert
51:                 sql = "#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
52:                 single_value = true
53:               end
54:               sql = "EXEC sp_executesql N'#{c.escape(sql)}', N'#{c.escape(types.join(', '))}', #{values.join(', ')}"
55:               log_connection_yield(sql, c) do
56:                 r = c.execute(sql)
57:                 r.each{|row| return row.values.first} if single_value
58:               end
59:             else
60:               log_connection_yield(sql, c) do
61:                 r = c.execute(sql)
62:                 return r.send(m) if m
63:               end
64:             end
65:             yield(r) if block_given?
66:           rescue TinyTds::Error => e
67:             raise_error(e, :disconnect=>!c.active?)
68:           ensure
69:             r.cancel if r && c.sqlsent? && c.active?
70:           end
71:         end
72:       end

Execute the DDL sql on the database and return nil.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 90
90:       def execute_ddl(sql, opts=OPTS)
91:         opts = Hash[opts]
92:         opts[:return] = :each
93:         execute(sql, opts)
94:         nil
95:       end

Return the number of rows modified by the given sql.

[Source]

    # File lib/sequel/adapters/tinytds.rb, line 75
75:       def execute_dui(sql, opts=OPTS)
76:         opts = Hash[opts]
77:         opts[:return] = :do
78:         execute(sql, opts)
79:       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 83
83:       def execute_insert(sql, opts=OPTS)
84:         opts = Hash[opts]
85:         opts[:return] = :insert
86:         execute(sql, opts)
87:       end

[Validate]