#include <dbixx.h>
Public Member Functions | |
session () | |
session (std::string const &backend_or_connection_string) | |
~session () | |
void | connect (std::string const &connection_string) |
void | driver (std::string const &backend) |
std::string | driver () |
void | param (std::string const &par, std::string const &val) |
void | param (std::string const &par, int) |
void | connect () |
void | reconnect () |
void | close () |
dbi_conn | get_dbi_conn () |
void | query (std::string const &query) |
unsigned long long | rowid (char const *seq=NULL) |
unsigned long long | affected () |
void | bind (std::string const &s, bool isnull=false) |
void | bind (int v, bool isnull=false) |
void | bind (unsigned v, bool isnull=false) |
void | bind (long v, bool isnull=false) |
void | bind (unsigned long v, bool isnull=false) |
void | bind (long long int v, bool isnull=false) |
void | bind (unsigned long long v, bool isnull=false) |
void | bind (double v, bool isnull=false) |
void | bind (long double v, bool isnull=false) |
void | bind (std::tm const &time, bool isnull=false) |
void | bind (null const &, bool isnull=true) |
void | exec () |
void | fetch (result &res) |
bool | single (row &r) |
session & | operator<< (std::string const &q) |
session & | operator, (std::string const &v) |
session & | operator, (std::pair< std::string, bool > p) |
session & | operator, (char const *v) |
session & | operator, (std::tm const &v) |
void | operator, (dbixx::exec const &e) |
void | operator, (result &res) |
bool | operator, (row &r) |
template<typename T> | |
session & | operator, (T v) |
template<typename T> | |
session & | operator, (std::pair< T, bool > p) |
dbixx::session::session | ( | ) |
Create unconnected session
dbixx::session::session | ( | std::string const & | backend_or_connection_string | ) |
Create unconnected session that uses SQL backend backend or connection_string see connect(std::string const &connection_string) function
Note, if the string is not in connection string format but rather as driver name format it does not initiate connection, otherwise it does initiate one.
Passing driver name as parameter rather then connection string is deprecated, and available for backward compatibility
dbixx::session::~session | ( | ) |
Destroy the session and close the connection
void dbixx::session::connect | ( | std::string const & | connection_string | ) |
Connect to DB using "short-cut" connection string.
The string format is following:
backend:key=value[;key=value]*
where value is ether quoted string starting and ending with "'" or any other character sequence that does not include ";". If the value is looks like number (i.e. consists of digits and may start with "-" it is used as numeric value, if you want to prevent this use double quote.
For example:
sql.connect("sqlite3:dbname=test.db;sqlite3_dbdir=./");
is interpreted as sequence:
If you want to have a single quote in the string escape it as double quote: "mysql:username='foo';password='xdfr''s!d;f'" And the password would be interpreted as "xdf's!d;f"
void dbixx::session::driver | ( | std::string const & | backend | ) |
Set driver, for example mysql
std::string dbixx::session::driver | ( | ) |
Get current driver, for example "mysql", if driver was not set, empty string is returned
void dbixx::session::param | ( | std::string const & | par, | |
std::string const & | val | |||
) |
Set string parameter
void dbixx::session::param | ( | std::string const & | par, | |
int | ||||
) |
Set numeric parameter
void dbixx::session::connect | ( | ) |
Connect to database
void dbixx::session::reconnect | ( | ) |
Reconnect to database, useful if the DB was disconnected
void dbixx::session::close | ( | ) |
Close connection
dbi_conn dbixx::session::get_dbi_conn | ( | ) | [inline] |
Get low level libdbi connection object
void dbixx::session::query | ( | std::string const & | query | ) |
Set query to be prepared for execution, parameters that should be binded should be marked with "?" symbol. Note: when binding string you should not write quites around it as they would be automatically added.
For example
sql.query("SELECT * FROM users WHERE name=?")
sql.bind(username);
sql.fetch(res);
unsigned long long dbixx::session::rowid | ( | char const * | seq = NULL |
) |
Get last inserted rowid for sequence seq. Some DB require sequence name (postgresql) for other seq is just ignored (mysql, sqlite).
unsigned long long dbixx::session::affected | ( | ) | [inline] |
Get number of affected rows by the last statement
void dbixx::session::bind | ( | std::string const & | s, | |
bool | isnull = false | |||
) |
Bind a string parameter at next position in query
void dbixx::session::bind | ( | int | v, | |
bool | isnull = false | |||
) |
Bind a numeric parameter at next position in query
void dbixx::session::bind | ( | unsigned | v, | |
bool | isnull = false | |||
) |
Bind a numeric parameter at next position in query
void dbixx::session::bind | ( | long | v, | |
bool | isnull = false | |||
) |
Bind a numeric parameter at next position in query
void dbixx::session::bind | ( | unsigned long | v, | |
bool | isnull = false | |||
) |
Bind a numeric parameter at next position in query
void dbixx::session::bind | ( | long long int | v, | |
bool | isnull = false | |||
) |
Bind a numeric parameter at next position in query
void dbixx::session::bind | ( | unsigned long long | v, | |
bool | isnull = false | |||
) |
Bind a numeric parameter at next position in query
void dbixx::session::bind | ( | double | v, | |
bool | isnull = false | |||
) |
Bind a numeric parameter at next position in query
void dbixx::session::bind | ( | long double | v, | |
bool | isnull = false | |||
) |
Bind a numeric parameter at next position in query
void dbixx::session::bind | ( | std::tm const & | time, | |
bool | isnull = false | |||
) |
Bind a date-time parameter at next position in query
void dbixx::session::bind | ( | null const & | , | |
bool | isnull = true | |||
) |
Bind a NULL parameter at next position in query, isnull is just for consistency, don't use it.
void dbixx::session::exec | ( | ) |
Execute the statement
bool dbixx::session::single | ( | row & | r | ) |
Fetch a single row from query. If no rows where selected returns false, if more then one row is available, throws dbixx_error, If exactly one row was fetched, returns true.
session& dbixx::session::operator<< | ( | std::string const & | q | ) | [inline] |
Syntactic sugar for query(q)
session& dbixx::session::operator, | ( | std::string const & | v | ) | [inline] |
Syntactic sugar for bind(v)
session& dbixx::session::operator, | ( | std::pair< std::string, bool > | p | ) | [inline] |
Syntactic sugar for bind(p.first,p.second), usually used with use() function
session& dbixx::session::operator, | ( | char const * | v | ) | [inline] |
Syntactic sugar for bind(v)
session& dbixx::session::operator, | ( | std::tm const & | v | ) | [inline] |
Syntactic sugar for bind(v)
void dbixx::session::operator, | ( | dbixx::exec const & | e | ) | [inline] |
Syntactic sugar for calling exec() function.
void dbixx::session::operator, | ( | result & | res | ) | [inline] |
Syntactic sugar for fetching result - calling fetch(res)
bool dbixx::session::operator, | ( | row & | r | ) | [inline] |
Syntactic sugar for fetching a single row - calling single(r)
session& dbixx::session::operator, | ( | T | v | ) | [inline] |
Syntactic sugar for bind(v)
session& dbixx::session::operator, | ( | std::pair< T, bool > | p | ) | [inline] |
Syntactic sugar for bind(p.first,p.second), usually used with use() function