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::ExplainPrettyPrinter
- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::StatementPool
- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version
- C
- D
- E
- L
- N
- R
- S
- T
- V
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 77 def initialize(connection, logger, config) super(connection, logger) @statements = StatementPool.new(@connection, config.fetch(:statement_limit) { 1000 }) @config = config if config.fetch(:prepared_statements) { true } @visitor = Arel::Visitors::SQLite.new self else @visitor = BindSubstitution.new self end end
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 431 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.
Disconnects from the database if already connected. Otherwise, this method does nothing.
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 241 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
DATABASE STATEMENTS ======================================
Renames a table.
Example:
rename_table('octopuses', 'octopi')
Returns true if SQLite version is ‘3.1.6’ or greater, false otherwise.
Returns true if SQLite version is ‘2.0.0’ or greater, false otherwise.
Returns true.
Returns true if SQLite version is ‘3.6.8’ or greater, false otherwise.
Returns true, since this connection adapter supports prepared statement caching.
See: www.sqlite.org/lang_altertable.html SQLite has an additional restriction on the ALTER TABLE statement
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 470 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