class Sequel::ADO::Database
Constants
- CommandTimeout
- Provider
Attributes
Public Instance Methods
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 thisADO
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 106 def connect(server) 107 opts = server_opts(server) 108 s = opts[:conn_string] || "driver=#{opts[:driver]};server=#{opts[:host]};database=#{opts[:database]}#{";uid=#{opts[:user]};pwd=#{opts[:password]}" if opts[:user]}" 109 handle = WIN32OLE.new('ADODB.Connection') 110 handle.CommandTimeout = opts[:command_timeout] if opts[:command_timeout] 111 handle.Provider = opts[:provider] if opts[:provider] 112 handle.Open(s) 113 handle 114 end
# File lib/sequel/adapters/ado.rb 116 def disconnect_connection(conn) 117 conn.Close 118 rescue WIN32OLERuntimeError 119 nil 120 end
# File lib/sequel/adapters/ado.rb 153 def execute(sql, opts=OPTS) 154 synchronize(opts[:server]) do |conn| 155 begin 156 r = log_connection_yield(sql, conn){conn.Execute(sql)} 157 begin 158 yield r if block_given? 159 ensure 160 begin 161 r.close 162 rescue ::WIN32OLERuntimeError 163 end 164 end 165 rescue ::WIN32OLERuntimeError => e 166 raise_error(e) 167 end 168 end 169 nil 170 end
Just execute so it doesn't attempt to return the number of rows modified.
# File lib/sequel/adapters/ado.rb 128 def execute_ddl(sql, opts=OPTS) 129 execute(sql, opts) 130 end
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).
Sequel::Database#execute_dui
# File lib/sequel/adapters/ado.rb 141 def execute_dui(sql, opts=OPTS) 142 return super if opts[:provider] 143 synchronize(opts[:server]) do |conn| 144 begin 145 log_connection_yield(sql, conn){conn.Execute(sql, 1)} 146 WIN32OLE::ARGV[1] 147 rescue ::WIN32OLERuntimeError => e 148 raise_error(e) 149 end 150 end 151 end
Just execute so it doesn't attempt to return the number of rows modified.
# File lib/sequel/adapters/ado.rb 133 def execute_insert(sql, opts=OPTS) 134 execute(sql, opts) 135 end
Sequel::Database#freeze
# File lib/sequel/adapters/ado.rb 122 def freeze 123 @conversion_procs.freeze 124 super 125 end
Private Instance Methods
Sequel::Database#adapter_initialize
# File lib/sequel/adapters/ado.rb 174 def adapter_initialize 175 case @opts[:conn_string] 176 when /Microsoft\.(Jet|ACE)\.OLEDB/io 177 require_relative 'ado/access' 178 extend Sequel::ADO::Access::DatabaseMethods 179 self.dataset_class = ADO::Access::Dataset 180 else 181 @opts[:driver] ||= 'SQL Server' 182 case @opts[:driver] 183 when 'SQL Server' 184 require_relative 'ado/mssql' 185 extend Sequel::ADO::MSSQL::DatabaseMethods 186 self.dataset_class = ADO::MSSQL::Dataset 187 set_mssql_unicode_strings 188 end 189 end 190 191 @conversion_procs = CONVERSION_PROCS.dup 192 193 super 194 end
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.
Sequel::Database#begin_transaction
# File lib/sequel/adapters/ado.rb 203 def begin_transaction(conn, opts=OPTS) 204 super if @opts[:provider] 205 end
Sequel::Database#commit_transaction
# File lib/sequel/adapters/ado.rb 207 def commit_transaction(conn, opts=OPTS) 208 super if @opts[:provider] 209 end
# File lib/sequel/adapters/ado.rb 211 def database_error_classes 212 [::WIN32OLERuntimeError] 213 end
# File lib/sequel/adapters/ado.rb 196 def dataset_class_default 197 Dataset 198 end
Sequel::Database#disconnect_error?
# File lib/sequel/adapters/ado.rb 215 def disconnect_error?(e, opts) 216 super || (e.is_a?(::WIN32OLERuntimeError) && e.message =~ /Communication link failure/) 217 end
Sequel::Database#rollback_transaction
# File lib/sequel/adapters/ado.rb 219 def rollback_transaction(conn, opts=OPTS) 220 super if @opts[:provider] 221 end