class SQLite3::Statement

via the Database#prepare method.
(if ever) be instantiated directly by a client, and is most often obtained
A statement represents a prepared-but-unexecuted SQL query. It will rarely

def active?

open result set.
Returns true if the statement is currently active, meaning it has an
def active?
  !done?
end

def bind_params(*bind_vars)

Statement#bind_params.
See also #execute, #bind_param, Statement#bind_param, and

stmt.bind_params( 15, "hello" )
stmt = db.prepare( "select * from table where a=? and b=?" )

Example:

syntaxes.
See Database#execute for a description of the valid placeholder

text.
Binds the given variables to the corresponding placeholders in the SQL
def bind_params(*bind_vars)
  index = 1
  bind_vars.flatten.each do |var|
    if Hash === var
      var.each { |key, val| bind_param key, val }
    else
      bind_param index, var
      index += 1
    end
  end
end

def columns

a (potentially) expensive operation.
may execute the statement in order to obtain the metadata; this makes it
Return an array of the column names for this statement. Note that this
def columns
  get_metadata unless @columns
  @columns
end

def each

def each
  loop do
    val = step
    break self if done?
    yield val
  end
end

def execute(*bind_vars)

See also #bind_params, #execute!.

end
...
stmt.execute do |result|
stmt = db.prepare( "select * from table" )

Example:

Any parameters will be bound to the statement using #bind_params.

be yielded to it; otherwise, the ResultSet will be returned.
statement's virtual machine. If a block was given, the new ResultSet will
Execute the statement. This creates a new ResultSet object for the
def execute(*bind_vars)
  reset! if active? || done?
  bind_params(*bind_vars) unless bind_vars.empty?
  results = @connection.build_result_set self
  step if column_count == 0
  yield results if block_given?
  results
end

def execute!(*bind_vars, &block)

See also #bind_params, #execute.

end
...
stmt.execute! do |row|
stmt = db.prepare( "select * from table" )

Example:

Any parameters will be bound to the statement using #bind_params.

yielded to the block.
rows returned by executing the statement. Otherwise, each row will be
Execute the statement. If no block was given, this returns an array of
def execute!(*bind_vars, &block)
  execute(*bind_vars)
  block ? each(&block) : to_a
end

def get_metadata

(potentially) expensive operation.
that this will actually execute the SQL, which means it can be a
A convenience method for obtaining the metadata about the query. Note
def get_metadata
  @columns = Array.new(column_count) do |column|
    column_name column
  end
  @types = Array.new(column_count) do |column|
    val = column_decltype(column)
    val&.downcase
  end
end

def initialize(db, sql)

will be set to the trailing text.
statement (i.e., separated by semicolons), then the #remainder property
encapsulates the given SQL text. If the text contains more than one
Create a new statement attached to the given Database instance, and which

call-seq: SQLite3::Statement.new(db, sql)
def initialize(db, sql)
  raise ArgumentError, "prepare called on a closed database" if db.closed?
  sql = sql.encode(Encoding::UTF_8) if sql && sql.encoding != Encoding::UTF_8
  @connection = db
  @columns = nil
  @types = nil
  @remainder = prepare db, sql
end

def must_be_open! # :nodoc:

:nodoc:
closed. If it is, an exception is raised.
Performs a sanity check to ensure that the statement is not
def must_be_open! # :nodoc:
  if closed?
    raise SQLite3::Exception, "cannot use a closed statement"
  end
end

def stat key = nil

because a Bloom filter returned not-found
- +filter_hits+: the number of times that a join step was bypassed
a find, and thus the join step had to be processed as normal
- +filter_misses+: the number of times that the Bloom filter returned
- +runs+: the number of times that the prepared statement has been run
parameters that might affect the query plan
automatically regenerated due to schema changes or changes to bound
- +reprepares+: the number of times that the prepare statement has been
prepared statement
- +vm_steps+: the number of virtual machine operations executed by the
that were created automatically in order to help joins run faster
- +autoindexes+: the number of rows inserted into transient indices
- +sorts+: the number of sort operations that have occurred
in a table as part of a full table scan
- +fullscan_steps+: the number of times that SQLite has stepped forward
statistics about the statement such as:
the future without notice. The hash includes information about internal
The contents of the hash are implementation specific and may change in
Returns a Hash containing information about the statement.
def stat key = nil
  if key
    stat_for(key)
  else
    stats_as_hash
  end
end

def types

makes it a (potentially) expensive operation.
that this may execute the statement in order to obtain the metadata; this
Return an array of the data types for each column in this statement. Note
def types
  must_be_open!
  get_metadata unless @types
  @types
end