Debea Library 1.4.0

SQL Class Reference

This class allows you to create and send parameterized SQL queries to database and retrieve records directly into C++ variables or classes. More...

#include <sql.h>

List of all members.


Public Member Functions

void appendData (const SQL &pQuery)
 append query, data, filters and placeholders from other query.
void appendFilterData (const SQL &pQuery)
 append filter data *only* from other query
virtual std::string cstring (const FilterMapper &pMapper, const ConvSpec &pSpecs) const
 Create SQL query string replacing parameter specifiers with data using pMapper as filter database and pSpecs for conversion specification.
SQLinto (StoreableFilterBase *pFilter)
 Specify custom conversion filter which will convert data readed from database into C++ variable.
template<typename T >
SQLinto (T &pVar)
 Specify C++ variable where data readed from database should be written.
dba::SQLoperator+ (const SQL &pFrom)
 Merge two instances of SQL into one.
template<typename T >
SQLoperator<< (const T &pData)
 Specify C++ variable for query parameter.
template<typename T >
SQLoperator<< (T *pData)
 Specify custom filter class for query parameter.
SQLoperator<< (const char *pData)
 Specify const char* data for query parameter.
 SQL (const std::string &pData)
 Create SQL from string containing SQL query.
 SQL (const char *pData)
 Create SQL from string containing SQL query.
virtual void updateVars (DbResult &pRes, const FilterMapper &pMapper, const ConvSpec &pSpecs) const
 update variables defined by into() from DbResult.

Static Public Attributes

static const int VAR_INDEX_UNDEFINED
 Next position in sql SELECT.

Detailed Description

This class allows you to create and send parameterized SQL queries to database and retrieve records directly into C++ variables or classes.

Parameters specification in SQL query are:

  • :s - variable should be formated as SQL string, special chars will be escaped depending on if it is value to insert or data for SQL LIKE keyword.
  • :d - variable should be formatted as integer
  • :f - variable should be formatted as floating point number

You can escape ":" by putting double "::" in query.

Conversion between database type and C++ type is done using StoreableFilter instances. dba::SQLArchive has default mappings for all C++ types for which Debea provides filters. You can change those mappings using SQLArchive::mapType(). You can add new filters for other C++ types in the same way.

Use operator<< to feed query with parameter data from C++ variables, and into() to specify C++ variables where data read from database should written.

Some examples:

  //insert some data into table
  pAr.getOStream().sendUpdate(
    dba::SQL("INSERT INTO data(intval,strval) VALUES(:d,:s)") << 1 << "test"
  );

  //vars to put data in
  std::string strval;
  int intval;
  //and read inserted row
  std::auto_ptr<dba::DbResult> res(
    pAr.getIStream().sendQuery(dba::SQL("SELECT strval,intval FROM data").into(strval).into(intval))
  );

see Parameterized SQL statements for complete example.


Constructor & Destructor Documentation

SQL ( const char *  pData  ) 

Create SQL from string containing SQL query.

Parameters:
pData SQL query data

SQL ( const std::string &  pData  ) 

Create SQL from string containing SQL query.

Parameters:
pData SQL query data


Member Function Documentation

SQL& into ( StoreableFilterBase pFilter  ) 

Specify custom conversion filter which will convert data readed from database into C++ variable.

This filter should be constructed with reference to C++ variable where result of conversion should be written

Parameters:
pFilter StoreableFilterBase derived object

SQL& into ( T &  pVar  ) 

Specify C++ variable where data readed from database should be written.

Parameters:
pVar reference to output variable

SQL& operator<< ( const T &  pData  ) 

Specify C++ variable for query parameter.

We copy passed data in this call.

Parameters:
pData C++ variable with data for query parameter

SQL& operator<< ( T *  pData  ) 

Specify custom filter class for query parameter.

Parameters:
pData StoreableFilterBase derived object


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

Documentation
Quick start
Examples

API Documentation
Class hierarchy
Member index
API Reference
Store filters
Store table macros
Back

Generated by doxygen at Fri Feb 26 10:46:21 2010