Module: ActiveRecord::ConnectionAdapters::SQLite3::DatabaseStatements
- Included in:
- ActiveRecord::ConnectionAdapters::SQLite3Adapter
- Defined in:
- lib/active_record/connection_adapters/sqlite3/database_statements.rb
Instance Method Summary collapse
-
#begin_db_transaction ⇒ Object
:nodoc:.
-
#commit_db_transaction ⇒ Object
:nodoc:.
- #exec_delete(sql, name = "SQL", binds = []) ⇒ Object (also: #exec_update)
- #exec_query(sql, name = nil, binds = [], prepare: false) ⇒ Object
-
#exec_rollback_db_transaction ⇒ Object
:nodoc:.
-
#execute(sql, name = nil) ⇒ Object
:nodoc:.
-
#write_query?(sql) ⇒ Boolean
:nodoc:.
Instance Method Details
#begin_db_transaction ⇒ Object
:nodoc:
70 71 72 |
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 70 def begin_db_transaction #:nodoc: log("begin transaction", nil) { @connection.transaction } end |
#commit_db_transaction ⇒ Object
:nodoc:
74 75 76 |
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 74 def commit_db_transaction #:nodoc: log("commit transaction", nil) { @connection.commit } end |
#exec_delete(sql, name = "SQL", binds = []) ⇒ Object Also known as: exec_update
64 65 66 67 |
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 64 def exec_delete(sql, name = "SQL", binds = []) exec_query(sql, name, binds) @connection.changes end |
#exec_query(sql, name = nil, binds = [], prepare: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 28 def exec_query(sql, name = nil, binds = [], prepare: false) if preventing_writes? && write_query?(sql) raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end materialize_transactions type_casted_binds = type_casted_binds(binds) log(sql, name, binds, type_casted_binds) do ActiveSupport::Dependencies.interlock.permit_concurrent_loads do # Don't cache statements if they are not prepared unless prepare stmt = @connection.prepare(sql) begin cols = stmt.columns unless without_prepared_statement?(binds) stmt.bind_params(type_casted_binds) end records = stmt.to_a ensure stmt.close end else stmt = @statements[sql] ||= @connection.prepare(sql) cols = stmt.columns stmt.reset! stmt.bind_params(type_casted_binds) records = stmt.to_a end ActiveRecord::Result.new(cols, records) end end end |
#exec_rollback_db_transaction ⇒ Object
:nodoc:
78 79 80 |
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 78 def exec_rollback_db_transaction #:nodoc: log("rollback transaction", nil) { @connection.rollback } end |
#execute(sql, name = nil) ⇒ Object
:nodoc:
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 14 def execute(sql, name = nil) #:nodoc: if preventing_writes? && write_query?(sql) raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}" end materialize_transactions log(sql, name) do ActiveSupport::Dependencies.interlock.permit_concurrent_loads do @connection.execute(sql) end end end |
#write_query?(sql) ⇒ Boolean
:nodoc:
10 11 12 |
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 10 def write_query?(sql) # :nodoc: !READ_QUERY.match?(sql) end |