Skip to content

Commit a376bfb

Browse files
dr-itzkares
authored andcommitted
[core] fix legacy binds when directly using exec_* methods (#1035)
Works with AR, breaks with AR-JDBC. Fix it by pushing the conversion down to the actual methods, remove the higher-level wrappers. Fixes #1033
1 parent 3d1cc0e commit a376bfb

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

lib/arjdbc/abstract/database_statements.rb

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module DatabaseStatements
1010
NO_BINDS = [].freeze
1111

1212
def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil)
13+
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
14+
1315
if without_prepared_statement?(binds)
1416
log(sql, name) { @connection.execute_insert(sql) }
1517
else
@@ -22,6 +24,8 @@ def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil
2224
# It appears that at this point (AR 5.0) "prepare" should only ever be true
2325
# if prepared statements are enabled
2426
def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false)
27+
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
28+
2529
if without_prepared_statement?(binds)
2630
log(sql, name) { @connection.execute_query(sql) }
2731
else
@@ -34,6 +38,8 @@ def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false)
3438
end
3539

3640
def exec_update(sql, name = nil, binds = NO_BINDS)
41+
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
42+
3743
if without_prepared_statement?(binds)
3844
log(sql, name) { @connection.execute_update(sql) }
3945
else
@@ -42,25 +48,6 @@ def exec_update(sql, name = nil, binds = NO_BINDS)
4248
end
4349
alias :exec_delete :exec_update
4450

45-
# overridden to support legacy binds
46-
def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
47-
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
48-
super
49-
end
50-
alias create insert
51-
52-
# overridden to support legacy binds
53-
def update(arel, name = nil, binds = [])
54-
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
55-
super
56-
end
57-
58-
# overridden to support legacy binds
59-
def delete(arel, name = nil, binds = [])
60-
binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
61-
super
62-
end
63-
6451
def execute(sql, name = nil)
6552
log(sql, name) { @connection.execute(sql) }
6653
end

0 commit comments

Comments
 (0)