Module: ArJdbc::Abstract::DatabaseStatements

Overview

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

Constant Summary collapse

NO_BINDS =
[].freeze

Instance Method Summary collapse

Instance Method Details

#delete(arel, name = nil, binds = []) ⇒ Object

overridden to support legacy binds



59
60
61
62
# File 'lib/arjdbc/abstract/database_statements.rb', line 59

def delete(arel, name = nil, binds = [])
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
  super
end

#exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/arjdbc/abstract/database_statements.rb', line 12

def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil)
  if without_prepared_statement?(binds)
    log(sql, name) { @connection.execute_insert(sql) }
  else
    log(sql, name, binds) do
      @connection.execute_insert(sql, binds)
    end
  end
end

#exec_query(sql, name = nil, binds = NO_BINDS, prepare: false) ⇒ Object

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/arjdbc/abstract/database_statements.rb', line 24

def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false)
  if without_prepared_statement?(binds)
    log(sql, name) { @connection.execute_query(sql) }
  else
    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_query(sql, binds, cached_statement)
    end
  end
end

#exec_update(sql, name = nil, binds = NO_BINDS) ⇒ Object Also known as: exec_delete



36
37
38
39
40
41
42
# File 'lib/arjdbc/abstract/database_statements.rb', line 36

def exec_update(sql, name = nil, binds = NO_BINDS)
  if without_prepared_statement?(binds)
    log(sql, name) { @connection.execute_update(sql) }
  else
    log(sql, name, binds) { @connection.execute_prepared_update(sql, binds) }
  end
end

#execute(sql, name = nil) ⇒ Object



64
65
66
# File 'lib/arjdbc/abstract/database_statements.rb', line 64

def execute(sql, name = nil)
  log(sql, name) { @connection.execute(sql) }
end

#insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = []) ⇒ Object Also known as: create

overridden to support legacy binds



46
47
48
49
# File 'lib/arjdbc/abstract/database_statements.rb', line 46

def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
  super
end

#select_all(arel, name = nil, binds = NO_BINDS, preparable: nil) ⇒ Object

overridden to support legacy binds



69
70
71
72
# File 'lib/arjdbc/abstract/database_statements.rb', line 69

def select_all(arel, name = nil, binds = NO_BINDS, preparable: nil)
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
  super
end

#update(arel, name = nil, binds = []) ⇒ Object

overridden to support legacy binds



53
54
55
56
# File 'lib/arjdbc/abstract/database_statements.rb', line 53

def update(arel, name = nil, binds = [])
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
  super
end