libcommonc++  0.7
SQLQuery Class Reference

An SQL prepared statement that can be efficiently executed multiple times. More...

#include <SQLQuery.h++>

Public Member Functions

 ~SQLQuery ()
 Destructor. More...
 
void reset ()
 Reset the query so that it can be executed again. More...
 
String toSQL ()
 Get the SQL statement represented by this query. More...
 
void bind (uint_t index)
 Bind a null value to the designated parameter in the query. More...
 
void bind (const String &name)
 Bind a null value to the designated parameter in the query. More...
 
void bind (uint_t index, int value)
 Bind an integer value to the designated parameter in the query. More...
 
void bind (const String &name, int value)
 Bind an integer value to the designated parameter in the query. More...
 
void bind (uint_t index, const int64_t &value)
 Bind a 64-bit integer value to the designated parameter in the query. More...
 
void bind (const String &name, const int64_t &value)
 Bind a 64-bit integer value to the designated parameter in the statement. More...
 
void bind (uint_t index, const double &value)
 Bind a double-precision floating point value to the designated parameter in the query. More...
 
void bind (const String &name, const double &value)
 Bind a double-precision floating point value to the designated parameter in the query. More...
 
void bind (uint_t index, const String &value)
 Bind a String value to the designated parameter in the query. More...
 
void bind (const String &name, const String &value)
 Bind a String value to the designated parameter in the query. More...
 
void bind (uint_t index, const char *value)
 Bind a string value to the designated parameter in the query. More...
 
void bind (const String &name, const char *value)
 Bind a string value to the designated parameter in the query. More...
 
void bind (uint_t index, const Blob &value)
 Bind a Blob value to the designated parameter in the query. More...
 
void bind (const String &name, const Blob &value)
 Bind a Blob value to the designated parameter in the query. More...
 
void clear ()
 Clear the parameter value bindings for the query. More...
 
uint_t getParameterCount ()
 Get the number of parameters in the query. More...
 
void execute ()
 Execute the query. More...
 
bool next ()
 Advance to the next result. More...
 
uint_t getColumnCount ()
 Get the number of columns in the results. More...
 
Variant getColumnValue (uint_t column)
 Get the value for the given column in the current row of the results. More...
 
String getColumnName (uint_t column)
 Get the unaliased name for the given column in the results. More...
 
String getAliasedColumnName (uint_t column)
 Get the aliased name for the given column in the results. More...
 
String getTableName (uint_t column)
 Get the name of the table for the given column in the results. More...
 
int getInt (uint_t column)
 Get the value for the given column in the current row of the results, as an integer. More...
 
int64_t getInt64 (uint_t column)
 Get the value for the given column in the current row of the results, as a 64-bit integer. More...
 
double getDouble (uint_t column)
 Get the value for the given column in the current row of the results, as a double-precision floating point value. More...
 
String getString (uint_t column)
 Get the value for the given column in the current row of the results, as a String. More...
 
Blob getBlob (uint_t column)
 Get the value for the given column in the current row of the results, as a Blob. More...
 

Friends

class SQLDatabase
 

Detailed Description

An SQL prepared statement that can be efficiently executed multiple times.

New values may be bound to the statement's parameters (if any) using the various bind*() methods. Once the statement is executed, the next() method is used to iterate over the result set, and the various get*() methods are used to extract the values from each row of the result set.

A SQLQuery must be reset via a call to reset() before it can be executed again.

An SQLValueBinder may optionally be used to express the parameter value binding and result value extraction in a concise way.

SQLQuery objects should be destroyed before the SQLDatabase that they are associated with is closed.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ~SQLQuery()

~SQLQuery ( )

Destructor.

Member Function Documentation

◆ bind() [1/14]

void bind ( uint_t  index)

Bind a null value to the designated parameter in the query.

Parameters
indexThe index of the parameter (where 1 refers to the first parameter).
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [2/14]

void bind ( const String name)

Bind a null value to the designated parameter in the query.

Parameters
nameThe name of the parameter.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [3/14]

void bind ( uint_t  index,
int  value 
)

Bind an integer value to the designated parameter in the query.

Parameters
indexThe index of the parameter (where 1 refers to the first parameter).
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [4/14]

void bind ( const String name,
int  value 
)

Bind an integer value to the designated parameter in the query.

Parameters
nameThe name of the parameter.
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [5/14]

void bind ( uint_t  index,
const int64_t &  value 
)

Bind a 64-bit integer value to the designated parameter in the query.

Parameters
indexThe index of the parameter (where 1 refers to the first parameter).
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [6/14]

void bind ( const String name,
const int64_t &  value 
)

Bind a 64-bit integer value to the designated parameter in the statement.

Parameters
nameThe name of the parameter.
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [7/14]

void bind ( uint_t  index,
const double &  value 
)

Bind a double-precision floating point value to the designated parameter in the query.

Parameters
indexThe index of the parameter (where 1 refers to the first parameter).
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [8/14]

void bind ( const String name,
const double &  value 
)

