Qore jni Module  1.1.0
org.qore.lang.AbstractSQLStatement Class Reference

Java wrapper for the Qore::SQL::AbstractSQLStatement class in Qore. More...

Inheritance diagram for org.qore.lang.AbstractSQLStatement:
org.qore.jni.QoreObjectWrapper

Public Member Methods

 AbstractSQLStatement (QoreObject ds)
 creates the object
 
void prepare (String sql, Object... args) throws Throwable
 Saves an SQL statement that will be prepared and executed later, along with optional arguments. More...
 
void prepareRaw (String sql) throws Throwable
 Saves an SQL statement that will be prepared and executed later. More...
 
void bind (Object... args) throws Throwable
 Binds placeholder buffer specifications and values to buffers defined in prepare() More...
 
void bindArgs (Object[] vargs) throws Throwable
 Binds placeholder buffer specifications and values given as a list in the single argument to the method to buffers defined in prepare() More...
 
void bindPlaceholders (Object... args) throws Throwable
 Binds placeholder buffer specifications to buffers defined in prepare() More...
 
void bindPlaceholdersArgs (Object[] vargs) throws Throwable
 Binds placeholder buffer specifications given as a list in the single argument to the method to buffers defined in prepare() More...
 
void bindValues (Object... args) throws Throwable
 Binds values to value buffer specifications to buffers defined in prepare() More...
 
void bindValuesArgs (Object[] vargs) throws Throwable
 Binds values to value buffer specifications given as a list in the single argument to the method to value buffers defined in prepare() More...
 
void exec (Object... args) throws Throwable
 Executes the bound statement with any bound buffers, also optionally allows binding placeholder buffer specifications and values to buffers defined in prepare() before executing the statement. More...
 
void execArgs (Object[] vargs) throws Throwable
 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 prepare() More...
 
int affectedRows () throws Throwable
 Returns the number of rows affected by the last call to exec() More...
 
HashMap< String, Object > getOutput () throws Throwable
 Retrieves output buffers as a hash; result sets will be returned as hashes of lists. More...
 
HashMap< String, Object > getOutputRows () throws Throwable
 Retrieves output buffers as a hash; result sets will be returned as lists of hashes. More...
 
void define () throws Throwable
 Performs an explicit define operation on the SQLStatement. More...
 
void close () throws Throwable
 Closes the statement if it is open, however this method does not release the connection or transaction lock. More...
 
void commit () throws Throwable
 Commits the transaction, releases the connection or the transaction lock according to the object used in the constructor and closes the statement. More...
 
void rollback () throws Throwable
 Closes the SQLStatement, performs a transaction rollback, and releases the connection or the transaction lock according to the object used in the constructor, and closes the statement. More...
 
void beginTransaction () throws Throwable
 Manually starts a transaction and allocates a connection or grabs the transaction lock according to the object used in the constructor. More...
 
boolean next () throws Throwable
 Increments the row pointer when retrieving rows from a select statement; returns true if there is a row to retrieve, false if not. More...
 
boolean valid () throws Throwable
 returns true if the object is currently pointing at a valid element, false if not (use when iterating with next()) More...
 
HashMap< String, Object > fetchRow () throws Throwable
 Retrieves the current row as a Map<String, Object> where the keys are the column names and the values are the column values. More...
 
HashMap< String, Object > getValue () throws Throwable
 Retrieves the current row as a Map<String, Object> where the keys are the column names and the values are the column values. More...
 
HashMap< String, Object > [] fetchRows (int rows) throws Throwable
 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 next() More...
 
HashMap< String, Object > [] fetchRows () throws Throwable
 Retrieves all available rows as a list of hashes; automatically advances the row pointer; with this call it is not necessary to call next() More...
 
HashMap< String, Object > fetchColumns (int rows) throws Throwable
 Retrieves a block of rows as a Map<String, Object> 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 next(). More...
 
HashMap< String, Object > fetchColumns () throws Throwable
 Retrieves all available rows as a Map<String, Object> of lists; automatically advances the row pointer; with this call it is not necessary to call next(). More...
 
HashMap< String, Object > describe () throws Throwable
 Describes columns in the statement result. More...
 
String getSQL () throws Throwable
 Returns the current SQL string set with the call to prepare() or prepareRaw() or void if no SQL has been set. More...
 
boolean active () throws Throwable
 Returns true if the object is currently active and has a connection or transaction lock allocated to it, or false if not. More...
 
