The SQLite3 adapter works SQLite 3.6.16 or newer with the sqlite3-ruby drivers (available as gem from rubygems.org/gems/sqlite3).
Options:
-
:database
- Path to the database file.
Namespace
- CLASS ActiveRecord::ConnectionAdapters::SQLite3Adapter::ExplainPrettyPrinter
- CLASS ActiveRecord::ConnectionAdapters::SQLite3Adapter::StatementPool
Methods
- A
- C
- D
- E
- I
- L
- N
- Q
- R
- S
- T
- V
Constants
ADAPTER_NAME | = | 'SQLite'.freeze |
NATIVE_DATABASE_TYPES | = | { primary_key: 'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL', string: { name: "varchar" }, text: { name: "text" }, integer: { name: "integer" }, float: { name: "float" }, decimal: { name: "decimal" }, datetime: { name: "datetime" }, time: { name: "time" }, date: { name: "date" }, binary: { name: "blob" }, boolean: { name: "boolean" } } |
Class Public methods
new(connection, logger, connection_options, config)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 112 def initialize(connection, logger, connection_options, config) super(connection, logger) @active = nil @statements = StatementPool.new(@connection, self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 })) @config = config @visitor = Arel::Visitors::SQLite.new self if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true }) @prepared_statements = true else @prepared_statements = false end end
Instance Public methods
active?()
Link
allowed_index_name_length()
Link
Returns 62. SQLite supports index names up to 64 characters. The rest is used by rails internally to perform temporary rename operations
change_column_null(table_name, column_name, null, default = nil)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 463 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
clear_cache!()
Link
Clears the prepared statements cache.
disconnect!()
Link
Disconnects from the database if already connected. Otherwise, this method does nothing.
encoding()
Link
Returns the current database encoding format as a string, eg: 'UTF-8'
exec_query(sql, name = nil, binds = [])
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 276 def exec_query(sql, name = nil, binds = []) type_casted_binds = binds.map { |col, val| [col, type_cast(val, col)] } log(sql, name, type_casted_binds) do # Don't cache statements if they are not prepared if without_prepared_statement?(binds) stmt = @connection.prepare(sql) begin cols = stmt.columns records = stmt.to_a ensure stmt.close end stmt = records else cache = @statements[sql] ||= { :stmt => @connection.prepare(sql) } stmt = cache[:stmt] cols = cache[:cols] ||= stmt.columns stmt.reset! stmt.bind_params type_casted_binds.map { |_, val| val } end ActiveRecord::Result.new(cols, stmt.to_a) end end
explain(arel, binds = [])
Link
last_inserted_id(result)
Link
quote_table_name_for_assignment(table, attr)
Link
rename_table(table_name, new_name)
Link
Renames a table.
Example:
rename_table('octopuses', 'octopi')
requires_reloading?()
Link
select_rows(sql, name = nil, binds = [])
Link
supports_ddl_transactions?()
Link
supports_explain?()
Link
supports_index_sort_order?()
Link
supports_partial_index?()
Link
supports_savepoints?()
Link
supports_statement_cache?()
Link
Returns true, since this connection adapter supports prepared statement caching.
supports_views?()
Link
valid_alter_table_type?(type)
Link
See: www.sqlite.org/lang_altertable.html SQLite has an additional restriction on the ALTER TABLE statement
Instance Protected methods
initialize_type_map(m)
Link
sqlite_version()
Link
table_structure(table_name)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 499 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
translate_exception(exception, message)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 598 def translate_exception(exception, message) case exception.message # SQLite 3.8.2 returns a newly formatted error message: # UNIQUE constraint failed: *table_name*.*column_name* # Older versions of SQLite return: # column *column_name* is not unique when /column(s)? .* (is|are) not unique/, /UNIQUE constraint failed: .*/ RecordNotUnique.new(message, exception) else super end end