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
112 def connect(server)
113   opts = server_opts(server)
114   s = opts[:conn_string] || "driver=#{opts[:driver]};server=#{opts[:host]};database=#{opts[:database]}#{";uid=#{opts[:user]};pwd=#{opts[:password]}" if opts[:user]}"
115   handle = WIN32OLE.new('ADODB.Connection')
116   handle.CommandTimeout = opts[:command_timeout] if opts[:command_timeout]
117   handle.Provider = opts[:provider] if opts[:provider]
118   handle.Open(s)
119   handle
120 end
disconnect_connection(conn) click to toggle source
    # File lib/sequel/adapters/ado.rb
122 def disconnect_connection(conn)
123   conn.Close
124 rescue WIN32OLERuntimeError
125   nil
126 end
execute(sql, opts=OPTS) { |r| ... } click to toggle source
    # File lib/sequel/adapters/ado.rb
159 def execute(sql, opts=OPTS)
160   synchronize(opts[:server]) do |conn|
161     begin
162       r = log_connection_yield(sql, conn){conn.Execute(sql)}
163       begin
164         yield r if block_given?
165       ensure
166         begin
167           r.close
168         rescue ::WIN32OLERuntimeError
169         end
170       end
171     rescue ::WIN32OLERuntimeError => e
172       raise_error(e)
173     end
174   end
175   nil
176 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
134 def execute_ddl(sql, opts=OPTS)
135   execute(sql, opts)
136 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
147 def execute_dui(sql, opts=OPTS)
148   return super if opts[:provider]
149   synchronize(opts[:server]) do |conn|
150     begin
151       log_connection_yield(sql, conn){conn.Execute(sql, 1)}
152       WIN32OLE::ARGV[1]
153     rescue ::WIN32OLERuntimeError => e
154       raise_error(e)
155     end
156   end
157 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
139 def execute_insert(sql, opts=OPTS)
140   execute(sql, opts)
141 end
freeze() click to toggle source
Calls superclass method Sequel::Database#freeze
    # File lib/sequel/adapters/ado.rb
128 def freeze
129   @conversion_procs.freeze
130   super
131 end

Private Instance Methods

adapter_initialize() click to toggle source
Calls superclass method Sequel::Database#adapter_initialize
    # File lib/sequel/adapters/ado.rb
180 def adapter_initialize
181   case @opts[:conn_string]
182   when /Microsoft\.(Jet|ACE)\.OLEDB/io
183     require_relative 'ado/access'
184     extend Sequel::ADO::Access::DatabaseMethods
185     self.dataset_class = ADO::Access::Dataset
186   else
187     @opts[:driver] ||= 'SQL Server'
188     case @opts[:driver]
189     when 'SQL Server'
190       require_relative 'ado/mssql'
191       extend Sequel::ADO::MSSQL::DatabaseMethods
192       self.dataset_class = ADO::MSSQL::Dataset
193       set_mssql_unicode_strings
194     end
195   end
196 
197   @conversion_procs = CONVERSION_PROCS.dup
198 
199   super
200 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
209 def begin_transaction(conn, opts=OPTS)
210   super if @opts[:provider]
211 end
commit_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#commit_transaction
    # File lib/sequel/adapters/ado.rb
213 def commit_transaction(conn, opts=OPTS)
214   super if @opts[:provider]
215 end
database_error_classes() click to toggle source
    # File lib/sequel/adapters/ado.rb
217 def database_error_classes
218   [::WIN32OLERuntimeError]
219 end
dataset_class_default() click to toggle source
    # File lib/sequel/adapters/ado.rb
202 def dataset_class_default
203   Dataset
204 end
disconnect_error?(e, opts) click to toggle source
Calls superclass method Sequel::Database#disconnect_error?
    # File lib/sequel/adapters/ado.rb
221 def disconnect_error?(e, opts)
222   super || (e.is_a?(::WIN32OLERuntimeError) && e.message =~ /Communication link failure/)
223 end
rollback_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#rollback_transaction
    # File lib/sequel/adapters/ado.rb
225 def rollback_transaction(conn, opts=OPTS)
226   super if @opts[:provider]
227 end