Class DBI::StatementHandle
In: lib/dbi/handles/statement.rb
Parent: Handle

StatementHandle is the interface the consumer sees after successfully issuing a DatabaseHandle#prepare. They may also be exposed through other methods that send statements to the database.

Almost all methods in this class will raise InterfaceError if the statement is already finished.


Included Modules



dbh  [RW] 

Public Class methods

Public Instance methods

Get an attribute from the StatementHandle object.

Set an attribute on the StatementHandle object.

Instruct successive calls to fetch to cast the type returned into `type`, for row position `pos`. Like all bind_* calls, `pos` indexes starting at 1.

`type` is an object with the DBI::Type calling convention.

This call must be called after execute has successfully ran, otherwise it will raise InterfaceError.


 # `foo` is an integer and this statement will return two rows.
 sth = dbh.prepare("select foo from bar")
 # would raise InterfaceError if called here

 sth.bind_coltype(1, DBI::Type::Varchar)
 # would normally use DBI::Type::Integer and return a Fixnum. We'll make it a string.
 sth.fetch => ["1"]

 # Here we coerce it to Float.
 sth.bind_coltype(1, DBI::Type::Float)
 sth.fetch => [1.0]

Just like BaseStatement#bind_param, but will attempt to convert the type if it‘s supposed to, adhering to the DBD‘s current ruleset.

Cancel the query, closing any open result cursors and truncating any result sets.

The difference between this and finish is that cancelled statements may be re-executed.

Obtains the column names for this query as an array.

Obtain the type mappings for the columns in this query based on ColumnInfo data on the query.

The result will be a position-dependent array of objects that conform to the DBI::Type calling syntax.

Synonym for fetch with a block.

Execute the statement.

This generally means that the statement will be sent to the database and some form of result cursor will be obtained, but is ultimately driver-dependent.

If arguments are supplied, these are fed to bind_param.

See BaseStatement#fetch.

fetch can also take a block which will be applied to each row in a similar fashion to Enumerable#collect. See each.

Fetch the entire result set. Result is array of DBI::Row.

Similar to fetch, but returns Array of Array instead of Array of DBI::Row objects (and therefore does not perform type mapping). This is basically a way to get the raw data from the DBD.

Map the columns and results into an Array of Hash resultset.

No type conversion is performed here. Expect this to change in 0.6.0.

Fetch `cnt` rows. Result is array of DBI::Row

Returns true if the statement is believed to return data upon fetch.

The current reliability of this (and the concept in general) is suspect.

Finish the statement, causing the database to release all assets related to it (any result cursors, normally).

StatementHandles that have already been finished will normally be inoperable and unavailable for further use.

Returns true if the StatementHandle has had finish called on it, explicitly or otherwise.

Should return the row modified count as the result of statement execution.

However, some low-level drivers do not supply this information or supply misleading information (> 0 rows for read-only select statements, f.e.)