Class/Module Index [+]

Quicksearch

Sequel::SQLite::Database

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 Class Methods

new(opts={}) click to toggle source
# File lib/sequel/adapters/sqlite.rb, line 53
def initialize(opts={})
  super
  @conversion_procs = SQLITE_TYPES.dup
  @conversion_procs['timestamp'] = method(:to_application_timestamp)
  @conversion_procs['datetime'] = method(:to_application_timestamp)
end

Public Instance Methods

connect(server) click to toggle source

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

# File lib/sequel/adapters/sqlite.rb, line 64
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
execute(sql, opts={}, &block) click to toggle source

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

# File lib/sequel/adapters/sqlite.rb, line 81
def execute(sql, opts={}, &block)
  _execute(:select, sql, opts, &block)
end
execute_ddl(sql, opts={}) click to toggle source

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 93
def execute_ddl(sql, 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={}) click to toggle source

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

# File lib/sequel/adapters/sqlite.rb, line 86
def execute_dui(sql, opts={})
  _execute(:update, sql, opts)
end
execute_insert(sql, opts={}) click to toggle source

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

# File lib/sequel/adapters/sqlite.rb, line 102
def execute_insert(sql, opts={})
  _execute(:insert, sql, opts)
end
single_value(sql, opts={}) click to toggle source

Run the given SQL with the given arguments and return the first value of the first row.

# File lib/sequel/adapters/sqlite.rb, line 107
def single_value(sql, opts={})
  _execute(:single_value, sql, opts)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.