#include <Query.h>
Public Member Functions | |
Query () noexcept | |
Query (const DatabaseConnection &db, const String &sql="", bool autoPrepare=true) | |
Query (PoolDatabaseConnection *db, const String &sql="", bool autoPrepare=true) | |
Query (const Query &)=delete | |
Query & | operator= (const Query &)=delete |
~Query () override | |
Field & | operator[] (size_t fieldIndex) override |
Field & | operator[] (const String &fieldName) override |
size_t | fieldCount () const override |
size_t | recordCount () const override |
virtual String | sql () const |
virtual void | sql (const String &_sql) |
FieldList & | fields () |
QueryParameterList & | params () |
bool | readField (const char *fname, Variant &value) override |
bool | writeField (const char *fname, const Variant &fvalue) override |
bool | open () override |
bool | close () override |
bool | next () override |
virtual void | exec () |
virtual void | exec (const String &newSQL) |
void | fetch () |
size_t | paramCount () const |
QueryParameter & | param (const char *paramName) const |
QueryParameter & | param (const String ¶mName) const |
QueryParameter & | param (size_t paramIndex) const |
Public Member Functions inherited from sptk::QueryStatementManagement | |
QueryStatementManagement (bool autoPrepare) | |
QueryStatementManagement (const QueryStatementManagement &other)=delete | |
StmtHandle | statement () const |
bool | autoPrepare () const |
bool | active () const |
bool | prepared () const |
bool | eof () const override |
bool | bulkMode () const |
void | connect (PoolDatabaseConnection *db) |
void | disconnect () |
PoolDatabaseConnection * | database () const |
void | database (PoolDatabaseConnection *db) |
Public Member Functions inherited from sptk::DataSource | |
DataSource ()=default | |
virtual | ~DataSource ()=default |
virtual Field & | operator[] (size_t fieldIndex)=0 |
virtual Field & | operator[] (const String &fieldName)=0 |
virtual size_t | fieldCount () const =0 |
virtual size_t | recordCount () const =0 |
virtual bool | readField (const char *fieldName, Variant &fieldValue)=0 |
virtual bool | writeField (const char *fieldName, const Variant &fieldValue)=0 |
virtual bool | open () |
virtual bool | close () |
virtual bool | first () |
virtual bool | next () |
virtual bool | prior () |
virtual bool | last () |
virtual bool | find (const String &, const Variant &) |
virtual bool | eof () const |
bool | load () |
bool | save () |
void | exportRowTo (const xdoc::SNode &node, bool compactXmlMode, bool nullLargeData=false) |
virtual void | exportTo (xdoc::Node &parentNode, const String &nodeName, bool compactXmlMode) |
Static Public Member Functions | |
static void | throwError (const String &method, const String &error) |
Protected Member Functions | |
void | execute () |
bool | loadData () override |
bool | saveData () override |
Protected Member Functions inherited from sptk::QueryStatementManagement | |
void | setDatabase (PoolDatabaseConnection *db) |
void | setStatement (StmtHandle statement) |
void | setPrepared (bool prepared) |
void | setActive (bool active) |
void | setEof (bool eof) |
void | setBulkMode (bool _bulkMode) |
void | closeStmt (bool freeStatement=false) |
void | closeQuery (bool releaseStatement=false) |
Strings & | messages () |
String & | getSQL () |
const String & | getSQL () const |
void | setSQL (const String &sql) |
void | notImplemented (const String &functionName) const |
virtual bool | loadData () |
virtual bool | saveData () |
Friends | |
class | PoolDatabaseConnection |
class | PoolDatabaseConnectionQueryMethods |
Database query
A CDataset connected to the database to execute a database queries. The type of the database depends on the DatabaseConnection object query is connected to.
|
noexcept |
Default constructor
|
explicit |
Constructor
You can optionally provide the name of the file and line number where this query is created. This is used to collect statistical information for the query calls. If file and line information is provided, then calls statistics is stored to the database object during the query dtor.
db | The database to connect to, optional |
sql | The SQL query text to use, optional |
autoPrepare | If true then statement is auto-prepared before execution (if not yet prepared), otherwise it's called directly. Parameter binding is not available in not prepared statements. |
|
explicit |
Constructor
You can optionally provide the name of the file and line number where this query is created. This is used to collect statistical information for the query calls. If file and line information is provided, then calls statistics is stored to the database object during the query dtor.
db | The database to connect to, optional |
sql | The SQL query text to use, optional |
autoPrepare | If true then statement is auto-prepared before execution (if not yet prepared), otherwise it's called directly. Parameter binding is not available in not prepared statements. |
|
delete |
Deleted copy constructor
|
override |
Destructor
|
inlineoverridevirtual |
Closes the query
Doesn't release the db statement, so the query may be called again, and faster than for the first time.
Reimplemented from sptk::DataSource.
|
inlinevirtual |
Executes the query and closes the statement.
Reimplemented in sptk::InsertQuery.
|
inlinevirtual |
Executes the query and closes the statement.
Query SQL would be set to the new SQL statement
newSQL | SQL statement to execute |
Reimplemented in sptk::InsertQuery.
|
protected |
Executes a statement
void sptk::Query::fetch | ( | ) |
Fetches the next row from the recordset, same as next()
|
inlineoverridevirtual |
|
inline |
Returns the query fields list
|
inlineoverrideprotectedvirtual |
In CDataset it should load data into the dataset.
Since the query loads all the data by open() or fetch(), in Query this method does exactly nothing
Reimplemented from sptk::DataSource.
|
inlineoverridevirtual |
Fetches the next row from the recordset, same as fetch()
Reimplemented from sptk::DataSource.
|
overridevirtual |
Opens the query and fetches the first row.
It is necessary for the select queries and some stored procedures that may return the dataset. First-time call for open() also prepares the query.
Reimplemented from sptk::DataSource.
Field access by field name.
Implements sptk::DataSource.
|
inlineoverridevirtual |
Field access by number, const version
Field index should be inside 0..fieldCount()-1
fieldIndex | Field index |
Implements sptk::DataSource.
|
inline |
Returns the parameter by the name.
If the parameter name isn't found, throws an exception
paramName | const char *, parameter name |
|
inline |
Returns the parameter by the name.
If the parameter name isn't found, throws an exception
paramName | Parameter name |
|
inline |
Returns the parameter by the index.
paramIndex | Parameter index |
|
inline |
Reports the number of unique parameters in the query.
Makes sense after the SQL query text is set.
|
inline |
Returns the query parameters list
|
overridevirtual |
Field read access by the field name, for the universal data connection
Implements sptk::DataSource.
|
inlineoverridevirtual |
Reports the record count for the recordset, returned by the open() method.
Currently is NOT implemented.
Implements sptk::DataSource.
|
inlineoverrideprotectedvirtual |
In CDataset it should save data into the dataset.
Since the query saves all the data by execute, in Query this method does exactly nothing
Reimplemented from sptk::DataSource.
|
inlinevirtual |
Returns the text of current SQL query as String
Reimplemented in sptk::InsertQuery.
|
virtual |
Sets SQL Query text. If the Query text is not the same and the db statement was prepared earlier then the db statement is released and new one is created.
Reimplemented in sptk::InsertQuery.
Throws an exception
Before exception is thrown, it is logged into the logfile (if the logfile is defined)
method | Method name where error has occured |
error | Error text |
|
overridevirtual |
Field write access by the field name, for the universal data connection
Implements sptk::DataSource.