Generic Database. More...

#include <rdb.h>

Inheritance diagram for RDb:
[legend]

Public Types

enum  Db { MySQL, SQLite, PostgreSQL }
 

Public Member Functions

 RDb (Db type)
 
Db GetType (void) const
 
virtual void CreateTransactionTable (const RString &name, size_t nb,...)
 
virtual size_t GetLastInsertId (void)=0
 
virtual void * InitQuery (const RString &sql, size_raw &nbcols)=0
 
virtual void ReleaseQuery (void *data)=0
 
virtual bool EndQuery (const void *data)=0
 
virtual void StartQuery (void *data)=0
 
virtual void NextQuery (void *data)=0
 
virtual RString GetField (const void *data, size_t index)=0
 
void RunSQLFile (const RURI &file, bool coutit=false)
 
virtual ~RDb (void)
 

Protected Attributes

Db Type
 

Detailed Description

Generic Database.

The RDb pure class provides a representation of connection to a database. Actually, MySQL and SQLite child classes are supported.

Member Enumeration Documentation

enum Db

Type of the databases supported.

Enumerator
MySQL 
SQLite 

MySQL database.

PostgreSQL 

SQLite database. PostgreSQL database.

Constructor & Destructor Documentation

RDb ( Db  type)

Construct a connection to the database.

Parameters
typeType of the database.
virtual ~RDb ( void  )
virtual

Destruct the connection to the database.

Member Function Documentation

Db GetType ( void  ) const

Get the type of the database.

virtual void CreateTransactionTable ( const RString name,
size_t  nb,
  ... 
)
virtual

Create a table that will be used to simulate transactions.

Parameters
nameName of the transaction.
nbNumber of parameters.
...Name of the parameters of the transaction (transid is reserved).
virtual size_t GetLastInsertId ( void  )
pure virtual

Get the last auto-increment identifier inserted.

Implemented in RDbPostgreSQL, RDbMySQL, and RDbSQLite.

virtual void* InitQuery ( const RString sql,
size_raw nbcols 
)
pure virtual

Initialize a query.

Parameters
sqlSQL query.
nbcolsNumber of columns of the query (assigned by the method).
Returns
Pointer to a structure allocated by the database.

Implemented in RDbPostgreSQL, RDbMySQL, and RDbSQLite.

virtual void ReleaseQuery ( void *  data)
pure virtual

Release a query.

Parameters
dataDatabase-dependent data.

Implemented in RDbPostgreSQL, RDbMySQL, and RDbSQLite.

virtual bool EndQuery ( const void *  data)
pure virtual
Parameters
dataDatabase-dependent data.
Returns
true if all the rows of a query are treated.

Implemented in RDbPostgreSQL, RDbMySQL, and RDbSQLite.

virtual void StartQuery ( void *  data)
pure virtual

Start a query.

Parameters
dataDatabase-dependent data.

Implemented in RDbPostgreSQL, RDbMySQL, and RDbSQLite.

virtual void NextQuery ( void *  data)
pure virtual

Read the next row of the query.

Parameters
dataDatabase-dependent data.

Implemented in RDbPostgreSQL, RDbMySQL, and RDbSQLite.

virtual RString GetField ( const void *  data,
size_t  index 
)
pure virtual

Return a specific field of the current row.

Parameters
dataDatabase-dependent data.
indexIndex of the field in the query.

Implemented in RDbPostgreSQL, RDbMySQL, and RDbSQLite.

void RunSQLFile ( const RURI file,
bool  coutit = false 
)

Run file containing SQL commands. The file is supposed to be encoded in utf-8. Lines starting with C comment with "!", "--" or "#" are considered as comments and not send to the database.

Parameters
fileFile to execute.
coutitIf yes, each SQL query is printed on screen.

Field Documentation

Db Type
protected

Type of the database.