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
Methods
- A
- C
- D
- E
- L
- N
- 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" } } |
COLLATE_REGEX | = | /.*\"(\w+)\".*collate\s+\"(\w+)\".*/i.freeze |
Class Public methods
new(connection, logger, connection_options, config)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 86 def initialize(connection, logger, connection_options, config) super(connection, logger, config) @active = nil @statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit])) 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
clear_cache!()
Link
Clears the prepared statements cache.
data_source_exists?(table_name)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 279 def data_source_exists?(table_name) return false unless table_name.present? sql = "SELECT name FROM sqlite_master WHERE type IN ('table','view') AND name <> 'sqlite_sequence'" sql << " AND name = #{quote(table_name)}" select_values(sql, 'SCHEMA').any? end
data_sources()
Link
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 = [], prepare: false)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 190 def exec_query(sql, name = nil, binds = [], prepare: false) type_casted_binds = type_casted_binds(binds) log(sql, name, binds, type_casted_binds) do # Don't cache statements if they are not prepared unless prepare stmt = @connection.prepare(sql) begin cols = stmt.columns unless without_prepared_statement?(binds) stmt.bind_params(type_casted_binds) end records = stmt.to_a ensure stmt.close end else cache = @statements[sql] ||= { :stmt => @connection.prepare(sql) } stmt = cache[:stmt] cols = cache[:cols] ||= stmt.columns stmt.reset! stmt.bind_params(type_casted_binds) records = stmt.to_a end ActiveRecord::Result.new(cols, records) end end
explain(arel, binds = [])
Link
last_inserted_id(result)
Link
rename_table(table_name, new_name)
Link
Renames a table.
Example:
rename_table('octopuses', 'octopi')
requires_reloading?()
Link
supports_datetime_with_precision?()
Link
supports_ddl_transactions?()
Link
supports_explain?()
Link
supports_index_sort_order?()
Link
supports_multi_insert?()
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
table_exists?(table_name)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 269 def table_exists?(table_name) ActiveSupport::Deprecation.warn(" #table_exists? currently checks both tables and views. This behavior is deprecated and will be changed with Rails 5.1 to only check tables. Use #data_source_exists? instead. ".squish) data_source_exists?(table_name) end
valid_alter_table_type?(type)
Link
See: www.sqlite.org/lang_altertable.html SQLite has an additional restriction on the ALTER TABLE statement
valid_type?(type)
Link
Instance Protected methods
sqlite_version()
Link
table_structure(table_name)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 427 def table_structure(table_name) structure = exec_query("PRAGMA table_info(#{quote_table_name(table_name)})", 'SCHEMA') raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty? table_structure_with_collation(table_name, structure) end
translate_exception(exception, message)
Link
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 515 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) else super end end