class SQLite3::Statement

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/sqlite3/statement.rbs

class SQLite3::Statement
  def active?: () -> bool
  def bind_params: (*(Array[String] | Array[Array, ]) bind_vars) -> Array[String]
  def columns: () -> untyped
  def each: () -> SQLite3::Statement
  def execute: (*Array[String] bind_vars) -> SQLite3::ResultSet
  def execute!: (*Array[String] bind_vars, ) -> Array[Array, String, String]
end

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?

Experimental RBS support (using type sampling data from the type_fusion project).

def active?: () -> bool

This signature was generated using 37 samples from 3 applications.

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

def bind_params( *bind_vars )

Experimental RBS support (using type sampling data from the type_fusion project).

def bind_params: (*(Integer | ) bind_vars) -> Integer

This signature was generated using 45 samples from 5 applications.

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

Experimental RBS support (using type sampling data from the type_fusion project).

def columns: () -> untyped

This signature was generated using 1 sample from 1 application.

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
  return @columns
end

def each

Experimental RBS support (using type sampling data from the type_fusion project).

def each: () -> SQLite3::Statement

This signature was generated using 28 samples from 2 applications.

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

def execute( *bind_vars )

Experimental RBS support (using type sampling data from the type_fusion project).

def execute: (*Integer bind_vars) -> SQLite3::ResultSet

This signature was generated using 33 samples from 4 applications.

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 = ResultSet.new(@connection, self)
  step if 0 == column_count
  yield @results if block_given?
  @results
end

def execute!( *bind_vars, &block )

Experimental RBS support (using type sampling data from the type_fusion project).

def execute!: (*Integer bind_vars, ) ->

This signature was generated using 38 samples from 2 applications.

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_given? ? 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.nil? ? nil : val.downcase
  end
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 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