Class: ActiveRecord::ConnectionAdapters::SQLiteAdapter

### Home Classes Methods

### In Files

- lib/active_record/connection_adapters/sqlite_adapter.rb

### Parent

ActiveRecord::ConnectionAdapters::AbstractAdapter

### Namespace

- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version

### Methods

- ::new
- #change_column_null
- #default_primary_key_type
- #disconnect!
- #empty_insert_statement_value
- #rename_table
- #requires_reloading?
- #select_rows
- #sqlite_version
- #supports_add_column?
- #supports_ddl_transactions?
- #table_structure
- #translate_exception
- #valid_alter_table_options

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- ActiveRecord
- ActiveRecord::ActiveRecordError
- ActiveRecord::AdapterNotFound
- ActiveRecord::AdapterNotSpecified
- ActiveRecord::Aggregations
- ActiveRecord::Aggregations::ClassMethods
- ActiveRecord::AssociationPreload
- ActiveRecord::AssociationPreload::ClassMethods
- ActiveRecord::AssociationTypeMismatch
- ActiveRecord::Associations
- ActiveRecord::Associations::ClassMethods
- ActiveRecord::Associations::HasOneThroughAssociation
- ActiveRecord::Associations::ThroughAssociationScope
- ActiveRecord::AttributeAssignmentError
- ActiveRecord::AttributeMethods
- ActiveRecord::AttributeMethods::BeforeTypeCast
- ActiveRecord::AttributeMethods::ClassMethods
- ActiveRecord::AttributeMethods::Dirty
- ActiveRecord::AttributeMethods::PrimaryKey
- ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods
- ActiveRecord::AttributeMethods::Query
- ActiveRecord::AttributeMethods::Read
- ActiveRecord::AttributeMethods::Read::ClassMethods
- ActiveRecord::AttributeMethods::TimeZoneConversion
- ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods
- ActiveRecord::AttributeMethods::Write
- ActiveRecord::AttributeMethods::Write::ClassMethods
- ActiveRecord::AutosaveAssociation
- ActiveRecord::AutosaveAssociation::ClassMethods
- ActiveRecord::Base
- ActiveRecord::Calculations
- ActiveRecord::Callbacks
- ActiveRecord::Callbacks::ClassMethods
- ActiveRecord::ConfigurationError
- ActiveRecord::ConnectionAdapters
- ActiveRecord::ConnectionAdapters::AbstractAdapter
- ActiveRecord::ConnectionAdapters::Column
- ActiveRecord::ConnectionAdapters::Column::Format
- ActiveRecord::ConnectionAdapters::ConnectionHandler
- ActiveRecord::ConnectionAdapters::ConnectionManagement
- ActiveRecord::ConnectionAdapters::ConnectionPool
- ActiveRecord::ConnectionAdapters::DatabaseLimits
- ActiveRecord::ConnectionAdapters::DatabaseStatements
- ActiveRecord::ConnectionAdapters::MysqlAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLColumn
- ActiveRecord::ConnectionAdapters::QueryCache
- ActiveRecord::ConnectionAdapters::Quoting
- ActiveRecord::ConnectionAdapters::SQLiteAdapter
- ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version
- ActiveRecord::ConnectionAdapters::SchemaStatements
- ActiveRecord::ConnectionAdapters::Table
- ActiveRecord::ConnectionAdapters::TableDefinition
- ActiveRecord::ConnectionNotEstablished
- ActiveRecord::ConnectionTimeoutError
- ActiveRecord::CounterCache
- ActiveRecord::DangerousAttributeError
- ActiveRecord::DynamicFinderMatch
- ActiveRecord::DynamicScopeMatch
- ActiveRecord::FinderMethods
- ActiveRecord::Generators
- ActiveRecord::Generators::Migration
- ActiveRecord::Generators::MigrationGenerator
- ActiveRecord::Generators::ModelGenerator
- ActiveRecord::Generators::ObserverGenerator
- ActiveRecord::Generators::SessionMigrationGenerator
- ActiveRecord::InvalidForeignKey
- ActiveRecord::IrreversibleMigration
- ActiveRecord::Locking
- ActiveRecord::Locking::Optimistic
- ActiveRecord::Locking::Optimistic::ClassMethods
- ActiveRecord::Locking::Pessimistic
- ActiveRecord::LogSubscriber
- ActiveRecord::Migration
- ActiveRecord::MigrationProxy
- ActiveRecord::MultiparameterAssignmentErrors
- ActiveRecord::NamedScope
- ActiveRecord::NamedScope::ClassMethods
- ActiveRecord::NestedAttributes
- ActiveRecord::NestedAttributes::ClassMethods
- ActiveRecord::NestedAttributes::TooManyRecords
- ActiveRecord::Observer
- ActiveRecord::Persistence
- ActiveRecord::PredicateBuilder
- ActiveRecord::PreparedStatementInvalid
- ActiveRecord::QueryCache
- ActiveRecord::QueryCache::ClassMethods
- ActiveRecord::QueryMethods
- ActiveRecord::Railtie
- ActiveRecord::Railties
- ActiveRecord::Railties::ControllerRuntime
- ActiveRecord::Railties::ControllerRuntime::ClassMethods
- ActiveRecord::ReadOnlyRecord
- ActiveRecord::RecordInvalid
- ActiveRecord::RecordNotFound
- ActiveRecord::RecordNotSaved
- ActiveRecord::RecordNotUnique
- ActiveRecord::Reflection
- ActiveRecord::Reflection::ClassMethods
- ActiveRecord::Reflection::MacroReflection
- ActiveRecord::Relation
- ActiveRecord::Rollback
- ActiveRecord::Schema
- ActiveRecord::Serialization
- ActiveRecord::SerializationTypeMismatch
- ActiveRecord::SessionStore
- ActiveRecord::SessionStore::Session
- ActiveRecord::SessionStore::SqlBypass
- ActiveRecord::SpawnMethods
- ActiveRecord::StaleObjectError
- ActiveRecord::StatementInvalid
- ActiveRecord::TestFixtures
- ActiveRecord::TestFixtures::ClassMethods
- ActiveRecord::ThrowResult
- ActiveRecord::Timestamp
- ActiveRecord::Transactions
- ActiveRecord::Transactions::ClassMethods
- ActiveRecord::UnknownAttributeError
- ActiveRecord::Validations
- ActiveRecord::Validations::AssociatedValidator
- ActiveRecord::Validations::ClassMethods
- ActiveRecord::Validations::UniquenessValidator
- ActiveRecord::WrappedDatabaseException
- <
- Fixtures
- FixturesFileNotFound

No matching classes.

# 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:

- `:database` - Path to the database file.

### 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.