module ActiveRecord::ConnectionAdapters::SQLite3::DatabaseStatements
Public Instance Methods
Source
# 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
Source
# File lib/active_record/connection_adapters/sqlite3/database_statements.rb, line 49 def high_precision_current_timestamp HIGH_PRECISION_CURRENT_TIMESTAMP end
Private Instance Methods
Source
# File lib/active_record/connection_adapters/sqlite3/database_statements.rb, line 142 def affected_rows(result) result.affected_rows end
Source
# File lib/active_record/connection_adapters/sqlite3/database_statements.rb, line 151 def build_truncate_statement(table_name) "DELETE FROM #{quote_table_name(table_name)}" end
Source
# File lib/active_record/connection_adapters/sqlite3/database_statements.rb, line 136 def cast_result(result) # Given that SQLite3 doesn't have a Result type, raw_execute already returns an ActiveRecord::Result # so we have nothing to cast here. result end
Source
# File lib/active_record/connection_adapters/sqlite3/database_statements.rb, line 146 def execute_batch(statements, name = nil, **kwargs) sql = combine_multi_statements(statements) raw_execute(sql, name, batch: true, **kwargs) end
Source
# File lib/active_record/connection_adapters/sqlite3/database_statements.rb, line 73 def internal_begin_transaction(mode, isolation) if isolation raise TransactionIsolationError, "SQLite3 only supports the `read_uncommitted` transaction isolation level" if isolation != :read_uncommitted raise StandardError, "You need to enable the shared-cache mode in SQLite mode before attempting to change the transaction isolation level" unless shared_cache? end internal_execute("BEGIN #{mode} TRANSACTION", "TRANSACTION", allow_retry: true, materialize_transactions: false) if isolation @previous_read_uncommitted = query_value("PRAGMA read_uncommitted") internal_execute("PRAGMA read_uncommitted=ON", "TRANSACTION", allow_retry: true, materialize_transactions: false) end end
Source
# File lib/active_record/connection_adapters/sqlite3/database_statements.rb, line 86 def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch: false) total_changes_before_query = raw_connection.total_changes affected_rows = nil if batch raw_connection.execute_batch2(sql) else stmt = if prepare @statements[sql] ||= raw_connection.prepare(sql) @statements[sql].reset! else # Don't cache statements if they are not prepared. raw_connection.prepare(sql) end begin unless binds.nil? || binds.empty? stmt.bind_params(type_casted_binds) end result = if stmt.column_count.zero? # No return stmt.step affected_rows = if raw_connection.total_changes > total_changes_before_query raw_connection.changes else 0 end ActiveRecord::Result.empty(affected_rows: affected_rows) else rows = stmt.to_a affected_rows = if raw_connection.total_changes > total_changes_before_query raw_connection.changes else 0 end ActiveRecord::Result.new(stmt.columns, rows, stmt.types.map { |t| type_map.lookup(t) }, affected_rows: affected_rows) end ensure stmt.close unless prepare end end verified! notification_payload[:affected_rows] = affected_rows notification_payload[:row_count] = result&.length || 0 result end
Source
# File lib/active_record/connection_adapters/sqlite3/database_statements.rb, line 155 def returning_column_values(result) result.rows.first end