class Sequel::ADO::Database

Constants

CommandTimeout
Provider

Attributes

conversion_procs[R]

Public Instance Methods

connect(server) click to toggle source

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
106 def connect(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
disconnect_connection(conn) click to toggle source
    # File lib/sequel/adapters/ado.rb
116 def disconnect_connection(conn)
117   conn.Close
118 rescue WIN32OLERuntimeError
119   nil
120 end
execute(sql, opts=OPTS) { |r| ... } click to toggle source
    # File lib/sequel/adapters/ado.rb
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
execute_ddl(sql, opts=OPTS) click to toggle source

Just execute so it doesn't attempt to return the number of rows modified.

    # File lib/sequel/adapters/ado.rb
128 def execute_ddl(sql, opts=OPTS)
129   execute(sql, opts)
130 end
execute_dui(sql, opts=OPTS) click to toggle source

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

Calls superclass method Sequel::Database#execute_dui
    # File lib/sequel/adapters/ado.rb
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
execute_insert(sql, opts=OPTS) click to toggle source

Just execute so it doesn't attempt to return the number of rows modified.

    # File lib/sequel/adapters/ado.rb
133 def execute_insert(sql, opts=OPTS)
134   execute(sql, opts)
135 end
freeze() click to toggle source
Calls superclass method Sequel::Database#freeze
    # File lib/sequel/adapters/ado.rb
122 def freeze
123   @conversion_procs.freeze
124   super
125 end

Private Instance Methods

adapter_initialize() click to toggle source
Calls superclass method Sequel::Database#adapter_initialize
    # File lib/sequel/adapters/ado.rb
174 def adapter_initialize
175   case @opts[:conn_string]
176   when /Microsoft\.(Jet|ACE)\.OLEDB/io
177     require_relative 'ado/access'
178     extend Sequel::ADO::Access::DatabaseMethods
179     self.dataset_class = ADO::Access::Dataset
180   else
181     @opts[:driver] ||= 'SQL Server'
182     case @opts[:driver]
183     when 'SQL Server'
184       require_relative 'ado/mssql'
185       extend Sequel::ADO::MSSQL::DatabaseMethods
186       self.dataset_class = ADO::MSSQL::Dataset
187       set_mssql_unicode_strings
188     end
189   end
190 
191   @conversion_procs = CONVERSION_PROCS.dup
192 
193   super
194 end
begin_transaction(conn, opts=OPTS) click to toggle source

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.

Calls superclass method Sequel::Database#begin_transaction
    # File lib/sequel/adapters/ado.rb
203 def begin_transaction(conn, opts=OPTS)
204   super if @opts[:provider]
205 end
commit_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#commit_transaction
    # File lib/sequel/adapters/ado.rb
207 def commit_transaction(conn, opts=OPTS)
208   super if @opts[:provider]
209 end
database_error_classes() click to toggle source
    # File lib/sequel/adapters/ado.rb
211 def database_error_classes
212   [::WIN32OLERuntimeError]
213 end
dataset_class_default() click to toggle source
    # File lib/sequel/adapters/ado.rb
196 def dataset_class_default
197   Dataset
198 end
disconnect_error?(e, opts) click to toggle source
Calls superclass method Sequel::Database#disconnect_error?
    # File lib/sequel/adapters/ado.rb
215 def disconnect_error?(e, opts)
216   super || (e.is_a?(::WIN32OLERuntimeError) && e.message =~ /Communication link failure/)
217 end
rollback_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#rollback_transaction
    # File lib/sequel/adapters/ado.rb
219 def rollback_transaction(conn, opts=OPTS)
220   super if @opts[:provider]
221 end