tntdb Namespace Reference

Main namespace for Tntdb. More...

## Classes

class | ConnectionPool
class | ConnectionPools
class | Date
| This class holds a date. More...
class | Datetime
| This class holds a date and a time. More...
class | Decimal
class | Error
| Base class for database errors. More...
class | NotFound
| Exception thrown when selectRow or selectValue doesn't fetch any data. More...
class | NullValue
| Exception thrown when a Value::get...() is called on a NULL value. More...
class | TypeError
| Exception thrown when a Value can't be converted to a requested type. More...
class | SqlError
| Exception thrown when the execution of an SQL statement caused an error. More...
class | FieldNotFound
class | LibraryManager
class | SqlBuilder
| Helper class for building sql statements. More...
class | StmtEvent
class | Time
| This class holds a time. More...
class | Transaction
| The class Transaction monitors the state of a transaction on a database connection. More...
class | Blob
| Binary large objects. More...
class | BlobStreamBuf
| streambuf for reading from a tntdb::Blob More...
class | BlobIStream
| istream for reading from a tntdb::Blob More...
class | Connection
| This class holds a connection to a database. More...
class | Result
| The class holds a resultset of a query. More...
class | Row
| Row represents a row, which is fetched from the database. More...
class | RowReader
| A RowReader is a class which helps reading multiple columns from a row. More...
class | Statement
| This class represents an SQL statement. More...
class | Hostvar
| Helper class to hold a Statement and a column name. More...
class | Value
| The class Value represents a value, which is fetched from the database. More...

## Typedefs

typedef Statement::const_iterator | Cursor
| Alternative name for the statement iterator.

## Functions

Connection | connect (const std::string &url, const std::string &username, const std::string &password)
| Establish a connection to a database.
Connection | connect (const std::string &url)
Connection | connectCached (const std::string &url, const std::string &username, const std::string &password)
| Fetch a connection from a pool or create a new one.
Connection | connectCached (const std::string &url)
unsigned | cachedConnections ()
| Returns the number of cached connections.
unsigned | cachedConnections (const std::string &url, const std::string &username, const std::string &password)
| Returns the number of cached connections for the specified url.
unsigned | cachedConnections (const std::string &url)
unsigned | dropCached (unsigned keep=0)
| Release unused connections; keep the given number of connections.
unsigned | dropCached (const std::string &url, const std::string &username="", const std::string &password="", unsigned keep=0)
| Release unused connections with the given database url; keep the given number of connections Note that connections, which are in use are not freed.
unsigned | dropCached (const std::string &url, unsigned keep)
void | setMaxPoolSize (unsigned max)
| Set the maximum pool size for new connection pools.
unsigned | getMaxPoolSize ()
| Get the current setting for maximum pool size (see setMaxPoolSize()).
std::istream & | operator>> (std::istream &in, Decimal &dec)
std::ostream & | operator<< (std::ostream &out, const Decimal &dec)
Result::const_iterator | begin (const Result &stmt)
| C++11 style begin function for tntdb::Result.
Result::const_iterator | end (const Result &stmt)
| C++11 style end function for tntdb::Result.
Row::const_iterator | begin (const Row &stmt)
| C++11 style begin function for tntdb::Row.
Row::const_iterator | end (const Row &stmt)
| C++11 style end function for tntdb::Row.
void | operator<<= (cxxtools::SerializationInfo &si, const Value &value)
| Makes tntdb::Value serializable in cxxtools serialization framework.
void | operator<<= (cxxtools::SerializationInfo &si, const Row &row)
| Makes tntdb::Row serializable in cxxtools serialization framework.
void | operator<<= (cxxtools::SerializationInfo &si, const Result &res)
| Makes tntdb::Result serializable in cxxtools serialization framework.
void | operator<<= (cxxtools::SerializationInfo &si, const Statement &res)
| Makes tntdb::Statement serializable in cxxtools serialization framework.
void | operator>>= (const cxxtools::SerializationInfo &si, Statement &stmt)
| Serialize operator for tntdb::Statement.
template<typename T>
Statement & | operator<<= (Statement &stmt, const T &obj)
| Serialize objects into tntdb::Statement.
template<typename T>
void | operator>>= (const Row &row, T &obj)
Statement::const_iterator | begin (const Statement &stmt, unsigned fetchsize=100)
| C++11 style begin function for tntdb::Statement.
Statement::const_iterator | end (const Statement &stmt)
| C++11 style end function for tntdb::Statement.
bool | operator>> (const Value &value, bool &out)
| Extraction operators for standard types.
bool | operator>> (const Value &value, short &out)
bool | operator>> (const Value &value, int &out)
bool | operator>> (const Value &value, long &out)
bool | operator>> (const Value &value, unsigned short &out)
bool | operator>> (const Value &value, unsigned &out)
bool | operator>> (const Value &value, unsigned long &out)
bool | operator>> (const Value &value, int32_t &out)
bool | operator>> (const Value &value, uint32_t &out)
bool | operator>> (const Value &value, int64_t &out)
bool | operator>> (const Value &value, uint64_t &out)
bool | operator>> (const Value &value, Decimal &out)
bool | operator>> (const Value &value, float &out)
bool | operator>> (const Value &value, double &out)
bool | operator>> (const Value &value, char &out)
bool | operator>> (const Value &value, std::string &out)
bool | operator>> (const Value &value, cxxtools::String &out)
bool | operator>> (const Value &value, Blob &out)
bool | operator>> (const Value &value, Date &out)
bool | operator>> (const Value &value, Time &out)
bool | operator>> (const Value &value, Datetime &out)
void | operator<< (Hostvar &hostvar, bool data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, int data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, long data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, unsigned data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, unsigned long data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, int32_t data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, uint32_t data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, int64_t data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, uint64_t data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, const Decimal &data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, float data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, double data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, char data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, const std::string &data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, const char *data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, const cxxtools::String &data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, const Blob &data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, const Date &data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, const Time &data)
| Set operators for host variables.
void | operator<< (Hostvar &hostvar, const Datetime &data)
| Set operators for host variables.
template<typename T>
void | operator<< (Hostvar &hostvar, const std::vector< T > &data)
| Set operators for host variables.
template<typename T>
void | operator<< (Hostvar &hostvar, const std::list< T > &data)
| Set operators for host variables.
template<typename T>
void | operator<< (Hostvar &hostvar, const std::deque< T > &data)
| Set operators for host variables.
template<typename T>
void | operator<< (Hostvar &hostvar, const std::set< T > &data)
| Set operators for host variables.
template<typename T>
void | operator<< (Hostvar &hostvar, const std::multiset< T > &data)
| Set operators for host variables.

