Module: ArJdbc::Abstract::DatabaseStatements
- Included in:
- ActiveRecord::ConnectionAdapters::JdbcAdapter, ActiveRecord::ConnectionAdapters::MSSQLAdapter, ActiveRecord::ConnectionAdapters::Mysql2Adapter, ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, ActiveRecord::ConnectionAdapters::SQLite3Adapter
- Defined in:
- lib/arjdbc/abstract/database_statements.rb
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
- #exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil) ⇒ Object
-
#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.
- #exec_update(sql, name = nil, binds = NO_BINDS) ⇒ Object (also: #exec_delete)
- #execute(sql, name = nil) ⇒ Object
-
#select_all(arel, name = nil, binds = NO_BINDS, preparable: nil) ⇒ Object
overridden to support legacy binds.
Instance Method Details
#exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/arjdbc/abstract/database_statements.rb', line 12 def exec_insert(sql, name = nil, binds = NO_BINDS, pk = nil, sequence_name = nil) if preventing_writes? raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end materialize_transactions mark_transaction_written_if_write(sql) binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array) if without_prepared_statement?(binds) log(sql, name) { @connection.execute_insert_pk(sql, pk) } else log(sql, name, binds) do @connection.execute_insert_pk(sql, binds, pk) 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/arjdbc/abstract/database_statements.rb', line 33 def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false) if preventing_writes? && write_query?(sql) raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end materialize_transactions mark_transaction_written_if_write(sql) binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array) if without_prepared_statement?(binds) log(sql, name) { @connection.execute_query(sql) } else log(sql, name, binds) do # this is different from normal AR that always caches cached_statement = fetch_cached_statement(sql) if prepare && @jdbc_statement_cache_enabled @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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/arjdbc/abstract/database_statements.rb', line 54 def exec_update(sql, name = nil, binds = NO_BINDS) if preventing_writes? raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end materialize_transactions mark_transaction_written_if_write(sql) binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array) 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
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/arjdbc/abstract/database_statements.rb', line 72 def execute(sql, name = nil) if preventing_writes? && write_query?(sql) raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end materialize_transactions mark_transaction_written_if_write(sql) log(sql, name) { @connection.execute(sql) } end |
#select_all(arel, name = nil, binds = NO_BINDS, preparable: nil) ⇒ Object
overridden to support legacy binds
84 85 86 87 |
# File 'lib/arjdbc/abstract/database_statements.rb', line 84 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 |