boolean currentThreadInTransaction () throws Throwable
 Returns true if the current thread is in a transaction (i.e. holds the transaction lock), false if not. More...
 
- Public Member Methods inherited from org.qore.jni.QoreObjectWrapper
 QoreObjectWrapper (QoreObject obj)
 creates the wrapper object with the Qore object
 
void release ()
 releases the Qore object; do not call any further methods on the object after this call
 
QoreObject getQoreObject ()
 returns the Qore object
 
String className ()
 returns the class name for the Qore object
 
boolean instanceOf (String class_name)
 returns true if the object is an instance of the given class
 

Additional Inherited Members

- Private Attributes inherited from org.qore.jni.QoreObjectWrapper
QoreObject obj
 the wrapper Qore object
 

Detailed Description

Java wrapper for the Qore::SQL::AbstractSQLStatement class in Qore.

Example:
{
AbstractSQLStatement stmt = ds.getSQLStatement();
try {
stmt.prepare("select * from table");
stmt.exec();
stmt.define();
// note that the next() would implicitly execute exec() and define()
while (stmt.next()) {
Map<String, Object> row = stmt.fetchRow();
process(row);
}
// release transaction lock on exit
stmt.commit();
} catch (Throwable e) {
stmt.rollback();
throw e;
} finally {
stmt.release();
}
}

Member Function Documentation

◆ active()

boolean org.qore.lang.AbstractSQLStatement.active ( ) throws Throwable
inline

Returns true if the object is currently active and has a connection or transaction lock allocated to it, or false if not.

Returns
true if the object is currently active and has a connection or transaction lock allocated to it, or false if not
Example:
if (stmt.active()) {
stmt.commit();
}

◆ affectedRows()

int org.qore.lang.AbstractSQLStatement.affectedRows ( ) throws Throwable
inline

Returns the number of rows affected by the last call to exec()

Returns
the number of rows affected by the last call to exec()
Example:
int rc = stmt.affectedRows();
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
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

◆ beginTransaction()

void org.qore.lang.AbstractSQLStatement.beginTransaction ( ) throws Throwable
inline

Manually starts a transaction and allocates a connection or grabs the transaction lock according to the object used in the constructor.

Example:
stmt.beginTransaction();

◆ bind()

void org.qore.lang.AbstractSQLStatement.bind ( Object...  args) throws Throwable
inline

Binds placeholder buffer specifications and values to buffers defined in 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 constructor.

Arguments to buffer specifications must be given in the same order as declared in the string given to the prepare() method.

Any arguments previously bound will be released when this call is made.

Note
You can also bind directly when calling exec() or execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
Parameters
argsArguments to placeholder specifications (if required by the underlying DBI driver) and bind by value arguments
Example:
stmt.prepare("insert into table (id, name) values (%v, %v)");
stmt.bind(h.get("id"), h.get("name"));
stmt.exec();
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare()
Note
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
See also
bindArgs(), bindPlaceholders(), bindPlaceholdersArgs(), bindValues(), and bindValuesArgs()

◆ bindArgs()

void org.qore.lang.AbstractSQLStatement.bindArgs ( Object []  vargs) throws Throwable
inline

Binds placeholder buffer specifications and values given as a list in the single argument to the method to buffers defined in 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 constructor.

Arguments to buffer specifications must be given in the same order as declared in the string given to the prepare() method.

Any arguments previously bound will be released when this call is made.

Note
You can also bind directly when calling exec() or execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
Parameters
vargsArguments to placeholder specifications (if required by the underlying DBI driver) and bind by value arguments
Example:
stmt.prepare("insert into table (id, name) values (%v, %v)");
stmt.bindArgs(args);
stmt.exec();
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare()
Note
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
See also
bind(), bindPlaceholders(), bindPlaceholdersArgs(), bindValues(), and bindValuesArgs()

◆ bindPlaceholders()

void org.qore.lang.AbstractSQLStatement.bindPlaceholders ( Object...  args) throws Throwable
inline

Binds placeholder buffer specifications to buffers defined in 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 constructor.

Arguments to buffer specifications must be given in the same order as declared in the string given to the 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
You can also bind buffer specifications directly when calling exec() or execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.

