Note: This class is not available with the PO_NO_DATABASE parse option.
The SQLStatement class provides the most flexibilty for executing SQL on a database server; it allows statements to be executed and result sets to be iteratively returned in all formats supported by Qore (single row at a time as a hash or blocks of rows as either hashes of lists or lists of hashes). The same flexibility of choosing the output format for result sets also applies to output values from stored procedure or function execution, for example.
This class does not differentiate between executing select statement or stored procedures or functions or other SQL code; the transaction lock for Datasource objects and a dedicated connection for DatasourcePool objects is allocated to the object when the connection is necessary, and it is not automatically released by this class. The transaction lock or connection must be manually released by calling SQLStatement::commit() or SQLStatement::rollback() (or the methods with the same name in the parent Datasource or DatasourcePool object).
Here is an example executing a select statement:
{
my SQLStatement $stmt($ds);
# release transaction lock on exit
on_exit $stmt.commit();
$stmt.prepare("select * from table");
while ($stmt.next()) {
my hash $row = $stmt.fetchRow();
do_something($row);
}
}Note that most commands are executed implicitly; for example, in the example above there is no call to SQLStatement::exec() as it is executed implicitly in the call to SQLStatement::next().
The following methods are useful when executing all statements:
The following methods are useful when executing select statements:
The following methods are useful when executing stored procedures, functions, or other non-select SQL statements:
Table 4.675. SQLStatement Method Overview
Method | Except? | Description |
|---|---|---|
Y | Creates the SQLStatement object based on the given Datasource or DatasourcePool object that provides the connection to the database. This method will throw an exception only if the object passed as an argument uses a driver that does not support the prepared statement interface added in Qore version 0.8.1. | |
Y | Closes the statement if it is open and destroys the object. | |
Y | Throws an exception; copying SQLStatement objects is not currently supported. | |
| Y | Saves an SQL statement that will be prepared and executed later, along with optional arguments. |
Y | Saves an SQL statement that will be prepared and executed later; does not parse the SQL string for placeholder specifications and/or bind by value markers. | |
Y | Returns the number of rows affected by the last call to SQLStatement::exec(). | |
Y | Binds placeholder buffer specifications and values to buffers defined in SQLStatement::prepare(). | |
Y | Binds placeholder buffer specifications and values as given in a list argument to buffers defined in SQLStatement::prepare(). | |
Y | Binds placeholder buffer specifications only (values are skipped) to buffers defined in SQLStatement::prepare(). | |
Y | Binds placeholder buffer specifications only (values are skipped) as given in a list argument to buffers defined in SQLStatement::prepare(). | |
Y | Binds value buffer specifications only (placeholder specifications are skipped) to buffers defined in SQLStatement::prepare(). | |
Y | Binds value buffer specifications only (placeholder specifications are skipped) as given in a list argument to buffers defined in SQLStatement::prepare(). | |
Y | Executes the bound statement with any bound buffers, also optionally allows binding placeholder buffer specifications and values to buffers defined in SQLStatement::prepare() before executing the statement. | |
Y | Executes the bound statement with any bound buffers, also optionally allows binding placeholder buffer specifications and values as given in a list argument to buffers defined in SQLStatement::prepare(). | |
Y | Retrieves output buffers as a hash; result sets will be returned as hashes of lists. | |
Y | Retrieves output buffers as a hash; result sets will be returned as lists of hashes. | |
Y | Increments the row pointer when retrieving rows from a select statement; returns | |
Y | Retrieves the current row as a hash where the keys are the column names and the values are the column values. | |
| Y | Retrieves a block of rows as a list of hashes with the maximum number of rows determined by the argument passed; automatically advances the row pointer; with this call it is not necessary to call SQLStatement::next(). |
| Y | Retrieves a block of rows as a hash of lists with the maximum number of rows retrieved determined by the argument passed; automatically advances the row pointer; with this call it is not necessary to call SQLStatement::next(). |
Y | Closes the statement if it is open, however this method does not release the connection or transaction lock. | |
Y | Manually starts a transaction and allocates a connection or grabs the transaction lock according to the object used in the SQLStatement::constructor(). | |
Y | Commits the transaction, releases the connection or the transaction lock according to the object used in the SQLStatement::constructor(), and closes the SQLStatement. | |
Y | Closes the SQLStatement, commits the transaction, and releases the connection or the transaction lock according to the object used in the SQLStatement::constructor(). | |
Y | Closes the SQLStatement, performs a transaction rollback, and releases the connection or the transaction lock according to the object used in the SQLStatement::constructor(). | |
Y | Returns the current SQL string set with the call to SQLStatement::prepare() or SQLStatement::prepareRaw() or NOTHING if no SQL has been set. | |
N | Returns |
Creates the SQLStatement object based on the given Datasource or DatasourcePool object that provides the connection to the database. This method will throw an exception only if the object passed as an argument uses a driver that does not support the prepared statement interface added in Qore version 0.8.1.
my SQLStatement $stmt($ds);Table 4.676. Arguments for SQLStatement::constructor()
Argument | Description |
|---|---|
| The Datasource object to use for the DB connection for the SQLStatement object. |
| The DatasourcePool object to use for the DB connection for the SQLStatement object. |
Table 4.677. Exceptions Thrown by SQLStatement::constructor()
err | desc |
|---|---|
| The DBI driver used by the object passed as the sole argument does not support the prepared statement interface added in Qore 0.8.1. |
Closes the statement if it is open and destroys the object.
Throws an exception; objects of this class cannot be copied.
Table 4.678. Exceptions Thrown by SQLStatement::copy()
err | desc |
|---|---|
| Objects of this class cannot be copied. |
Saves an SQL statement that will be prepared and executed later, along with optional arguments. The statement is actually only prepared when used for the first time, this is so that SQLStatement objects created with DatasourcePool objects use the DatasourcePool more efficiently, as many drivers require the actual DB API prepare call to be made on the same connection as the connection the statement will be executed on as well.
Note that this method parses the SQL string for placeholders and bind by value tokens (%v); for a version of this method that does not parse the SQL string for placeholders and bind by value tokens, see SQLStatement::prepareRaw().
nothingSQLStatement::prepare(string$sql, ...)
$stmt.prepare("select * from table where id = %v and name = %v", $fixed_id);Table 4.679. Arguments for SQLStatement::prepare()
Argument | Description |
|---|---|
| The SQL string to prepare for execution on the DB server. |
| Any optional placeholder specifications (if required by the underlying DBI driver) or bind by value arguments can be given after the SQL string. |
Saves an SQL statement that will be prepared and executed later, along with optional arguments. The statement is actually only prepared when used for the first time, this is so that SQLStatement objects created with DatasourcePool objects use the DatasourcePool more efficiently, as many drivers require the actual DB API prepare call to be made on the same connection as the connection the statement will be executed on as well.
Note that this method does not parse the SQL string for placeholders and bind by value tokens (%v); for a version of this method that does parse the SQL string for placeholders and bind by value tokens, see SQLStatement::prepare().
$stmt.prepareRaw("select * from table where id = %v");Table 4.680. Arguments for SQLStatement::prepareRaw()
Argument | Description |
|---|---|
| The SQL string to prepare for execution on the DB server. |
Binds placeholder buffer specifications and values to buffers defined in SQLStatement::prepare().
If the statement has not previously been prepared with the DB API, it will be implicitly prepared by this method call. This means that this call will cause a connection to be dedicated from a DatasourcePool object or the transaction lock to be grabbed with a Datasource object, depending on the argument to SQLStatement::constructor().
Arguments to buffer specifications must be given in the same order as declared in the string given to the SQLStatement::prepare() method.
Any arguments previously bound will be released when this call is made.
Note that you can also bind directly when calling SQLStatement::exec() or SQLStatement::execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
See also: SQLStatement::bindArgs(), SQLStatement::bindPlaceholders(), SQLStatement::bindPlaceholdersArgs(), SQLStatement::bindValues(), and SQLStatement::bindValuesArgs().
$stmt.prepare("insert into table (id, name) values (%v, %v)");
foreach my hash $h in ($l) {
$stmt.bind($h.id, $h.name);
$stmt.exec();
}Table 4.681. Arguments for SQLStatement::bind()
Argument | Description |
|---|---|
| Arguments to placeholder specifications (if required by the underlying DBI driver) and bind by value arguments. |
Table 4.682. Exceptions Thrown by SQLStatement::bind()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications; see the relevant DBI driver docs for more information |
Binds placeholder buffer specifications and values given as a list in the single argument to the method to buffers defined in SQLStatement::prepare().
If the statement has not previously been prepared with the DB API, it will be implicitly prepared by this method call. This means that this call will cause a connection to be dedicated from a DatasourcePool object or the transaction lock to be grabbed with a Datasource object, depending on the argument to SQLStatement::constructor().
Arguments to buffer specifications must be given in the same order as declared in the string given to the SQLStatement::prepare() method.
Any arguments previously bound will be released when this call is made.
Note that you can also bind directly when calling SQLStatement::exec() or SQLStatement::execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
See also: SQLStatement::bind(), SQLStatement::bindPlaceholders(), SQLStatement::bindPlaceholdersArgs(), SQLStatement::bindValues(), and SQLStatement::bindValuesArgs().
$stmt.prepare("insert into table (id, name) values (%v, %v)");
foreach my hash $h in ($l) {
my list $l = ($h.id, $h.name);
$stmt.bindArgs($l);
$stmt.exec();
}Table 4.683. Arguments for SQLStatement::bindArgs()
Argument | Description |
|---|---|
| Arguments to placeholder specifications (if required by the underlying DBI driver) and bind by value arguments. |
Table 4.684. Exceptions Thrown by SQLStatement::bindArgs()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications; see the relevant DBI driver docs for more information |
Binds placeholder buffer specifications to buffers defined in SQLStatement::prepare().
If the statement has not previously been prepared with the DB API, it will be implicitly prepared by this method call. This means that this call will cause a connection to be dedicated from a DatasourcePool object or the transaction lock to be grabbed with a Datasource object, depending on the argument to SQLStatement::constructor().
Arguments to buffer specifications must be given in the same order as declared in the string given to the SQLStatement::prepare() method. Only placeholder buffer specifications will be processed; value buffer specifications will be skipped by this method.
Any buffer specifications previously defined will be released when this call is made.
Note that you can also bind buffer specifications directly when calling SQLStatement::exec() or SQLStatement::execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
See also: SQLStatement::bind(), SQLStatement::bindArgs(), SQLStatement::bindPlaceholdersArgs(), SQLStatement::bindValues(), and SQLStatement::bindValuesArgs().
$stmt.prepare("begin select sysdate into :sd from dual", Type::Date); end;
$stmt.bindPlaceholders(Type::Date);
my date $d = $stmt.getOutput().sd;Table 4.685. Arguments for SQLStatement::bindPlaceholders()
Argument | Description |
|---|---|
| Arguments to placeholder specifications (if required by the underlying DBI driver). |
Table 4.686. Exceptions Thrown by SQLStatement::bindPlaceholders()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications; see the relevant DBI driver docs for more information |
Binds placeholder buffer specifications given as a list in the single argument to the method to buffers defined in SQLStatement::prepare().
If the statement has not previously been prepared with the DB API, it will be implicitly prepared by this method call. This means that this call will cause a connection to be dedicated from a DatasourcePool object or the transaction lock to be grabbed with a Datasource object, depending on the argument to SQLStatement::constructor().
Arguments to buffer specifications must be given in the same order as declared in the string given to the SQLStatement::prepare() method. Only placeholder buffer specifications will be processed; value buffer specifications will be skipped by this method.
Any arguments previously bound will be released when this call is made.
Note that you can also bind directly when calling SQLStatement::exec() or SQLStatement::execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
See also: SQLStatement::bind(), SQLStatement::bindArgs(), SQLStatement::bindPlaceholders(), SQLStatement::bindValues(), and SQLStatement::bindValuesArgs().
$stmt.prepare("begin select sysdate into :sd from dual", Type::Date); end;
my list $l = list(Type::Date);
$stmt.bindPlaceholdersArgs($l);
my date $d = $stmt.getOutput().sd;Table 4.687. Arguments for SQLStatement::bindPlaceholdersArgs()
Argument | Description |
|---|---|
| Arguments to placeholder specification (if required by the underlying DBI driver). |
Table 4.688. Exceptions Thrown by SQLStatement::bindPlaceholdersArgs()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications; see the relevant DBI driver docs for more information |
Binds values to value buffer specifications to buffers defined in SQLStatement::prepare().
If the statement has not previously been prepared with the DB API, it will be implicitly prepared by this method call. This means that this call will cause a connection to be dedicated from a DatasourcePool object or the transaction lock to be grabbed with a Datasource object, depending on the argument to SQLStatement::constructor().
Arguments must be given in the same order as declared in the string given to the SQLStatement::prepare() method. Only bind by value buffer specifications will be processed by this method; placeholder buffer specifications will be skipped.
Any values previously bound will be released when this call is made.
Note that you can also bind buffer specifications directly when calling SQLStatement::exec() or SQLStatement::execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
See also: SQLStatement::bind(), SQLStatement::bindArgs(), SQLStatement::bindPlaceholders(), SQLStatement::bindPlaceholdersArgs(), and SQLStatement::bindValuesArgs().
$stmt.prepare("insert into table (id, name) values (%v, %v)");
foreach my hash $h in ($l) {
$stmt.bindValues($h.id, $h.name);
$stmt.exec();
}Table 4.689. Arguments for SQLStatement::bindValues()
Argument | Description |
|---|---|
| Arguments to bind by value as per value buffer specifications in the prepared SQL string. |
Table 4.690. Exceptions Thrown by SQLStatement::bindValues()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications; see the relevant DBI driver docs for more information |
Binds values to value buffer specifications given as a list in the single argument to the method to value buffers defined in SQLStatement::prepare().
If the statement has not previously been prepared with the DB API, it will be implicitly prepared by this method call. This means that this call will cause a connection to be dedicated from a DatasourcePool object or the transaction lock to be grabbed with a Datasource object, depending on the argument to SQLStatement::constructor().
Arguments to value buffer specifications must be given in the same order as declared in the string given to the SQLStatement::prepare() method. Only value buffer specifications will be processed by this method; value buffer specifications will be skipped.
Any arguments previously bound will be released when this call is made.
Note that you can also bind directly when calling SQLStatement::exec() or SQLStatement::execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
See also: SQLStatement::bind(), SQLStatement::bindArgs(), SQLStatement::bindValues(), SQLStatement::bindValues(), and SQLStatement::bindValuesArgs().
$stmt.prepare("insert into table (id, name) values (%v, %v)");
foreach my hash $h in ($l) {
my list $l = ($h.id, $h.name);
$stmt.bindValuesArgs($l);
$stmt.exec();
}Table 4.691. Arguments for SQLStatement::bindValuesArgs()
Argument | Description |
|---|---|
| Arguments to bind by value as per value buffer specifications in the prepared SQL string. |
Table 4.692. Exceptions Thrown by SQLStatement::bindValuesArgs()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications; see the relevant DBI driver docs for more information |
Executes the bound statement with any bound buffers, also optionally allows binding placeholder buffer specifications and values to buffers defined in SQLStatement::prepare() before executing the statement.
If the statement has not previously been prepared with the DB API, it will be implicitly prepared by this method call. This means that this call will cause a connection to be dedicated from a DatasourcePool object or the transaction lock to be grabbed with a Datasource object, depending on the argument to SQLStatement::constructor().
Optional arguments to buffer specifications must be given in the same order as declared in the string given to the SQLStatement::prepare() method.
If bind arguments are provided, any arguments previously bound will be released when this call is made.
After calling this method to execute the statement, to retrieve information about the call or output values bound in the call, call SQLStatement::affectedRows(), SQLStatement::getOutput(), or SQLStatement::getOutputRows() as needed. To retrieve rows from a select statement call either SQLStatement::next() and SQLStatement::fetchRow(), or SQLStatement::fetchRows() or SQLStatement::fetchColumns() as needed.
See also: SQLStatement::execArgs().
$stmt.prepare("insert into table (id, name) values (%v, %v)");
foreach my hash $h in ($l) {
$stmt.exec($h.id, $h.name);
}Table 4.693. Arguments for SQLStatement::exec()
Argument | Description |
|---|---|
| Optional arguments to placeholder specifications (if required by the underlying DBI driver) and bind by value arguments can be given in the call to the method; if present, arguments are bound before the statement is executed. |
Table 4.694. Exceptions Thrown by SQLStatement::exec()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare() or SQLStatement::prepareRaw() |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed; see the relevant DBI driver docs for more information |
Executes the bound statement with any bound buffers, also optionally allows binding placeholder buffer specifications and values given as a list in the single argument to the method to buffers defined in SQLStatement::prepare().
If the statement has not previously been prepared with the DB API, it will be implicitly prepared by this method call. This means that this call will cause a connection to be dedicated from a DatasourcePool object or the transaction lock to be grabbed with a Datasource object, depending on the argument to SQLStatement::constructor().
Optional arguments to buffer specifications must be given in the same order as declared in the string given to the SQLStatement::prepare() method.
If bind arguments are provided, any arguments previously bound will be released when this call is made.
After calling this method to execute the statement, to retrieve information about the call or output values bound in the call, call SQLStatement::affectedRows(), SQLStatement::getOutput(), or SQLStatement::getOutputRows() as needed. To retrieve rows from a select statement call either SQLStatement::next() and SQLStatement::fetchRow(), or SQLStatement::fetchRows() or SQLStatement::fetchColumns() as needed.
See also: SQLStatement::exec().
$stmt.prepare("insert into table (id, name) values (%v, %v)");
foreach my hash $h in ($l) {
my list $l = ($h.id, $h.name);
$stmt.execArgs($l);
}Table 4.695. Arguments for SQLStatement::execArgs()
Argument | Description |
|---|---|
| Optional arguments to placeholder specifications (if required by the underlying DBI driver) and bind by value arguments can be given in the call to the method; if present, arguments are bound before the statement is executed. |
Table 4.696. Exceptions Thrown by SQLStatement::execArgs()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed; see the relevant DBI driver docs for more information |
Retrieves output buffers as a hash; result sets will be returned as hashes of lists.
my hash $h = $stmt.getOutput();Table 4.697. Return Values for SQLStatement::getOutput()
Return Type | Description |
|---|---|
Retrieves output buffers as a hash; result sets will be returned as hashes of lists. Each key in the hash is the same as the name given to the placeholder specification in the call to SQLStatement::prepare() or SQLStatement::prepareRaw() |
Table 4.698. Exceptions Thrown by SQLStatement::getOutput()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed or when the output values are retrieved; see the relevant DBI driver docs for more information |
Retrieves output buffers as a hash; result sets will be returned as lists of hashes.
my hash $h = $stmt.getOutputRows();Table 4.699. Return Values for SQLStatement::getOutputRows()
Return Type | Description |
|---|---|
Retrieves output buffers as a hash; result sets will be returned as lists of hashes. Each key in the hash is the same as the name given to the placeholder specification in the call to SQLStatement::prepare() or SQLStatement::prepareRaw() |
Table 4.700. Exceptions Thrown by SQLStatement::getOutputRows()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed or when the output values are retrieved; see the relevant DBI driver docs for more information |
Returns the number of rows affected by the last call to SQLStatement::exec().
my int $rc = $stmt.affectedRows();Table 4.701. Return Values for SQLStatement::affectedRows()
Return Type | Description |
|---|---|
Returns the number of rows affected by the last call to SQLStatement::exec(). |
Table 4.702. Exceptions Thrown by SQLStatement::affectedRows()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed or when the output values are retrieved; see the relevant DBI driver docs for more information |
Increments the row pointer when retrieving rows from a select statement; returns True if there is a row to retrieve, False if not.
If this method returns True, then call SQLStatement::fetchRow() afterwards to retrieve the row.
while ($stmt.next()) { my hash $h = $stmt.fetchRow(); }
Table 4.703. Return Values for SQLStatement::next()
Return Type | Description |
|---|---|
Returns |
Table 4.704. Exceptions Thrown by SQLStatement::next()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed or when the output values are retrieved; see the relevant DBI driver docs for more information |
Retrieves the current row as a hash where the keys are the column names and the values are the column values.
Use with SQLStatement::next() to iterate through the results of a select statement onw row at a time.
while ($stmt.next()) { my hash $h = $stmt.fetchRow(); }
Table 4.705. Return Values for SQLStatement::fetchRow()
Return Type | Description |
|---|---|
Returns the current row as a hash where the keys are the column names and the values are the column values. |
Table 4.706. Exceptions Thrown by SQLStatement::fetchRow()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed or when the output values are retrieved; see the relevant DBI driver docs for more information |
Retrieves a block of rows as a list of hashes with the maximum number of rows determined by the argument passed; automatically advances the row pointer; with this call it is not necessary to call SQLStatement::next().
If the argument passed is omitted or less than or equal to zero, then all available rows from the current row position are retrieved, also if fewer rows are available than requested then only the rows available are retrieved.
If no more rows are available then an empty list is returned.
listSQLStatement::fetchRows(softint$rows = -1)
my list $l = $stmt.fetchRows(-1);Table 4.707. Arguments for SQLStatement::fetchRows()
Argument | Description |
|---|---|
| The maximum number of rows to retrieve, if this argument is omitted, negative, or equal to zero, then all available rows from the current row position are retrieved. |
Table 4.708. Return Values for SQLStatement::fetchRows()
Return Type | Description |
|---|---|
Returns a list of hashes with the maximum number of rows determined by the argument passed. |
Table 4.709. Exceptions Thrown by SQLStatement::fetchRows()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed or when the output values are retrieved; see the relevant DBI driver docs for more information |
Retrieves a block of rows as a hash of lists with the maximum number of rows determined by the argument passed; automatically advances the row pointer; with this call it is not necessary to call SQLStatement::next().
If the argument passed is omitted or less than or equal to zero, then all available rows from the current row position are retrieved, also if fewer rows are available than requested then only the rows available are retrieved.
If no more rows are available then a hash is returned where each key value is an empty list.
hashSQLStatement::fetchColumns(softint$rows = -1)
my hash $h = $stmt.fetchColumns(-1);Table 4.710. Arguments for SQLStatement::fetchColumns()
Argument | Description |
|---|---|
| The maximum number of rows to retrieve, if this argument is omitted, negative, or equal to zero, then all available rows from the current row position are retrieved. |
Table 4.711. Return Values for SQLStatement::fetchColumns()
Return Type | Description |
|---|---|
Returns a hash of lists with the maximum number of rows determined by the argument passed. |
Table 4.712. Exceptions Thrown by SQLStatement::fetchColumns()
err | desc |
|---|---|
| No SQL has been set with SQLStatement::prepare(). |
depends on DBI driver | Exceptions could be thrown by the DBI driver when the statement is prepared or when attempting to bind the given arguments to buffer specifications or when the statement is executed or when the output values are retrieved; see the relevant DBI driver docs for more information |
Closes the statement if it is open, however this method does not release the connection or transaction lock.
$stmt.close();
Manually starts a transaction and allocates a connection or grabs the transaction lock according to the object used in the SQLStatement::constructor().
$stmt.beginTransaction();
Commits the transaction, releases the connection or the transaction lock according to the object used in the SQLStatement::constructor(), and closes the SQLStatement.
$stmt.commit();
For possible exceptions; see DBI driver docs for the commit() method.
Closes the SQLStatement, performs a transaction rollback, and releases the connection or the transaction lock according to the object used in the SQLStatement::constructor().
$stmt.rollback();
For possible exceptions; see DBI driver docs for the commit() method.
Returns the current SQL string set with the call to SQLStatement::prepare() or SQLStatement::prepareRaw() or NOTHING if no SQL has been set.
my *string $sql = $stmt.getSQL();Table 4.713. Return Values for SQLStatement::getSQL()
Return Type | Description |
|---|---|
Returns the current SQL string set with the call to SQLStatement::prepare() or SQLStatement::prepareRaw() or NOTHING if no SQL has been set. |
Returns True if the object is currently active and has a connection or transaction lock allocated to it, or False if not.
if ($stmt.active())
$stmt.commit();Table 4.714. Return Values for SQLStatement::active()
Return Type | Description |
|---|---|
Returns |
There are no comments yet