## Detailed Description

Main namespace for Tntdb.

All Tntdb code is in this namespace.

## Typedef Documentation

## Cursor

typedef Statement::const_iterator tntdb::Cursor

Alternative name for the statement iterator.

It may be easier to write and read.

## Function Documentation

## begin() [1/3]

Result::const_iterator tntdb::begin | ( | const Result & | stmt | ) |

inline

C++11 style begin function for tntdb::Result.

## begin() [2/3]

Row::const_iterator tntdb::begin | ( | const Row & | stmt | ) |

inline

C++11 style begin function for tntdb::Row.

## begin() [3/3]

Statement::const_iterator tntdb::begin | ( | const Statement & | stmt,
|  | unsigned | fetchsize = 100 )

inline

C++11 style begin function for tntdb::Statement.

## cachedConnections() [1/2]

unsigned tntdb::cachedConnections | ( |  | ) |

Returns the number of cached connections.

Note that connections, which are in use are not counted.

## cachedConnections() [2/2]

unsigned tntdb::cachedConnections | ( | const std::string & | url,
|  | const std::string & | username,
|  | const std::string & | password )

Returns the number of cached connections for the specified url.

Note that connections, which are in use are not counted.

## connect()

Connection tntdb::connect | ( | const std::string & | url,
|  | const std::string & | username,
|  | const std::string & | password )

Establish a connection to a database.

The url is prefixed with a driver name followed by a colon and a driver-specific part. If the connection can't be established, an exception derived from tntdb::Error is thrown.

In the url the string "%u" is replaced with the username and "%p" is replaced with the password. The password parameter and the url with the replaced username and password fields is never logged.

To specify the text "%u" or "%p" in the connection string the '' can be escaped with backslash like this: "\%u".

Examples:

tntdb::Connection sqConn = tntdb::connect("sqlite:mydatabase.db");
tntdb::Connection pgConn = tntdb::connect("postgresql:dbname=DS2 user=%u passwd=%p", "web", "webpw");
tntdb::Connection myConn = tntdb::connect("mysql:db=DS2;user=%u;passwd=%p", "web", "webpw");
tntdb::Connection orConn = tntdb::connect("oracle:XE;user=%u;passwd=%p", "hr", "hr");
tntdb::Connection
This class holds a connection to a database.
Definition connection.h:67
tntdb::connect
Connection connect(const std::string &url, const std::string &username, const std::string &password)
Establish a connection to a database.

## connectCached()

Connection tntdb::connectCached | ( | const std::string & | url,
|  | const std::string & | username,
|  | const std::string & | password )

Fetch a connection from a pool or create a new one.

A static pool of connections is kept in memory. This function looks in this pool if there is a connection with the given url. If found, the connection is removed from the pool and returned. When the returned Connection object is destroyed (and all copies are too), the actual connection is put back into the pool.

When there is no connection with the given url in the pool, a new connection is established.

## dropCached() [1/2]

unsigned tntdb::dropCached | ( | const std::string & | url,
|  | const std::string & | username = "",
|  | const std::string & | password = "",
|  | unsigned | keep = 0 )

Release unused connections with the given database url; keep the given number of connections Note that connections, which are in use are not freed.

## dropCached() [2/2]

unsigned tntdb::dropCached | ( | unsigned | keep = 0 | ) |

