Skip to content

Commit f117e2c

Browse files
committed
Merge pull request #326 from veracross/fix_select_rows_binds
Fixed select_rows() to actual support binds via do_exec_query()
2 parents 58dea08 + f16b45b commit f117e2c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Sqlserver
44
module DatabaseStatements
55

66
def select_rows(sql, name = nil, binds = [])
7-
raw_select sql, name, binds, fetch: :rows
7+
do_exec_query sql, name, binds, fetch: :rows
88
end
99

1010
def execute(sql, name = nil)
@@ -327,7 +327,13 @@ def do_execute(sql, name = 'SQL')
327327
end
328328
end
329329

330-
def do_exec_query(sql, name, binds)
330+
def do_exec_query(sql, name, binds, options = {})
331+
# This allows non-AR code to utilize the binds
332+
# handling code, e.g. select_rows()
333+
if options[:fetch] != :rows
334+
options[:ar_result] = true
335+
end
336+
331337
explaining = name == 'EXPLAIN'
332338
names_and_types = []
333339
params = []
@@ -358,7 +364,7 @@ def do_exec_query(sql, name, binds)
358364
sql = "EXEC sp_executesql #{quote(sql)}"
359365
sql << ", #{quote(names_and_types.join(', '))}, #{params.join(', ')}" unless binds.empty?
360366
end
361-
raw_select sql, name, binds, ar_result: true
367+
raw_select sql, name, binds, options
362368
end
363369

364370
def raw_connection_do(sql)

0 commit comments

Comments
 (0)