Not all DBI drivers require binding placeholders specification.
Parameters
argsArguments to placeholder specifications (if required by the underlying DBI driver)
Example:
stmt.prepare("begin select sysdate into :sd from dual", "date"); end;
stmt.bindPlaceholders(Type::Date);
ZonedDateTime d = stmt.getOutput().get("sd");
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare()
Note
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
See also
bind(), bindArgs(), bindPlaceholdersArgs(), bindValues(), and bindValuesArgs()

◆ bindPlaceholdersArgs()

void org.qore.lang.AbstractSQLStatement.bindPlaceholdersArgs ( Object []  vargs) throws Throwable
inline

Binds placeholder buffer specifications given as a list in the single argument to the method to buffers defined in 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 constructor.

Arguments to buffer specifications must be given in the same order as declared in the string given to the 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
You can also bind buffer specifications directly when calling exec() or execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.

Not all DBI drivers require binding placeholders specification.
Parameters
vargsArguments to placeholder specifications (if required by the underlying DBI driver)
Example:
stmt.prepare("begin select sysdate into :sd from dual", "date"); end;
stmt.bindPlaceholdersArgs(args);
ZonedDateTime d = stmt.getOutput().get("sd");
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare()
Note
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
See also
bind(), bindArgs(), bindPlaceholders(), bindValues(), and bindValuesArgs()

◆ bindValues()

void org.qore.lang.AbstractSQLStatement.bindValues ( Object...  args) throws Throwable
inline

Binds values to value buffer specifications to buffers defined in 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 constructor.

Arguments to buffer specifications must be given in the same order as declared in the string given to the prepare() method.

Any values previously bound will be released when this call is made.

Note
You can also bind directly when calling exec() or execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
Parameters
argsArguments to bind by value arguments
Example:
stmt.prepare("insert into table (id, name) values (%v, %v)");
stmt.exec(h.get("id"), h.get("name"));
stmt.exec();
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare()
Note
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
See also
bind(), bindArgs(), bindPlaceholders(), bindPlaceholdersArgs(), and bindValuesArgs().

◆ bindValuesArgs()

void org.qore.lang.AbstractSQLStatement.bindValuesArgs ( Object []  vargs) throws Throwable
inline

Binds values to value buffer specifications given as a list in the single argument to the method to value buffers defined in 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 constructor.

Arguments to buffer specifications must be given in the same order as declared in the string given to the prepare() method.

Any values previously bound will be released when this call is made.

Note
You can also bind directly when calling exec() or execArgs() as a shortcut as well, in which case it's not necessary to make an extra call to this method.
Parameters
vargsArguments to bind by value arguments
Example:
stmt.prepare("insert into table (id, name) values (%v, %v)");
stmt.bindValuesArgs(args);
stmt.exec();
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare()
Note
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

◆ close()

void org.qore.lang.AbstractSQLStatement.close ( ) throws Throwable
inline

Closes the statement if it is open, however this method does not release the connection or transaction lock.

Example:
stmt.close();

◆ commit()

void org.qore.lang.AbstractSQLStatement.commit ( ) throws Throwable
inline

Commits the transaction, releases the connection or the transaction lock according to the object used in the constructor and closes the statement.

Example:
stmt.commit();
Note
For possible exceptions; see DBI driver docs for the commit() method

◆ currentThreadInTransaction()

boolean org.qore.lang.AbstractSQLStatement.currentThreadInTransaction ( ) throws Throwable
inline

Returns true if the current thread is in a transaction (i.e. holds the transaction lock), false if not.

Returns
true if the current thread is in a transaction (i.e. holds the transaction lock), false if not
Example:
boolean b = stmt.currentThreadInTransaction();

◆ define()

void org.qore.lang.AbstractSQLStatement.define ( ) throws Throwable
inline

Performs an explicit define operation on the SQLStatement.

It is not encessary to call this method manually; define operations are implicitly executed when needed when retrieving values from a select statement

Example:
{
AbstractSQLStatement stmt = ds.getSQLStatement();
try {
stmt.prepare("select * from table");
stmt.exec();
stmt.define();
// note that the next() would implicitly execute exec() and define()
while (stmt.next()) {
Map<String, Object> row = stmt.fetchRow();
process(row);
}
// release transaction lock on exit
stmt.commit();
} catch (Throwable e) {
stmt.rollback();
throw e;
} finally {
stmt.release();
}
}

◆ describe()

HashMap<String, Object> org.qore.lang.AbstractSQLStatement.describe ( ) throws Throwable
inline

Describes columns in the statement result.

