The ODBC query. More...
#include <query.h>

Classes | |
| class | field |
| Recordset field. More... | |
| class | flush |
| Special class to execute the query via << operator. More... | |
| class | parameter |
| Query parameter. More... | |
Public Types | |
| typedef std::vector< parameter > | parameters |
| The collection of query parameters. | |
| typedef std::vector< field > | fields |
| The recordset. | |
Public Member Functions | |
| query (const connection &connection) | |
| Constructor. | |
| virtual | ~query () |
| Destructor. | |
| parameters & | prepare (const std::string &statement) |
| Prepare the SQL statement. | |
| query & | operator() (const std::string &statement) |
| SQL statement assignment. | |
| const fields & | execute () |
| Execute the prepared SQL statement. | |
| const fields & | execute (const std::string &statement) |
| Direct execute the SQL statement. | |
| bool | next () |
| Fetch resultset row. | |
| void | set_parameter (int num, int value) |
| Set query parameter value. | |
| void | set_parameter (int num, double value) |
| Set query parameter value. | |
| void | set_parameter (int num, const std::string &value) |
| Set query parameter value. | |
| template<class T > | |
| query & | operator<< (const T ¶meter) |
| Query parameter assignment operator. | |
| void | get_field (int num, int &value) |
| Get field value. | |
| void | get_field (int num, double &value) |
| Get field value. | |
| void | get_field (int num, std::string &value) |
| Get field value. | |
| template<class T > | |
| query & | operator>> (T &var) |
| Query result assignment operator. | |
The ODBC query.
The query class represents the single SQL statement. By using this class you can execute any SQL statement to insert, update, delete records from database, select data from database and execute stored procedures.
| dbp::odbc::query::query | ( | const connection & | connection | ) |
Constructor.
Initializes the query by odbc connection.
| connection | the reference to the odbc connection. |
| virtual dbp::odbc::query::~query | ( | ) | [virtual] |
Destructor.
Destroys the query object and releases all its allocated resources.
| const fields& dbp::odbc::query::execute | ( | const std::string & | statement | ) |
Direct execute the SQL statement.
Executes SQL statement without preparing.
| statement | the SQL statement. |
| const fields& dbp::odbc::query::execute | ( | ) |
Execute the prepared SQL statement.
Executes prevuosly prepared SQL statement.
| bool dbp::odbc::query::next | ( | ) |
Fetch resultset row.
Retrieves the next row from resultset and fills the field values with the data retrieved.
| query& dbp::odbc::query::operator() | ( | const std::string & | statement | ) |
SQL statement assignment.
The syntax sugar for the query::prepare method.
| statement | the SQL statement. |
| query& dbp::odbc::query::operator<< | ( | const T & | parameter | ) | [inline] |
Query parameter assignment operator.
Assigns a parameter value to the prepared query. Consecutive execution of the operator assigns the next parameter. To execute the query, pass the special flush object: the query will be executed and you can assign another set of parameters, for example:
query q(db); q("insert into test1 (id, value) values (?, ?)") << 1 << "test1" << query::flush() << 2 << "test2" << query::flush() << 3 << "test3" << query::flush();
References set_parameter().
| parameters& dbp::odbc::query::prepare | ( | const std::string & | statement | ) |
Prepare the SQL statement.
Prepares the SQL statement to execute.
| statement | the SQL statement. |