class Sequel::SQLite::Database

  1. lib/sequel/adapters/sqlite.rb
Parent: SQLite

Database class for SQLite databases used with Sequel and the ruby-sqlite3 driver.

Attributes

conversion_procs [R]

The conversion procs to use for this database

Public Instance methods

connect (server)

Connect to the database. Since SQLite is a file based database, the only options available are :database (to specify the database name), and :timeout, to specify how long to wait for the database to be available if it is locked, given in milliseconds (default is 5000).

[show source]
# File lib/sequel/adapters/sqlite.rb, line 98
def connect(server)
  opts = server_opts(server)
  opts[:database] = ':memory:' if blank_object?(opts[:database])
  db = ::SQLite3::Database.new(opts[:database])
  db.busy_timeout(opts.fetch(:timeout, 5000))
  
  connection_pragmas.each{|s| log_yield(s){db.execute_batch(s)}}
  
  class << db
    attr_reader :prepared_statements
  end
  db.instance_variable_set(:@prepared_statements, {})
  
  db
end
disconnect_connection (c)

Disconnect given connections from the database.

[show source]
# File lib/sequel/adapters/sqlite.rb, line 115
def disconnect_connection(c)
  c.prepared_statements.each_value{|v| v.first.close}
  c.close
end
execute (sql, opts=OPTS, &block)

Run the given SQL with the given arguments and yield each row.

[show source]
# File lib/sequel/adapters/sqlite.rb, line 121
def execute(sql, opts=OPTS, &block)
  _execute(:select, sql, opts, &block)
end
execute_ddl (sql, opts=OPTS)

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.

[show source]
# File lib/sequel/adapters/sqlite.rb, line 133
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
execute_dui (sql, opts=OPTS)

Run the given SQL with the given arguments and return the number of changed rows.

[show source]
# File lib/sequel/adapters/sqlite.rb, line 126
def execute_dui(sql, opts=OPTS)
  _execute(:update, sql, opts)
end
execute_insert (sql, opts=OPTS)

Run the given SQL with the given arguments and return the last inserted row id.

[show source]
# File lib/sequel/adapters/sqlite.rb, line 142
def execute_insert(sql, opts=OPTS)
  _execute(:insert, sql, opts)
end
to_application_timestamp (s)

Handle Integer and Float arguments, since SQLite can store timestamps as integers and floats.

[show source]
# File lib/sequel/adapters/sqlite.rb, line 147
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