Skip to content

Commit e5fcaff

Browse files
committed
Delegate all low level #raw_connection calls to #raw_connection_run and #raw_connection_do which abstract out the low level modes in the connection options at that point. Also removed the without_type_conversion block since this was a DBI hack.
1 parent b9e8e31 commit e5fcaff

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
MASTER
33

4+
* Delegate all low level #raw_connection calls to #raw_connection_run and #raw_connection_do
5+
which abstract out the low level modes in the connection options at that point. [Ken Collins]
6+
47
* Remove DBI dependency and go straight ODBC for speed improvement [Erik Bryn]
58

69
* Leave order by alone when same column crosses two tables [Ransom Briggs]

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def disable_referential_integrity(&block)
326326
# CONNECTION MANAGEMENT ====================================#
327327

328328
def active?
329-
raw_connection.run("SELECT 1").drop
329+
raw_connection_do("SELECT 1")
330330
true
331331
rescue *lost_connection_exceptions
332332
false
@@ -342,6 +342,26 @@ def disconnect!
342342
raw_connection.disconnect rescue nil
343343
end
344344

345+
def raw_connection_run(sql)
346+
with_auto_reconnect do
347+
case connection_mode
348+
when :odbc
349+
block_given? ? raw_connection.run_block(sql) { |handle| yield(handle) } : raw_connection.run(sql)
350+
else :ado
351+
352+
end
353+
end
354+
end
355+
356+
def raw_connection_do(sql)
357+
case connection_mode
358+
when :odbc
359+
raw_connection.do(sql)
360+
else :ado
361+
362+
end
363+
end
364+
345365
def finish_statement_handle(handle)
346366
handle.drop if handle && handle.respond_to?(:drop) && !handle.finished?
347367
handle
@@ -827,25 +847,12 @@ def info_schema_query
827847
end
828848

829849
def raw_execute(sql, name = nil, &block)
830-
log(sql, name) do
831-
if block_given?
832-
with_auto_reconnect { raw_connection.run_block(sql) { |handle| yield(handle) } }
833-
else
834-
with_auto_reconnect { raw_connection.run(sql) }
835-
end
836-
end
837-
end
838-
839-
def without_type_conversion
840-
raw_connection.convert_types = false if raw_connection.respond_to?(:convert_types=)
841-
yield
842-
ensure
843-
raw_connection.convert_types = true if raw_connection.respond_to?(:convert_types=)
850+
log(sql,name) { raw_connection_run(sql) }
844851
end
845852

846853
def do_execute(sql,name=nil)
847854
log(sql, name || 'EXECUTE') do
848-
with_auto_reconnect { raw_connection.do(sql) }
855+
with_auto_reconnect { raw_connection_do(sql) }
849856
end
850857
end
851858

@@ -1042,7 +1049,7 @@ def column_definitions(table_name)
10421049
WHERE columns.TABLE_NAME = '#{table_name}'
10431050
ORDER BY columns.ordinal_position
10441051
}.gsub(/[ \t\r\n]+/,' ')
1045-
results = info_schema_query { without_type_conversion{ select(sql,nil,true) } }
1052+
results = info_schema_query { select(sql,nil,true) }
10461053
results.collect do |ci|
10471054
ci.symbolize_keys!
10481055
ci[:type] = case ci[:type]
@@ -1059,7 +1066,7 @@ def column_definitions(table_name)
10591066
real_table_name = table_name_or_views_table_name(table_name)
10601067
real_column_name = views_real_column_name(table_name,ci[:name])
10611068
col_default_sql = "SELECT c.COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS c WHERE c.TABLE_NAME = '#{real_table_name}' AND c.COLUMN_NAME = '#{real_column_name}'"
1062-
ci[:default_value] = info_schema_query { without_type_conversion{ select_value(col_default_sql) } }
1069+
ci[:default_value] = info_schema_query { select_value(col_default_sql) }
10631070
end
10641071
ci[:default_value] = case ci[:default_value]
10651072
when nil, '(null)', '(NULL)'

0 commit comments

Comments
 (0)