# File lib/sequel/adapters/ado.rb, line 11 11: def initialize(opts) 12: super 13: case @opts[:conn_string] 14: when /Microsoft\.(Jet|ACE)\.OLEDB/o 15: Sequel.ts_require 'adapters/shared/access' 16: extend Sequel::Access::DatabaseMethods 17: extend_datasets(Sequel::Access::DatasetMethods) 18: else 19: @opts[:driver] ||= 'SQL Server' 20: case @opts[:driver] 21: when 'SQL Server' 22: Sequel.ts_require 'adapters/ado/mssql' 23: extend Sequel::ADO::MSSQL::DatabaseMethods 24: @dataset_class = ADO::MSSQL::Dataset 25: set_mssql_unicode_strings 26: end 27: end 28: end
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 50 50: def connect(server) 51: opts = server_opts(server) 52: s = opts[:conn_string] || "driver=#{opts[:driver]};server=#{opts[:host]};database=#{opts[:database]}#{";uid=#{opts[:user]};pwd=#{opts[:password]}" if opts[:user]}" 53: handle = WIN32OLE.new('ADODB.Connection') 54: handle.CommandTimeout = opts[:command_timeout] if opts[:command_timeout] 55: handle.Provider = opts[:provider] if opts[:provider] 56: handle.Open(s) 57: handle 58: end
# File lib/sequel/adapters/ado.rb, line 60 60: def execute(sql, opts={}) 61: synchronize(opts[:server]) do |conn| 62: begin 63: r = log_yield(sql){conn.Execute(sql)} 64: yield(r) if block_given? 65: rescue ::WIN32OLERuntimeError => e 66: raise_error(e) 67: end 68: end 69: nil 70: end
The ADO adapter’s default provider doesn’t support transactions, since it creates a new native connection for each query. So Sequel only attempts to use transactions if an explicit :provider is given.
# File lib/sequel/adapters/ado.rb, line 78 78: def begin_transaction(conn, opts={}) 79: super if @opts[:provider] 80: end
# File lib/sequel/adapters/ado.rb, line 82 82: def commit_transaction(conn, opts={}) 83: super if @opts[:provider] 84: end
# File lib/sequel/adapters/ado.rb, line 86 86: def database_error_classes 87: [::WIN32OLERuntimeError] 88: end
# File lib/sequel/adapters/ado.rb, line 90 90: def disconnect_connection(conn) 91: conn.Close 92: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.