module ArJdbc::Abstract::DatabaseStatements

This provides the basic interface for interacting with the database for JDBC based adapters

Public Instance Methods

exec_delete(sql, name = nil, binds = [])
Alias for: exec_update
exec_query(sql, name = nil, binds = [], prepare: false) click to toggle source

It appears that at this point (AR 5.0) “prepare” should only ever be true if prepared statements are enabled

# File lib/arjdbc/abstract/database_statements.rb, line 10
def exec_query(sql, name = nil, binds = [], prepare: false)
  if without_prepared_statement?(binds)
    execute(sql, name)
  else
    binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
    log(sql, name, binds) do
      # It seems that #supports_statement_cache? is defined but isn't checked before setting "prepare" (AR 5.0)
      cached_statement = fetch_cached_statement(sql) if prepare && supports_statement_cache?
      @connection.execute_prepared(sql, binds, cached_statement)
    end
  end
end
exec_update(sql, name = nil, binds = []) click to toggle source
# File lib/arjdbc/abstract/database_statements.rb, line 23
def exec_update(sql, name = nil, binds = [])
  if without_prepared_statement?(binds)
    log(sql, name) { @connection.execute_update(sql, nil) }
  else
    log(sql, name, binds) { @connection.execute_prepared_update(sql, binds) }
  end
end
Also aliased as: exec_delete
execute(sql, name = nil) click to toggle source
# File lib/arjdbc/abstract/database_statements.rb, line 32
def execute(sql, name = nil)
  log(sql, name) { @connection.execute(sql) }
end

Private Instance Methods

convert_legacy_binds_to_attributes(binds) click to toggle source
# File lib/arjdbc/abstract/database_statements.rb, line 38
def convert_legacy_binds_to_attributes(binds)
  binds.map do |column, value|
    ActiveRecord::Relation::QueryAttribute.new(nil, type_cast(value, column), ActiveModel::Type::Value.new)
  end
end