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

    # 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/i
183     # SEQUEL6: Remove
184     require_relative 'ado/access'
185     extend Sequel::ADO::Access::DatabaseMethods
186     self.dataset_class = ADO::Access::Dataset
187   else
188     @opts[:driver] ||= 'SQL Server'
189     case @opts[:driver]
190     when 'SQL Server'
191       require_relative 'ado/mssql'
192       extend Sequel::ADO::MSSQL::DatabaseMethods
193       self.dataset_class = ADO::MSSQL::Dataset
194       set_mssql_unicode_strings
195     end
196   end
197 
198   @conversion_procs = CONVERSION_PROCS.dup
199   @conversion_procs[AdDBTimeStamp] = method(:adb_timestamp_to_application_timestamp)
200 
201   super
202 end
adb_timestamp_to_application_timestamp(v) click to toggle source
    # File lib/sequel/adapters/ado.rb
204 def adb_timestamp_to_application_timestamp(v)
205   # This hard codes a timestamp_precision of 6 when converting.
206   # That is the default timestamp_precision, but the ado/mssql adapter uses a timestamp_precision
207   # of 3.  However, timestamps returned by ado/mssql have nsec values that end up rounding to a
208   # the same value as if a timestamp_precision of 3 was hard coded (either xxx999yzz, where y is
209   # 5-9 or xxx000yzz where y is 0-4).
210   #
211   # ADO subadapters should override this they would like a different timestamp precision and the
212   # this code does not work for them (for example, if they provide full nsec precision).
213   #
214   # Note that fractional second handling for WIN32OLE objects is not correct on ruby <2.2
215   to_application_timestamp([v.year, v.month, v.day, v.hour, v.min, v.sec, (v.nsec/1000.0).round * 1000])
216 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
225 def begin_transaction(conn, opts=OPTS)
226   super if @opts[:provider]
227 end
commit_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#commit_transaction
    # File lib/sequel/adapters/ado.rb
229 def commit_transaction(conn, opts=OPTS)
230   super if @opts[:provider]
231 end
database_error_classes() click to toggle source
    # File lib/sequel/adapters/ado.rb
233 def database_error_classes
234   [::WIN32OLERuntimeError]
235 end
dataset_class_default() click to toggle source
    # File lib/sequel/adapters/ado.rb
218 def dataset_class_default
219   Dataset
220 end
disconnect_error?(e, opts) click to toggle source
Calls superclass method Sequel::Database#disconnect_error?
    # File lib/sequel/adapters/ado.rb
237 def disconnect_error?(e, opts)
238   super || (e.is_a?(::WIN32OLERuntimeError) && e.message.include?('Communication link failure'))
239 end
rollback_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#rollback_transaction
    # File lib/sequel/adapters/ado.rb
241 def rollback_transaction(conn, opts=OPTS)
242   super if @opts[:provider]
243 end