Ticket #428: sqlserver_reconnect.patch
| File sqlserver_reconnect.patch, 2.6 kB (added by kajism@yahoo.com, 3 years ago) |
|---|
-
sqlserver_adapter.rb
old new 30 30 if mode == "ODBC" 31 31 raise ArgumentError, "Missing DSN. Argument ':dsn' must be set in order for this adapter to work." unless config.has_key?(:dsn) 32 32 dsn = config[:dsn] 33 conn = DBI.connect("DBI:ODBC:#{dsn}", username, password)33 driver_url = "DBI:ODBC:#{dsn}" 34 34 else 35 35 raise ArgumentError, "Missing Database. Argument ':database' must be set in order for this adapter to work." unless config.has_key?(:database) 36 36 database = config[:database] 37 37 host = config[:host] ? config[:host].to_s : 'localhost' 38 conn = DBI.connect("DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};User Id=#{username};Password=#{password};")38 driver_url = "DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};User Id=#{username};Password=#{password};" 39 39 end 40 conn = DBI.connect(driver_url, username, password) 40 41 41 42 conn["AutoCommit"] = true 42 ConnectionAdapters::SQLServerAdapter.new(conn, logger )43 ConnectionAdapters::SQLServerAdapter.new(conn, logger, [driver_url, username, password]) 43 44 end 44 45 end # class Base 45 46 … … 172 173 # unixODBC 2.2.11, Ruby ODBC 0.996, Ruby DBI 0.0.23 and Ruby 1.8.2. 173 174 # [Linux strongmad 2.6.11-1.1369_FC4 #1 Thu Jun 2 22:55:56 EDT 2005 i686 i686 i386 GNU/Linux] 174 175 class SQLServerAdapter < AbstractAdapter 176 177 def initialize(connection, logger, connection_options=nil) 178 super(connection, logger) 179 @connection_options = connection_options 180 end 181 175 182 def native_database_types 176 183 { 177 184 :primary_key => "int NOT NULL IDENTITY(1, 1) PRIMARY KEY", … … 196 203 true 197 204 end 198 205 206 # CONNECTION MANAGEMENT ====================================# 207 208 # Returns true if the connection is active. 209 def active? 210 @connection.execute("SELECT 1") {|sth|} 211 true 212 rescue DBI::DatabaseError => e 213 false 214 end 215 216 # Reconnects to the database. 217 def reconnect! 218 begin 219 @connection.disconnect 220 @connection = DBI.connect(*@connection_options) 221 rescue DBI::DatabaseError => e 222 @logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}" 223 end 224 end 225 226 227 199 228 def select_all(sql, name = nil) 200 229 select(sql, name) 201 230 end