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.
- C
- D
- E
- L
- N
- R
- S
- T
- V
- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::BindSubstitution
- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::ExplainPrettyPrinter
- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::StatementPool
- CLASS ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 77 77: def initialize(connection, logger, config) 78: super(connection, logger) 79: @statements = StatementPool.new(@connection, 80: config.fetch(:statement_limit) { 1000 }) 81: @config = config 82: 83: if config.fetch(:prepared_statements) { true } 84: @visitor = Arel::Visitors::SQLite.new self 85: else 86: @visitor = BindSubstitution.new self 87: end 88: end
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 432 432: def change_column_null(table_name, column_name, null, default = nil) 433: unless null || default.nil? 434: exec_query("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote(default)} WHERE #{quote_column_name(column_name)} IS NULL") 435: end 436: alter_table(table_name) do |definition| 437: definition[column_name].null = null 438: end 439: end
Clears the prepared statements cache.
Disconnects from the database if already connected. Otherwise, this method does nothing.
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 241 241: def exec_query(sql, name = nil, binds = []) 242: log(sql, name, binds) do 243: 244: # Don't cache statements without bind values 245: if binds.empty? 246: stmt = @connection.prepare(sql) 247: cols = stmt.columns 248: records = stmt.to_a 249: stmt.close 250: stmt = records 251: else 252: cache = @statements[sql] ||= { 253: :stmt => @connection.prepare(sql) 254: } 255: stmt = cache[:stmt] 256: cols = cache[:cols] ||= stmt.columns 257: stmt.reset! 258: stmt.bind_params binds.map { |col, val| 259: type_cast(val, col) 260: } 261: end 262: 263: ActiveRecord::Result.new(cols, stmt.to_a) 264: end 265: end
Alias for exec_delete
DATABASE STATEMENTS ======================================
Renames a table.
Example:
rename_table('octopuses', 'octopi')
Returns true if SQLite version is ‘3.1.6’ or greater, false otherwise.
Returns true if SQLite version is ‘2.0.0’ or greater, false otherwise.
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/sqlite_adapter.rb, line 471 471: def table_structure(table_name) 472: structure = exec_query("PRAGMA table_info(#{quote_table_name(table_name)})", 'SCHEMA').to_hash 473: raise(ActiveRecord::StatementInvalid, "Could not find table '#{table_name}'") if structure.empty? 474: structure 475: end
# File activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb, line 569 569: def translate_exception(exception, message) 570: case exception.message 571: when /column(s)? .* (is|are) not unique/ 572: RecordNotUnique.new(message, exception) 573: else 574: super 575: end 576: end