dbp::odbc::query Class Reference

The ODBC query. More...

#include <query.h>

Collaboration diagram for dbp::odbc::query:
Collaboration graph
[legend]

List of all members.

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< parameterparameters
 The collection of query parameters.
typedef std::vector< fieldfields
 The recordset.

Public Member Functions

 query (const connection &connection)
 Constructor.
virtual ~query ()
 Destructor.
parametersprepare (const std::string &statement)
 Prepare the SQL statement.
queryoperator() (const std::string &statement)
 SQL statement assignment.
const fieldsexecute ()
 Execute the prepared SQL statement.
const fieldsexecute (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 >
queryoperator<< (const T &parameter)
 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 >
queryoperator>> (T &var)
 Query result assignment operator.

Detailed Description

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.


Constructor & Destructor Documentation

dbp::odbc::query::query ( const connection connection  ) 

Constructor.

Initializes the query by odbc connection.

Parameters:
connection the reference to the odbc connection.
virtual dbp::odbc::query::~query (  )  [virtual]

Destructor.

Destroys the query object and releases all its allocated resources.


Member Function Documentation

const fields& dbp::odbc::query::execute ( const std::string &  statement  ) 

Direct execute the SQL statement.

Executes SQL statement without preparing.

Parameters:
statement the SQL statement.
Returns:
the record set fields.
const fields& dbp::odbc::query::execute (  ) 

Execute the prepared SQL statement.

Executes prevuosly prepared SQL statement.

Returns:
the record set fields.
bool dbp::odbc::query::next (  ) 

Fetch resultset row.

Retrieves the next row from resultset and fills the field values with the data retrieved.

Returns:
true, if row is available and false when not.
query& dbp::odbc::query::operator() ( const std::string &  statement  ) 

SQL statement assignment.

The syntax sugar for the query::prepare method.

Parameters:
statement the SQL statement.
template<class T >
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.

Parameters:
statement the SQL statement.
Returns:
the parsed query parameters.

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

 
Support This Project
SourceForge.net Logo