Query. More...
#include <rquery.h>
Collaboration diagram for RQuery:
Public Member Functions | |
RQuery (RDb *db, const RString &sql) | |
size_raw | GetNbCols (void) |
bool | End (void) const |
void | Start (void) |
void | Next (void) |
RString | operator[] (size_t index) const |
virtual | ~RQuery (void) |
Static Public Member Functions | |
static RString | SQLValue (const RString val) |
static RString | SQLValue (int val) |
static RString | SQLValue (unsigned int val) |
static RString | SQLValue (long val) |
static RString | SQLValue (unsigned long val) |
static RString | SQLValue (double val) |
static RString | SQLValue (const RDate &d) |
Protected Attributes | |
RDb * | Db |
RString | SQL |
size_raw | NbCols |
void * | Data |
Detailed Description
Query.
The RQuery class provides a representation of a query for a given database.
Here is a example:
#include <iostream>
#include <rdb.h>
using namespace R;
using namespace std;
//----------------------------------------------------------------------------
void LoadMySQL(void)
{
RQuery q(db,"SELECT * FROM tbl");
for(q.Start();!q.End();q.Next())
cout<<"Col 1: "<<q[0]<<" - Col 2:"<<q[1]<<endl;
}
//----------------------------------------------------------------------------
void LoadSQlite(void)
{
RDbSQLite db("/path/to/db.sqlite");
RQuery q(db,"SELECT * FROM tbl");
for(q.Start();!q.End();q.Next())
cout<<"Col 1: "<<q[0]<<" - Col 2:"<<q[1]<<endl;
}
//----------------------------------------------------------------------------
int main(void)
{
try
{
LoadMySQL();
LoadMySQLite();
}
catch(RDbException &e)
{
cout<<"Error: "<<e.GetError()<<endl;
}
}
Constructor & Destructor Documentation
Construct a query.
- Parameters
-
db Database on which the query is done. sql String containing a SQL query.
|
virtual |
Destruct the query.
Member Function Documentation
size_raw GetNbCols | ( | void | ) |
- Returns
- Get the total number of columns of the query.
bool End | ( | void | ) | const |
Look if all rows of the query were treated.
- Returns
- True if all rows were treated.
void Start | ( | void | ) |
Put the query at the first row.
void Next | ( | void | ) |
Increment the current row.
RString operator[] | ( | size_t | index | ) | const |
Return a specific field of the current row.
- Parameters
-
index Index of the field in the query.
Transform a string to be used in a SQL (add quotes before and after, double quotes inside the string).
- Parameters
-
val String containing the value.
- Returns
- a SQL value or NULL if the string is empty.
|
static |
|
static |
|
static |
|
static |
|
static |
Field Documentation
|
protected |
Database on which the query is done.
|
protected |
SQL query.
|
protected |
Number of columns of the query.
|
protected |
Data depending of the database. This data is allocated by the corresponding RDb::InitQuery.