Returns
a Map<String, Object> with (column_name: description_hash) format, where each description_hash has the following keys:
  • "name": (string) the column name
  • "type": (integer) the column type code (Qore type code)
  • "maxsize": (integer) the maximum size of the column
  • "native_type": (string) the database-specific name of the type
  • "internal_id": (integer) the database-specific type code of the type

◆ exec()

void org.qore.lang.AbstractSQLStatement.exec ( Object...  args) throws Throwable
inline

Executes the bound statement with any bound buffers, also optionally allows binding placeholder buffer specifications and values to buffers defined in 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 constructor.

Optional arguments to buffer specifications must be given in the same order as declared in the string given to the 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 affectedRows(), getOutput(), or getOutputRows() as needed.

To retrieve rows from a select statement call either next() and fetchRow(), or fetchRows() or fetchColumns() as needed.

Parameters
argsOptional 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
Example:
stmt.prepare("insert into table (id, name) values (%v, %v)");
stmt.exec(h.get("id"), h.get("name"));
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare(); the SQLStatement uses a DatasourcePool an the statement was prepared on another connection
Note
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
See also
execArgs()

◆ execArgs()

void org.qore.lang.AbstractSQLStatement.execArgs ( Object []  vargs) throws Throwable
inline

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

Optional arguments to buffer specifications must be given in the same order as declared in the string given to the 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 affectedRows(), getOutput(), or getOutputRows() as needed.

To retrieve rows from a select statement call either next() and fetchRow(), or fetchRows() or fetchColumns() as needed.

Parameters
vargsOptional 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
Example:
stmt.prepare("insert into table (id, name) values (%v, %v)");
stmt.execArgs(args);
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw(); the SQLStatement uses a DatasourcePool an the statement was prepared on another connection
Note
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
See also
exec()

◆ fetchColumns() [1/2]

HashMap<String, Object> org.qore.lang.AbstractSQLStatement.fetchColumns ( int  rows) throws Throwable
inline

Retrieves a block of rows as a Map<String, Object> 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 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.

Parameters
rowsThe 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
Returns
a Map<String, Object> (giving column names) of lists (giving row values for each column) of data returned; each list will have at most rows elements (unless rows is negative, in which case all available rows are returned). If the total number of rows available is less than rows (if rows is positive), then the last data returned by this method may return short lists. If no more rows are available, then an empty Map<String, Object> is returned
Example:
Map<String, Object> h = stmt.fetchColumns(-1);
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
  • There is no need to call next() when calling this method; the method automatically iterates through the given number of rows
  • 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 row values are retrieved; see the relevant DBI driver docs for more information

◆ fetchColumns() [2/2]

HashMap<String, Object> org.qore.lang.AbstractSQLStatement.fetchColumns ( ) throws Throwable
inline

Retrieves all available rows as a Map<String, Object> of lists; automatically advances the row pointer; with this call it is not necessary to call next().

Example:
Map<String, Object> h = stmt.fetchColumns();
Returns
a Map<String, Object> (giving column names) of lists (giving row values for each column) of data returned; each list will have at most rows elements (unless rows is negative, in which case all available rows are returned). If the total number of rows available is less than rows (if rows is positive), then the last data returned by this method may return short lists. If no more rows are available, then an empty Map<String, Object> is returned
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
  • There is no need to call next() when calling this method; the method automatically iterates through the given number of rows
  • 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 row values are retrieved; see the relevant DBI driver docs for more information

◆ fetchRow()

HashMap<String, Object> org.qore.lang.AbstractSQLStatement.fetchRow ( ) throws Throwable
inline

Retrieves the current row as a Map<String, Object> where the keys are the column names and the values are the column values.

Use with next() to iterate through the results of a select statement one row at a time

Returns
the current row as a Map<String, Object> where the keys are the column names and the values are the column values
Example:
while (stmt.next()) {
Map<String, Object> h = stmt.fetchRow();
process(h);
}
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
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 row values are retrieved; see the relevant DBI driver docs for more information

◆ fetchRows() [1/2]

HashMap<String, Object> [] org.qore.lang.AbstractSQLStatement.fetchRows ( int  rows) throws Throwable
inline

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

Parameters
rowsThe 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
Example:
Map<String, Object>[] l = stmt.fetchRows(-1);
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
  • There is no need to call next() when calling this method; the method automatically iterates through the given number of rows
  • 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 row values are retrieved; see the relevant DBI driver docs for more information

◆ fetchRows() [2/2]

