Module: ActiveRecord::ConnectionAdapters::Peasys::DatabaseStatements
- Included in:
- ActiveRecord::ConnectionAdapters::PeasysAdapter
- Defined in:
- lib/active_record/connection_adapters/peasys/database_statements.rb
Instance Method Summary collapse
- #begin_db_transaction ⇒ Object
- #commit_db_transaction ⇒ Object
- #default_sequence_name(table_name, _column = nil) ⇒ Object
- #exec_delete(sql, name = nil, binds = []) ⇒ Object (also: #exec_update)
- #exec_rollback_db_transaction ⇒ Object
- #execute(sql, name = nil, allow_retry: false) ⇒ Object
- #internal_exec_query(sql, name = nil, binds = [], prepare: false, async: false, allow_retry: false) ⇒ Object
- #write_query?(sql) ⇒ Boolean
Instance Method Details
#begin_db_transaction ⇒ Object
79 80 81 82 83 |
# File 'lib/active_record/connection_adapters/peasys/database_statements.rb', line 79 def begin_db_transaction # DB2 on IBM i uses implicit transactions. # We send a SET TRANSACTION ISOLATION LEVEL to mark the start. # Alternatively, we just track state -- COMMIT/ROLLBACK are explicit. end |
#commit_db_transaction ⇒ Object
85 86 87 88 89 |
# File 'lib/active_record/connection_adapters/peasys/database_statements.rb', line 85 def commit_db_transaction with_raw_connection do |conn| conn.execute_sql("COMMIT") end end |
#default_sequence_name(table_name, _column = nil) ⇒ Object
97 98 99 |
# File 'lib/active_record/connection_adapters/peasys/database_statements.rb', line 97 def default_sequence_name(table_name, _column = nil) nil end |
#exec_delete(sql, name = nil, binds = []) ⇒ Object Also known as: exec_update
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/active_record/connection_adapters/peasys/database_statements.rb', line 50 def exec_delete(sql, name = nil, binds = []) sql = transform_query(sql) type_casted_binds = type_casted_binds(binds) bound_sql = bind_params_to_sql(sql, type_casted_binds) log(bound_sql, name, binds, type_casted_binds) do with_raw_connection do |conn| keyword = bound_sql.strip.split(/\s+/, 2).first.upcase case keyword when "DELETE" response = conn.execute_delete(bound_sql) raise_if_failed(response, bound_sql) verified! response.row_count when "UPDATE" response = conn.execute_update(bound_sql) raise_if_failed(response, bound_sql) verified! response.row_count else execute_and_extract(conn, bound_sql) verified! 0 end end end end |
#exec_rollback_db_transaction ⇒ Object
91 92 93 94 95 |
# File 'lib/active_record/connection_adapters/peasys/database_statements.rb', line 91 def exec_rollback_db_transaction with_raw_connection do |conn| conn.execute_sql("ROLLBACK") end end |
#execute(sql, name = nil, allow_retry: false) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/active_record/connection_adapters/peasys/database_statements.rb', line 37 def execute(sql, name = nil, allow_retry: false) sql = transform_query(sql) check_if_write_query(sql) mark_transaction_written_if_write(sql) log(sql, name) do with_raw_connection do |conn| execute_and_extract(conn, sql) verified! end end end |
#internal_exec_query(sql, name = nil, binds = [], prepare: false, async: false, allow_retry: false) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_record/connection_adapters/peasys/database_statements.rb', line 18 def internal_exec_query(sql, name = nil, binds = [], prepare: false, async: false, allow_retry: false) sql = transform_query(sql) check_if_write_query(sql) mark_transaction_written_if_write(sql) type_casted_binds = type_casted_binds(binds) bound_sql = bind_params_to_sql(sql, type_casted_binds) log(bound_sql, name, binds, type_casted_binds, async: async) do |notification_payload| with_raw_connection do |conn| columns, rows = execute_and_extract(conn, bound_sql) verified! result = build_result(columns: columns, rows: rows) notification_payload[:row_count] = result.length if notification_payload result end end end |
#write_query?(sql) ⇒ Boolean
12 13 14 15 16 |
# File 'lib/active_record/connection_adapters/peasys/database_statements.rb', line 12 def write_query?(sql) !READ_QUERY.match?(sql) rescue ArgumentError !READ_QUERY.match?(sql.b) end |