Bind a double-precision floating point value to the designated parameter in the query.

Parameters
nameThe name of the parameter.
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [9/14]

void bind ( uint_t  index,
const String value 
)

Bind a String value to the designated parameter in the query.

Parameters
indexThe index of the parameter (where 1 refers to the first parameter).
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [10/14]

void bind ( const String name,
const String value 
)

Bind a String value to the designated parameter in the query.

Parameters
nameThe name of the parameter.
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [11/14]

void bind ( uint_t  index,
const char *  value 
)

Bind a string value to the designated parameter in the query.

Parameters
indexThe index of the parameter (where 1 refers to the first parameter).
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [12/14]

void bind ( const String name,
const char *  value 
)

Bind a string value to the designated parameter in the query.

Parameters
nameThe name of the parameter.
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [13/14]

void bind ( uint_t  index,
const Blob value 
)

Bind a Blob value to the designated parameter in the query.

Parameters
indexThe index of the parameter (where 1 refers to the first parameter).
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ bind() [14/14]

void bind ( const String name,
const Blob value 
)

Bind a Blob value to the designated parameter in the query.

Parameters
nameThe name of the parameter.
valueThe value to bind.
Exceptions
SQLExceptionIf a database error occurs.

◆ clear()

void clear ( )

Clear the parameter value bindings for the query.

Exceptions
SQLExceptionIf a database error occurs.

◆ execute()

void execute ( )

Execute the query.

Exceptions
SQLExceptionIf a database error occurs.
InterruptedExceptionIf the operation was interrupted via a call to SQLDatabase::interrupt().

◆ getAliasedColumnName()

String getAliasedColumnName ( uint_t  column)

Get the aliased name for the given column in the results.

Parameters
columnThe column number (counting from 1).
Returns
The aliased column name.
Exceptions
SQLExceptionIf a database error occurs.

◆ getBlob()

Blob getBlob ( uint_t  column)

Get the value for the given column in the current row of the results, as a Blob.

Parameters
columnThe column number (counting from 1).
Returns
The value, as a Blob.
Exceptions
SQLExceptionIf a database error occurs.

◆ getColumnCount()

uint_t getColumnCount ( )

Get the number of columns in the results.

Exceptions
SQLExceptionIf a database error occurs.
Returns
The column count.

◆ getColumnName()

String getColumnName ( uint_t  column)

Get the unaliased name for the given column in the results.

Parameters
columnThe column number (counting from 1).
Returns
The column name.
Exceptions
SQLExceptionIf a database error occurs.

◆ getColumnValue()

Variant getColumnValue ( uint_t  column)

Get the value for the given column in the current row of the results.

Parameters
columnThe column number (counting from 1).
Returns
The value, as a Variant.
Exceptions
SQLExceptionIf a database error occurs.

◆ getDouble()

double getDouble ( uint_t  column)

Get the value for the given column in the current row of the results, as a double-precision floating point value.

Parameters
columnThe column number (counting from 1).
Returns
The value, as a double.
Exceptions
SQLExceptionIf a database error occurs.

◆ getInt()

int getInt ( uint_t  column)

Get the value for the given column in the current row of the results, as an integer.

Parameters
columnThe column number (counting from 1).
Returns
The value, as an int.
Exceptions
SQLExceptionIf a database error occurs.

◆ getInt64()

int64_t getInt64 ( uint_t  column)

Get the value for the given column in the current row of the results, as a 64-bit integer.

Parameters
columnThe column number (counting from 1).
Returns
The value, as an int64_t.
Exceptions
SQLExceptionIf a database error occurs.

◆ getParameterCount()

uint_t getParameterCount ( )

Get the number of parameters in the query.

Exceptions
SQLExceptionIf a database error occurs.

◆ getString()

String getString ( uint_t  column)

Get the value for the given column in the current row of the results, as a String.

Parameters
columnThe column number (counting from 1).
Returns
The value, as a String.
Exceptions
SQLExceptionIf a database error occurs.

◆ getTableName()

String getTableName ( uint_t  column)

Get the name of the table for the given column in the results.

Parameters
columnThe column number (counting from 1).
Returns
The table name.
Exceptions
SQLExceptionIf a database error occurs.

◆ next()

bool next ( )

Advance to the next result.

Exceptions
SQLExceptionIf a database error occurs.
InterruptedExceptionIf the operation was interrupted via a call to SQLDatabase::interrupt().
TimeoutExceptionIf a timeout occurs while waiting for database locks. The call should be retried in this case.
Returns
true if successful, or false if there are no more results.

◆ reset()

void reset ( )

Reset the query so that it can be executed again.

Exceptions
SQLExceptionIf a database error occurs.

◆ toSQL()

String toSQL ( )

Get the SQL statement represented by this query.

Returns
The SQL statement, as a String.
Exceptions
SQLExceptionIf a database error occurs.

Friends And Related Function Documentation

◆ SQLDatabase

friend class SQLDatabase
friend

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