| Class | Sequel::ADO::Database |
| In: |
lib/sequel/adapters/ado.rb
|
| Parent: | Sequel::Database |
| CommandTimeout | = | opts[:command_timeout] if opts[:command_timeout] |
| Provider | = | opts[:provider] if opts[:provider] |
| conversion_procs | [R] |
In addition to the usual database options, the following options have an effect:
| :command_timeout : | Sets the time in seconds to wait while attempting to execute a command before cancelling the attempt and generating an error. Specifically, it sets the ADO CommandTimeout property. |
| :driver : | The driver to use in the ADO connection string. If not provided, a default of "SQL Server" is used. |
| :conn_string : | The full ADO connection string. If this is provided, the usual options are ignored. |
| :provider : | Sets the Provider of this ADO connection (for example, "SQLOLEDB"). If you don‘t specify a provider, the default one used by WIN32OLE has major problems, such as creating a new native database connection for every query, which breaks things such as temporary tables. |
Pay special attention to the :provider option, as without specifying a provider, many things will be broken. The SQLNCLI10 provider appears to work well if you are connecting to Microsoft SQL Server, but it is not the default as that is not always available and would break backwards compatability.
# File lib/sequel/adapters/ado.rb, line 106
106: def connectconnectconnectconnectconnect(server)
107: opts = server_opts(server)
108: s = opts[:conn_string] || "driver=#{opts[:driver]};server=#{opts[:host]};database=#{opts[:database]}#{";uid=#{opts[:user]};pwd=#{opts[:password]}" if opts[:user]}"
109: handle = WIN32OLE.new('ADODB.Connection')
110: handle.CommandTimeout = opts[:command_timeout] if opts[:command_timeout]
111: handle.Provider = opts[:provider] if opts[:provider]
112: handle.Open(s)
113: handle
114: end
# File lib/sequel/adapters/ado.rb, line 116
116: def disconnect_connection(conn)
117: conn.Close
118: rescue WIN32OLERuntimeError
119: nil
120: end
# File lib/sequel/adapters/ado.rb, line 153
153: def execute(sql, opts=OPTS)
154: synchronize(opts[:server]) do |conn|
155: begin
156: r = log_connection_yield(sql, conn){conn.Execute(sql)}
157: begin
158: yield r if block_given?
159: ensure
160: begin
161: r.close
162: rescue ::WIN32OLERuntimeError
163: end
164: end
165: rescue ::WIN32OLERuntimeError => e
166: raise_error(e)
167: end
168: end
169: nil
170: end
Use pass by reference in WIN32OLE to get the number of affected rows, unless is a provider is in use (since some providers don‘t seem to return the number of affected rows, but the default provider appears to).
# File lib/sequel/adapters/ado.rb, line 141
141: def execute_dui(sql, opts=OPTS)
142: return super if opts[:provider]
143: synchronize(opts[:server]) do |conn|
144: begin
145: log_connection_yield(sql, conn){conn.Execute(sql, 1)}
146: WIN32OLE::ARGV[1]
147: rescue ::WIN32OLERuntimeError => e
148: raise_error(e)
149: end
150: end
151: end