class Sequel::ADO::Database

Constants

CommandTimeout
DISCONNECT_ERROR_RE
DatasetClass
Provider

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. 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 31
def connect(server)
  opts = server_opts(server)
  s = opts[:conn_string] || "driver=#{opts[:driver]};server=#{opts[:host]};database=#{opts[:database]}#{";uid=#{opts[:user]};pwd=#{opts[:password]}" if opts[:user]}"
  handle = WIN32OLE.new('ADODB.Connection')
  handle.CommandTimeout = opts[:command_timeout] if opts[:command_timeout]
  handle.Provider = opts[:provider] if opts[:provider]
  handle.Open(s)
  handle
end
disconnect_connection(conn) click to toggle source
# File lib/sequel/adapters/ado.rb, line 41
def disconnect_connection(conn)
  conn.Close
rescue WIN32OLERuntimeError
  nil
end
execute(sql, opts=OPTS) { |r| ... } click to toggle source
# File lib/sequel/adapters/ado.rb, line 73
def execute(sql, opts=OPTS)
  synchronize(opts[:server]) do |conn|
    begin
      r = log_yield(sql){conn.Execute(sql)}
      yield(r) if block_given?
    rescue ::WIN32OLERuntimeError => e
      raise_error(e)
    end
  end
  nil
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, line 48
def execute_ddl(sql, opts=OPTS)
  execute(sql, opts)
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, line 61
def execute_dui(sql, opts=OPTS)
  return super if opts[:provider]
  synchronize(opts[:server]) do |conn|
    begin
      log_yield(sql){conn.Execute(sql, 1)}
      WIN32OLE::ARGV[1]
    rescue ::WIN32OLERuntimeError => e
      raise_error(e)
    end
  end
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, line 53
def execute_insert(sql, opts=OPTS)
  execute(sql, opts)
end

Private Instance Methods

adapter_initialize() click to toggle source
Calls superclass method Sequel::Database#adapter_initialize
# File lib/sequel/adapters/ado.rb, line 87
def adapter_initialize
  case @opts[:conn_string]
  when /Microsoft\.(Jet|ACE)\.OLEDB/io
    Sequel.require 'adapters/ado/access'
    extend Sequel::ADO::Access::DatabaseMethods
    self.dataset_class = ADO::Access::Dataset
  else
    @opts[:driver] ||= 'SQL Server'
    case @opts[:driver]
    when 'SQL Server'
      Sequel.require 'adapters/ado/mssql'
      extend Sequel::ADO::MSSQL::DatabaseMethods
      self.dataset_class = ADO::MSSQL::Dataset
      set_mssql_unicode_strings
    end
  end
  super
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, line 109
def begin_transaction(conn, opts=OPTS)
  super if @opts[:provider]
end
commit_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#commit_transaction
# File lib/sequel/adapters/ado.rb, line 113
def commit_transaction(conn, opts=OPTS)
  super if @opts[:provider]
end
database_error_classes() click to toggle source
# File lib/sequel/adapters/ado.rb, line 117
def database_error_classes
  [::WIN32OLERuntimeError]
end
disconnect_error?(e, opts) click to toggle source
Calls superclass method Sequel::Database#disconnect_error?
# File lib/sequel/adapters/ado.rb, line 121
def disconnect_error?(e, opts)
  super || (e.is_a?(::WIN32OLERuntimeError) && e.message =~ DISCONNECT_ERROR_RE)
end
rollback_transaction(conn, opts=OPTS) click to toggle source
Calls superclass method Sequel::Database#rollback_transaction
# File lib/sequel/adapters/ado.rb, line 125
def rollback_transaction(conn, opts=OPTS)
  super if @opts[:provider]
end