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.
|
| SQL & | into (StoreableFilterBase *pFilter) |
| | Specify custom conversion filter which will convert data readed from database into C++ variable.
|
| template<typename T > |
| SQL & | into (T &pVar) |
| | Specify C++ variable where data readed from database should be written.
|
|
dba::SQL & | operator+ (const SQL &pFrom) |
| | Merge two instances of SQL into one.
|
| template<typename T > |
| SQL & | operator<< (const T &pData) |
| | Specify C++ variable for query parameter.
|
| template<typename T > |
| SQL & | operator<< (T *pData) |
| | Specify custom filter class for query parameter.
|
|
SQL & | operator<< (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:
pAr.getOStream().sendUpdate(
dba::SQL("INSERT INTO data(intval,strval) VALUES(:d,:s)") << 1 << "test"
);
std::string strval;
int intval;
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:
-
| SQL |
( |
const std::string & |
pData |
) |
|
Create SQL from string containing SQL query.
- Parameters:
-
Member Function Documentation
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:
-
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:
-
The documentation for this class was generated from the following file: