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.

Namespace
Methods
C
D
E
N
R
S
T
V
Class Public methods
new(connection, logger, config)
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 97
def initialize(connection, logger, config)
  super(connection, logger)
  @config = config
end
Instance Public methods
change_column_null(table_name, column_name, null, default = nil)
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 286
def change_column_null(table_name, column_name, null, default = nil)
  unless null || default.nil?
    execute("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
disconnect!()
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 126
def disconnect!
  super
  @connection.close rescue nil
end
empty_insert_statement(table_name)
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 314
def empty_insert_statement(table_name)
  "INSERT INTO #{table_name} VALUES(NULL)"
end
rename_table(name, new_name)
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 250
def rename_table(name, new_name)
  execute "ALTER TABLE #{name} RENAME TO #{new_name}"
end
requires_reloading?()
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 118
def requires_reloading?
  true
end
select_rows(sql, name = nil)
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 188
def select_rows(sql, name = nil)
  execute(sql, name).map do |row|
    (0...(row.size / 2)).map { |i| row[i] }
  end
end
supports_add_column?()
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 122
def supports_add_column?
  sqlite_version >= '3.1.6'
end
supports_ddl_transactions?()
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 106
def supports_ddl_transactions?
  sqlite_version >= '2.0.0'
end
valid_alter_table_options( type, options)

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 256
def valid_alter_table_options( type, options)
  type.to_sym != :primary_key
end
Instance Protected methods
catch_schema_changes()
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 416
def catch_schema_changes
  return yield
rescue ActiveRecord::StatementInvalid => exception
  if exception.message =~ /database schema has changed/
    reconnect!
    retry
  else
    raise
  end
end
default_primary_key_type()
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 431
def default_primary_key_type
  if supports_autoincrement?
    'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL'.freeze
  else
    'INTEGER PRIMARY KEY NOT NULL'.freeze
  end
end
sqlite_version()
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 427
def sqlite_version
  @sqlite_version ||= SQLiteAdapter::Version.new(select_value('select sqlite_version(*)'))
end
table_structure(table_name)
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 331
def table_structure(table_name)
  execute("PRAGMA table_info(#{quote_table_name(table_name)})").tap do |structure|
    raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
  end
end