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.
- CLASS ActiveRecord::ConnectionAdapters::SQLite3Adapter::ExplainPrettyPrinter
- CLASS ActiveRecord::ConnectionAdapters::SQLite3Adapter::StatementPool
- CLASS ActiveRecord::ConnectionAdapters::SQLite3Adapter::Version
- A
- C
- D
- E
- L
- N
- Q
- R
- S
- T
- V
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 107 def initialize(connection, logger, config) super(connection, logger) @active = nil @statements = StatementPool.new(@connection, self.class.type_cast_config_to_integer(config.fetch(:statement_limit) { 1000 })) @config = config if self.class.type_cast_config_to_boolean(config.fetch(:prepared_statements) { true }) @prepared_statements = true @visitor = Arel::Visitors::SQLite.new self else @visitor = unprepared_visitor end end
Returns 62. SQLite supports index names up to 64 characters. The rest is used by rails internally to perform temporary rename operations
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 474 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.
Returns the current database encoding format as a string, eg: 'UTF-8'
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 294 def exec_query(sql, name = nil, binds = []) log(sql, name, binds) do # Don't cache statements if they are not prepared if without_prepared_statement?(binds) 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 ======================================
QUOTING ==================================================
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 229 def quote(value, column = nil) if value.kind_of?(String) && column && column.type == :binary && column.class.respond_to?(:string_to_binary) s = column.class.string_to_binary(value).unpack("H*")[0] "x'#{s}'" else super end end
Renames a table.
Example:
rename_table('octopuses', 'octopi')
Returns true
Returns true
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/sqlite3_adapter.rb, line 510 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