Release unused connections; keep the given number of connections.

Returns the number of connections freed. Note that connections, which are in use are not freed.

## end() [1/3]

Result::const_iterator tntdb::end | ( | const Result & | stmt | ) |

inline

C++11 style end function for tntdb::Result.

## end() [2/3]

Row::const_iterator tntdb::end | ( | const Row & | stmt | ) |

inline

C++11 style end function for tntdb::Row.

## end() [3/3]

Statement::const_iterator tntdb::end | ( | const Statement & | stmt | ) |

inline

C++11 style end function for tntdb::Statement.

## getMaxPoolSize()

unsigned tntdb::getMaxPoolSize | ( |  | ) |

Get the current setting for maximum pool size (see setMaxPoolSize()).

## operator<<() [1/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | bool | data )

inline

Set operators for host variables.

## operator<<() [2/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | char | data )

inline

Set operators for host variables.

## operator<<() [3/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const Blob & | data )

inline

Set operators for host variables.

## operator<<() [4/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const char * | data )

inline

Set operators for host variables.

## operator<<() [5/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const cxxtools::String & | data )

inline

Set operators for host variables.

## operator<<() [6/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const Date & | data )

inline

Set operators for host variables.

## operator<<() [7/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const Datetime & | data )

inline

Set operators for host variables.

## operator<<() [8/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const Decimal & | data )

inline

Set operators for host variables.

## operator<<() [9/25]

template<typename T>

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const std::deque< T > & | data )

Set operators for host variables.

## operator<<() [10/25]

template<typename T>

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const std::list< T > & | data )

Set operators for host variables.

## operator<<() [11/25]

template<typename T>

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const std::multiset< T > & | data )

Set operators for host variables.

## operator<<() [12/25]

template<typename T>

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const std::set< T > & | data )

Set operators for host variables.

## operator<<() [13/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const std::string & | data )

inline

Set operators for host variables.

## operator<<() [14/25]

template<typename T>

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const std::vector< T > & | data )

Set operators for host variables.

## operator<<() [15/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | const Time & | data )

inline

Set operators for host variables.

## operator<<() [16/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | double | data )

inline

Set operators for host variables.

## operator<<() [17/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | float | data )

inline

Set operators for host variables.

## operator<<() [18/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | int | data )

inline

Set operators for host variables.

## operator<<() [19/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | int32_t | data )

inline

Set operators for host variables.

## operator<<() [20/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | int64_t | data )

inline

Set operators for host variables.

## operator<<() [21/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | long | data )

inline

Set operators for host variables.

## operator<<() [22/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | uint32_t | data )

inline

Set operators for host variables.

## operator<<() [23/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | uint64_t | data )

inline

Set operators for host variables.

## operator<<() [24/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | unsigned | data )

inline

Set operators for host variables.

## operator<<() [25/25]

void tntdb::operator<< | ( | Hostvar & | hostvar,
|  | unsigned long | data )

inline

Set operators for host variables.

## operator<<=() [1/5]

void tntdb::operator<<= | ( | cxxtools::SerializationInfo & | si,
|  | const Result & | res )

Makes tntdb::Result serializable in cxxtools serialization framework.

## operator<<=() [2/5]

void tntdb::operator<<= | ( | cxxtools::SerializationInfo & | si,
|  | const Row & | row )

Makes tntdb::Row serializable in cxxtools serialization framework.

## operator<<=() [3/5]

void tntdb::operator<<= | ( | cxxtools::SerializationInfo & | si,
|  | const Statement & | res )

Makes tntdb::Statement serializable in cxxtools serialization framework.

## operator<<=() [4/5]

void tntdb::operator<<= | ( | cxxtools::SerializationInfo & | si,
|  | const Value & | value )

Makes tntdb::Value serializable in cxxtools serialization framework.

## operator<<=() [5/5]

template<typename T>

Statement & tntdb::operator<<= | ( | Statement & | stmt,
|  | const T & | obj )

Serialize objects into tntdb::Statement.

This sets the placeholder variables in statement to the value of the object to serialize.

Example: /code MyObject obj = ...; stmt = db.prepare("insert into ..."); stmt <<= obj; // this serializes MyObject into the statement // by using the serialization operator of MyObject // and setting the members in the statement one by one

stmt.execute(); /endcode

## operator>>()

bool tntdb::operator>> | ( | const Value & | value,
|  | bool & | out )

inline

Extraction operators for standard types.

## operator>>=()

void tntdb::operator>>= | ( | const cxxtools::SerializationInfo & | si,
|  | Statement & | stmt )

Serialize operator for tntdb::Statement.

## setMaxPoolSize()

void tntdb::setMaxPoolSize | ( | unsigned | max | ) |

Set the maximum pool size for new connection pools.

When the maximum number of connections to a specific url is reached, connectCached blocks until a connection is available.

This setting do not affect pools with active connections. You have to release all connections and clear the pool of all connections to your database with dropCached(url) for this setting to take effect.