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.
- A
- C
- D
- E
- F
- L
- N
- R
- S
- V
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 |
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 95 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])) configure_connection end
Returns 62. SQLite supports index names up to 64 characters. The rest is used by Rails internally to perform temporary rename operations
Clears the prepared statements cache.
Disconnects from the database if already connected. Otherwise, this method does nothing.
Returns the current database encoding format as a string, eg: 'UTF-8'
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 205 def exec_query(sql, name = nil, binds = [], prepare: false) type_casted_binds = type_casted_binds(binds) log(sql, name, binds, type_casted_binds) do ActiveSupport::Dependencies.interlock.permit_concurrent_loads 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 end
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 400 def foreign_keys(table_name) fk_info = select_all("PRAGMA foreign_key_list(#{quote(table_name)})", "SCHEMA") fk_info.map do |row| options = { column: row["from"], primary_key: row["to"], on_delete: extract_foreign_key_action(row["on_delete"]), on_update: extract_foreign_key_action(row["on_update"]) } ForeignKeyDefinition.new(table_name, row["table"], options) end end
SCHEMA STATEMENTS ========================================
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 270 def new_column_from_field(table_name, field) # :nondoc: case field["dflt_value"] when /^null$/i field["dflt_value"] = nil when /^'(.*)'$/m field["dflt_value"] = $1.gsub("''", "'") when /^"(.*)"$/m field["dflt_value"] = $1.gsub('""', '"') end collation = field["collation"] sql_type = field["type"] type_metadata = fetch_type_metadata(sql_type) new_column(field["name"], field["dflt_value"], type_metadata, field["notnull"].to_i == 0, table_name, nil, collation) end
Renames a table.
Example:
rename_table('octopuses', 'octopi')
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