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

Instance Method Details

#begin_db_transactionObject

:nodoc:



32
33
34
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 32

def begin_db_transaction # :nodoc:
  internal_begin_transaction(:immediate, nil)
end

#begin_deferred_transaction(isolation = nil) ⇒ Object

:nodoc:



24
25
26
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 24

def begin_deferred_transaction(isolation = nil) # :nodoc:
  internal_begin_transaction(:deferred, isolation)
end

#begin_isolated_db_transaction(isolation) ⇒ Object

:nodoc:



28
29
30
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 28

def begin_isolated_db_transaction(isolation) # :nodoc:
  internal_begin_transaction(:deferred, isolation)
end

#commit_db_transactionObject

:nodoc:



36
37
38
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 36

def commit_db_transaction # :nodoc:
  internal_execute("COMMIT TRANSACTION", "TRANSACTION", allow_retry: true, materialize_transactions: false)
end

#exec_rollback_db_transactionObject

:nodoc:



40
41
42
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 40

def exec_rollback_db_transaction # :nodoc:
  internal_execute("ROLLBACK TRANSACTION", "TRANSACTION", allow_retry: true, materialize_transactions: false)
end

#executeObject

:nodoc:



53
54
55
56
57
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 53

def execute(...) # :nodoc:
  # SQLite3Adapter was refactored to use ActiveRecord::Result internally
  # but for backward compatibility we have to keep returning arrays of hashes here
  super&.to_a
end

#explain(arel, binds = [], _options = []) ⇒ Object



18
19
20
21
22
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 18

def explain(arel, binds = [], _options = [])
  sql    = "EXPLAIN QUERY PLAN " + to_sql(arel, binds)
  result = internal_exec_query(sql, "EXPLAIN", [])
  SQLite3::ExplainPrettyPrinter.new.pp(result)
end

#high_precision_current_timestampObject



49
50
51
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 49

def high_precision_current_timestamp
  HIGH_PRECISION_CURRENT_TIMESTAMP
end

#reset_isolation_levelObject

:nodoc:



59
60
61
62
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 59

def reset_isolation_level # :nodoc:
  internal_execute("PRAGMA read_uncommitted=#{@previous_read_uncommitted}", "TRANSACTION", allow_retry: true, materialize_transactions: false)
  @previous_read_uncommitted = nil
end

#write_query?(sql) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/active_record/connection_adapters/sqlite3/database_statements.rb', line 12

def write_query?(sql) # :nodoc:
  !READ_QUERY.match?(sql)
rescue ArgumentError # Invalid encoding
  !READ_QUERY.match?(sql.b)
end