The SQLite adapter works with both the 2.x and 3.x series of SQLite with the sqlite-ruby drivers (available both as gems and from rubyforge.org/projects/sqlite-ruby/).
Options:
-
:database
- Path to the database file.
- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::StatementPool
- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version
- C
- D
- E
- L
- N
- R
- S
- T
- V
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 88 def initialize(connection, logger, config) super(connection, logger) @statements = StatementPool.new(@connection, config.fetch(:statement_limit) { 1000 }) @config = config end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 400 def change_column_null(table_name, column_name, null, default = nil) unless null || default.nil? exec_query("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL") end alter_table(table_name) do |definition| definition[column_name].null = null end end
Clears the prepared statements cache.
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 147 def clear_cache! @statements.clear end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 282 def create_savepoint execute("SAVEPOINT #{current_savepoint_name}") end
Disconnects from the database if already connected. Otherwise, this method does nothing.
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 140 def disconnect! super clear_cache! @connection.close rescue nil end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 428 def empty_insert_statement_value "VALUES(NULL)" end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 248 def exec_delete(sql, name = 'SQL', binds = []) exec_query(sql, name, binds) @connection.changes end
DATABASE STATEMENTS ======================================
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 222 def exec_query(sql, name = nil, binds = []) log(sql, name, binds) do # Don't cache statements without bind values if binds.empty? stmt = @connection.prepare(sql) cols = stmt.columns records = stmt.to_a stmt.close stmt = records else cache = @statements[sql] ||= { :stmt => @connection.prepare(sql) } stmt = cache[:stmt] cols = cache[:cols] ||= stmt.columns stmt.reset! stmt.bind_params binds.map { |col, val| type_cast(val, col) } end ActiveRecord::Result.new(cols, stmt.to_a) end end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 254 def last_inserted_id(result) @connection.last_insert_row_id end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 290 def release_savepoint execute("RELEASE SAVEPOINT #{current_savepoint_name}") end
Renames a table.
Example:
rename_table('octopuses', 'octopi')
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 364 def rename_table(name, new_name) exec_query "ALTER TABLE #{quote_table_name(name)} RENAME TO #{quote_table_name(new_name)}" end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 129 def requires_reloading? true end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 286 def rollback_to_savepoint execute("ROLLBACK TO SAVEPOINT #{current_savepoint_name}") end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 278 def select_rows(sql, name = nil) exec_query(sql, name).rows end
Returns true if SQLite version is ‘3.1.6’ or greater, false otherwise.
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 134 def supports_add_column? sqlite_version >= '3.1.6' end
Returns true if SQLite version is ‘2.0.0’ or greater, false otherwise.
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 104 def supports_ddl_transactions? sqlite_version >= '2.0.0' end
Returns true if SQLite version is ‘3.6.8’ or greater, false otherwise.
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 109 def supports_savepoints? sqlite_version >= '3.6.8' end
Returns true, since this connection adapter supports prepared statement caching.
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 115 def supports_statement_cache? true end
See: www.sqlite.org/lang_altertable.html SQLite has an additional restriction on the ALTER TABLE statement
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 370 def valid_alter_table_options( type, options) type.to_sym != :primary_key end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 526 def default_primary_key_type if supports_autoincrement? 'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL' else 'INTEGER PRIMARY KEY NOT NULL' end end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 522 def sqlite_version @sqlite_version ||= SQLiteAdapter::Version.new(select_value('select sqlite_version(*)')) end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 437 def table_structure(table_name) structure = exec_query("PRAGMA table_info(#{quote_table_name(table_name)})", 'SCHEMA').to_hash raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty? structure end
Source: show
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 534 def translate_exception(exception, message) case exception.message when /column(s)? .* (is|are) not unique/ RecordNotUnique.new(message, exception) else super end end