Files

Class/Module Index [+]

Quicksearch

ActiveRecord::ConnectionAdapters::SQLiteAdapter

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:

Public Class Methods

new(connection, logger, config) click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 51
def initialize(connection, logger, config)
  super(connection, logger)
  @config = config
end

Public Instance Methods

change_column_null(table_name, column_name, null, default = nil) click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 250
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!() click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 80
def disconnect!
  super
  @connection.close rescue nil
end
empty_insert_statement_value() click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 278
def empty_insert_statement_value
  "VALUES(NULL)"
end
rename_table(name, new_name) click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 214
def rename_table(name, new_name)
  execute "ALTER TABLE #{quote_table_name(name)} RENAME TO #{quote_table_name(new_name)}"
end
requires_reloading?() click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 72
def requires_reloading?
  true
end
select_rows(sql, name = nil) click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 153
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?() click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 76
def supports_add_column?
  sqlite_version >= '3.1.6'
end
supports_ddl_transactions?() click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 60
def supports_ddl_transactions?
  sqlite_version >= '2.0.0'
end
valid_alter_table_options( type, options) click to toggle source

See: www.sqlite.org/lang_altertable.html SQLite has an additional restriction on the ALTER TABLE statement

# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 220
def valid_alter_table_options( type, options)
  type.to_sym != :primary_key
end

Protected Instance Methods

default_primary_key_type() click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 382
def default_primary_key_type
  if supports_autoincrement?
    'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL'
  else
    'INTEGER PRIMARY KEY NOT NULL'
  end
end
sqlite_version() click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 378
def sqlite_version
  @sqlite_version ||= SQLiteAdapter::Version.new(select_value('select sqlite_version(*)'))
end
table_structure(table_name) click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 293
def table_structure(table_name)
  structure = @connection.table_info(quote_table_name(table_name))
  raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty?
  structure
end
translate_exception(exception, message) click to toggle source
# File lib/active_record/connection_adapters/sqlite_adapter.rb, line 390
def translate_exception(exception, message)
  case exception.message
  when /column(s)? .* (is|are) not unique/
    RecordNotUnique.new(message, exception)
  else
    super
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.