The conversion procs to use for this database
Connect to the database. Since SQLite is a file based database, available options are limited:
database name (filename or ‘:memory:’ or file: URI)
open database in read-only mode; useful for reading static data that you do not want to modify
how long to wait for the database to be available if it is locked, given in milliseconds (default is 5000)
# File lib/sequel/adapters/sqlite.rb, line 105 def connect(server) opts = server_opts(server) opts[:database] = ':memory:' if blank_object?(opts[:database]) sqlite3_opts = {} sqlite3_opts[:readonly] = typecast_value_boolean(opts[:readonly]) if opts.has_key?(:readonly) db = ::SQLite3::Database.new(opts[:database].to_s, sqlite3_opts) db.busy_timeout(opts.fetch(:timeout, 5000)) connection_pragmas.each{|s| log_connection_yield(s, db){db.execute_batch(s)}} class << db attr_reader :prepared_statements end db.instance_variable_set(:@prepared_statements, {}) db end
Disconnect given connections from the database.
# File lib/sequel/adapters/sqlite.rb, line 124 def disconnect_connection(c) c.prepared_statements.each_value{|v| v.first.close} c.close end
Run the given SQL with the given arguments and yield each row.
# File lib/sequel/adapters/sqlite.rb, line 130 def execute(sql, opts=OPTS, &block) _execute(:select, sql, opts, &block) end
Drop any prepared statements on the connection when executing DDL. This is because prepared statements lock the table in such a way that you can’t drop or alter the table while a prepared statement that references it still exists.
# File lib/sequel/adapters/sqlite.rb, line 142 def execute_ddl(sql, opts=OPTS) synchronize(opts[:server]) do |conn| conn.prepared_statements.values.each{|cps, s| cps.close} conn.prepared_statements.clear super end end
Run the given SQL with the given arguments and return the number of changed rows.
# File lib/sequel/adapters/sqlite.rb, line 135 def execute_dui(sql, opts=OPTS) _execute(:update, sql, opts) end
Run the given SQL with the given arguments and return the last inserted row id.
# File lib/sequel/adapters/sqlite.rb, line 151 def execute_insert(sql, opts=OPTS) _execute(:insert, sql, opts) end
# File lib/sequel/adapters/sqlite.rb, line 155 def freeze @conversion_procs.freeze super end
Handle Integer and Float arguments, since SQLite can store timestamps as integers and floats.
# File lib/sequel/adapters/sqlite.rb, line 161 def to_application_timestamp(s) case s when String super when Integer super(Time.at(s).to_s) when Float super(DateTime.jd(s).to_s) else raise Sequel::Error, "unhandled type when converting to : #{s.inspect} (#{s.class.inspect})" end end