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 defined?(yield)
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   @conversion_procs[AdDBTimeStamp] = method(:adb_timestamp_to_application_timestamp)
199 
200   super
201 end
adb_timestamp_to_application_timestamp(v) click to toggle source
    # File lib/sequel/adapters/ado.rb
203 def adb_timestamp_to_application_timestamp(v)
204   # This hard codes a timestamp_precision of 6 when converting.
205   # That is the default timestamp_precision, but the ado/mssql adapter uses a timestamp_precision
206   # of 3.  However, timestamps returned by ado/mssql have nsec values that end up rounding to a
207   # the same value as if a timestamp_precision of 3 was hard coded (either xxx999yzz, where y is
208   # 5-9 or xxx000yzz where y is 0-4).
209   #
210   # ADO subadapters should override this they would like a different timestamp precision and the
211   # this code does not work for them (for example, if they provide full nsec precision).
212   #
213   # Note that fractional second handling for WIN32OLE objects is not correct on ruby <2.2
214   to_application_timestamp([v.year, v.month, v.day, v.hour, v.min, v.sec, (v.nsec/1000.0).round * 1000])
215 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
224 def begin_transaction(conn, opts=OPTS)
225   super if @opts[:provider]
226 end
commit_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#commit_transaction
    # File lib/sequel/adapters/ado.rb
228 def commit_transaction(conn, opts=OPTS)
229   super if @opts[:provider]
230 end
database_error_classes() click to toggle source
    # File lib/sequel/adapters/ado.rb
232 def database_error_classes
233   [::WIN32OLERuntimeError]
234 end
dataset_class_default() click to toggle source
    # File lib/sequel/adapters/ado.rb
217 def dataset_class_default
218   Dataset
219 end
disconnect_error?(e, opts) click to toggle source
Calls superclass method Sequel::Database#disconnect_error?
    # File lib/sequel/adapters/ado.rb
236 def disconnect_error?(e, opts)
237   super || (e.is_a?(::WIN32OLERuntimeError) && e.message =~ /Communication link failure/)
238 end
rollback_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#rollback_transaction
    # File lib/sequel/adapters/ado.rb
240 def rollback_transaction(conn, opts=OPTS)
241   super if @opts[:provider]
242 end