class Sequel::ADO::Database

  1. lib/sequel/adapters/ado.rb
Superclass: Sequel::Database

Constants

CommandTimeout = opts[:command_timeout] if opts[:command_timeout]  
Provider = opts[:provider] if opts[:provider]  

Attributes

Public Instance methods

connect(server)

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.

[show source]
    # 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)
[show 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)
[show 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)

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

[show source]
    # File lib/sequel/adapters/ado.rb
134 def execute_ddl(sql, opts=OPTS)
135   execute(sql, opts)
136 end
execute_dui(sql, opts=OPTS)

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

[show source]
    # 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)

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

[show source]
    # File lib/sequel/adapters/ado.rb
139 def execute_insert(sql, opts=OPTS)
140   execute(sql, opts)
141 end
freeze()
[show source]
    # File lib/sequel/adapters/ado.rb
128 def freeze
129   @conversion_procs.freeze
130   super
131 end