HashMap<String, Object> [] org.qore.lang.AbstractSQLStatement.fetchRows ( ) throws Throwable
inline

Retrieves all available rows as a list of hashes; automatically advances the row pointer; with this call it is not necessary to call next()

Example:
Map<String, Object>[] l = stmt.fetchRows();

If no more rows are available then an empty list is returned.

Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
  • There is no need to call next() when calling this method; the method automatically iterates through the given number of rows
  • 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 row values are retrieved; see the relevant DBI driver docs for more information

◆ getOutput()

HashMap<String, Object> org.qore.lang.AbstractSQLStatement.getOutput ( ) throws Throwable
inline

Retrieves output buffers as a hash; result sets will be returned as hashes of lists.

Returns
Returns a Map<String, Object> of output buffers; result sets will be returned as hashes of lists. Each key in the Map<String, Object> is the same as the name given to the placeholder specification in the call to prepare() or prepareRaw()
Example:
Map<String, Object> h = stmt.getOutput();
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
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 output values are retrieved; see the relevant DBI driver docs for more information

◆ getOutputRows()

HashMap<String, Object> org.qore.lang.AbstractSQLStatement.getOutputRows ( ) throws Throwable
inline

Retrieves output buffers as a hash; result sets will be returned as lists of hashes.

Returns
Retrieves output buffers as a hash; result sets will be returned as lists of hashes. Each key in the Map<String, Object> is the same as the name given to the placeholder specification in the call to prepare() or prepareRaw()
Example:
Map<String, Object> h = stmt.getOutputRows();
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
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 output values are retrieved; see the relevant DBI driver docs for more information

◆ getSQL()

String org.qore.lang.AbstractSQLStatement.getSQL ( ) throws Throwable
inline

Returns the current SQL string set with the call to prepare() or prepareRaw() or void if no SQL has been set.

Returns
Returns the current SQL string set with the call to prepare() or prepareRaw() or void if no SQL has been set
Example:
String sql = stmt.getSQL();

◆ getValue()

HashMap<String, Object> org.qore.lang.AbstractSQLStatement.getValue ( ) throws Throwable
inline

Retrieves the current row as a Map<String, Object> where the keys are the column names and the values are the column values.

Use with next() to iterate through the results of a select statement one row at a time

Returns
the current row as a Map<String, Object> where the keys are the column names and the values are the column values
Example:
while (stmt.next()) {
Map<String, Object> h = stmt.getValue();
process(h);
}
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
  • Equivalent to fetchRow()
  • 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 row values are retrieved; see the relevant DBI driver docs for more information

◆ next()

boolean org.qore.lang.AbstractSQLStatement.next ( ) throws Throwable
inline

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 fetchRow() afterwards to retrieve the row

Returns
true if there is a row to retrieve, false if not (no more rows to be retrieved)
Example:
while (stmt.next()) {
Map<String, Object> h = stmt.fetchRow();
process(h);
}
Exceptions
SQLSTATEMENT-ERRORNo SQL has been set with prepare() or prepareRaw()
Note
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

◆ prepare()

void org.qore.lang.AbstractSQLStatement.prepare ( String  sql,
Object...  args 
) throws Throwable
inline

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
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 prepareRaw().
Parameters
sqlThe SQL string to prepare for execution on the DB server
argsThe arguments for any bind placeholders
Example:
stmt.prepare("select * from table where id = %v");

◆ prepareRaw()

void org.qore.lang.AbstractSQLStatement.prepareRaw ( String  sql) throws Throwable
inline

Saves an SQL statement that will be prepared and executed later.

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
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 prepare().
Parameters
sqlThe SQL string to prepare for execution on the DB server
Example:
stmt.prepareRaw("select * from table");

◆ rollback()

void org.qore.lang.AbstractSQLStatement.rollback ( ) throws Throwable
inline

Closes the SQLStatement, performs a transaction rollback, and releases the connection or the transaction lock according to the object used in the constructor, and closes the statement.

Example:
stmt.rollback();
Note
For possible exceptions; see DBI driver docs for the rollback() method

◆ valid()

boolean org.qore.lang.AbstractSQLStatement.valid ( ) throws Throwable
inline

returns true if the object is currently pointing at a valid element, false if not (use when iterating with next())

Returns
true if the object is currently pointing at a valid element, false if not
Example:
if (i.valid()) {
process(i.getValue());
}

The documentation for this class was generated from the following file: