Skip to content

Commit 67fa60a

Browse files
committed
eliminate #do_exec helper - adapters should override exec_xxx methods
1 parent 7adc813 commit 67fa60a

File tree

3 files changed

+11
-34
lines changed

3 files changed

+11
-34
lines changed

lib/arjdbc/jdbc/adapter.rb

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,47 +234,30 @@ def jdbc_columns(table_name, name = nil)
234234
# +binds+ as the bind substitutes. +name+ is logged along with
235235
# the executed +sql+ statement.
236236
def exec_query(sql, name = 'SQL', binds = []) # :nodoc:
237-
do_exec(sql, name, binds, :query)
237+
log(sql, name || 'SQL') { @connection.execute_query(to_sql(sql, binds)) }
238238
end
239239

240240
# Executes insert +sql+ statement in the context of this connection using
241241
# +binds+ as the bind substitutes. +name+ is the logged along with
242242
# the executed +sql+ statement.
243243
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) # :nodoc:
244-
do_exec(sql, name, binds, :insert)
244+
log(sql, name || 'SQL') { @connection.execute_insert(to_sql(sql, binds)) }
245245
end
246246

247247
# Executes delete +sql+ statement in the context of this connection using
248248
# +binds+ as the bind substitutes. +name+ is the logged along with
249249
# the executed +sql+ statement.
250250
def exec_delete(sql, name, binds) # :nodoc:
251-
do_exec(sql, name, binds, :delete)
251+
log(sql, name || 'SQL') { @connection.execute_delete(to_sql(sql, binds)) }
252252
end
253253

254254
# Executes update +sql+ statement in the context of this connection using
255255
# +binds+ as the bind substitutes. +name+ is the logged along with
256256
# the executed +sql+ statement.
257257
def exec_update(sql, name, binds) # :nodoc:
258-
do_exec(sql, name, binds, :update)
258+
log(sql, name || 'SQL') { @connection.execute_update(to_sql(sql, binds)) }
259259
end
260260

261-
# TODO is it really useful to have do_exec now ?!
262-
def do_exec(sql, name, binds, type)
263-
sql = to_sql(sql, binds)
264-
log(sql, name || 'SQL') do
265-
if type == :insert
266-
@connection.execute_insert(sql)
267-
elsif type == :update
268-
@connection.execute_update(sql)
269-
elsif type == :delete
270-
@connection.execute_delete(sql)
271-
else # type == :query
272-
@connection.execute_query(sql)
273-
end
274-
end
275-
end
276-
protected :do_exec
277-
278261
# Similar to {#exec_query} except it returns "raw" results in an array
279262
# where each rows is a hash with keys as columns (just like Rails used to
280263
# do up until 3.0) instead of wrapping them in a {#ActiveRecord::Result}.
@@ -283,7 +266,6 @@ def exec_query_raw(sql, name = 'SQL', binds = [], &block) # :nodoc:
283266
@connection.execute_query_raw(to_sql(sql, binds), &block)
284267
end
285268
end
286-
alias_method :exec_raw_query, :exec_query_raw
287269

288270
def select_rows(sql, name = nil)
289271
exec_query_raw(sql, name).map!(&:values)

lib/arjdbc/mssql/adapter.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -596,17 +596,12 @@ def exec_proc(proc_name, *variables)
596596
end
597597
alias_method :execute_procedure, :exec_proc # AR-SQLServer-Adapter naming
598598

599-
protected
600-
601-
# NOTE: we allow to execute the SQL as explicitly requested by this,
602-
# {#exec_query} won't route to {#_execute} and analyze if it's a select
603-
# e.g. this allows to use SQLServer's EXEC with a result set ...
604-
def do_exec(sql, name, binds, type)
605-
if type == :query # exec_query
606-
sql = repair_special_columns to_sql(sql, binds)
607-
log(sql, name || 'SQL') { @connection.execute_query sql }
608-
else super
609-
end
599+
# @override
600+
def exec_query(sql, name = 'SQL', binds = []) # :nodoc:
601+
# NOTE: we allow to execute SQL as requested returning a results.
602+
# e.g. this allows to use SQLServer's EXEC with a result set ...
603+
sql = repair_special_columns to_sql(sql, binds)
604+
log(sql, name || 'SQL') { @connection.execute_query(sql) }
610605
end
611606

612607
private

lib/arjdbc/sqlite3/adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def select(sql, name = nil, binds = [])
294294
result
295295
end
296296

297-
# #override as {#execute_insert} not implemented by SQLite JDBC driver
297+
# @override as <code>execute_insert</code> not implemented by SQLite JDBC
298298
def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) # :nodoc:
299299
execute(sql, name, binds)
300300
end

0 commit comments

Comments
 (0)