Class | Sequel::ADO::Database |
In: |
lib/sequel/adapters/ado.rb
|
Parent: | Sequel::Database |
DISCONNECT_ERROR_RE | = | /Communication link failure/ |
CommandTimeout | = | opts[:command_timeout] if opts[:command_timeout] |
Provider | = | opts[:provider] if opts[:provider] |
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. If this property is not set, the default of 30 seconds is used. |
: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 would break backwards compatability.
# File lib/sequel/adapters/ado.rb, line 33 33: def connect(server) 34: opts = server_opts(server) 35: s = opts[:conn_string] || "driver=#{opts[:driver]};server=#{opts[:host]};database=#{opts[:database]}#{";uid=#{opts[:user]};pwd=#{opts[:password]}" if opts[:user]}" 36: handle = WIN32OLE.new('ADODB.Connection') 37: handle.CommandTimeout = opts[:command_timeout] if opts[:command_timeout] 38: handle.Provider = opts[:provider] if opts[:provider] 39: handle.Open(s) 40: handle 41: end
# File lib/sequel/adapters/ado.rb, line 43 43: def disconnect_connection(conn) 44: conn.Close 45: rescue WIN32OLERuntimeError 46: nil 47: end
# File lib/sequel/adapters/ado.rb, line 75 75: def execute(sql, opts=OPTS) 76: synchronize(opts[:server]) do |conn| 77: begin 78: r = log_connection_yield(sql, conn){conn.Execute(sql)} 79: yield(r) if block_given? 80: rescue ::WIN32OLERuntimeError => e 81: raise_error(e) 82: end 83: end 84: nil 85: 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 63 63: def execute_dui(sql, opts=OPTS) 64: return super if opts[:provider] 65: synchronize(opts[:server]) do |conn| 66: begin 67: log_connection_yield(sql, conn){conn.Execute(sql, 1)} 68: WIN32OLE::ARGV[1] 69: rescue ::WIN32OLERuntimeError => e 70: raise_error(e) 71: end 72: end 73: end