#include <database.h>
Public Member Functions | |
DatabaseConnection (const string &host_name, const int port, const string &user_name, const string &password, const string &database_name, const string &connection_type="QPSQL") | |
Constructor that opens a database connection. | |
bool | isConnected () const |
Shows if the connection to the database was successful. | |
bool | Query (const string &sql, Table *table=NULL) const |
Queries the database with a SQL string and populates a Table with the results. | |
virtual | ~DatabaseConnection () |
The destructor of the DatabaseConnection closes the underlying database connection. | |
Private Attributes | |
bool | connected_ |
Shows if the connection was successful. | |
QSqlDatabase | db_ |
The QT database object that this manages. | |
Static Private Attributes | |
static int | connection_num_ = 0 |
A counter to distinguish connections. |
A RAII object for managing a database connection. Each database connection is named, so multiply connections can exist by having multiple objects of this type. Each object maintains all the information about its own connection and queries.
Definition at line 87 of file database.h.
db_planner::DatabaseConnection::DatabaseConnection | ( | const string & | host_name, | |
const int | port, | |||
const string & | user_name, | |||
const string & | password, | |||
const string & | database_name, | |||
const string & | connection_type = "QPSQL" | |||
) |
Constructor that opens a database connection.
Multiple connections to the database can coexist as separate DatabaseConnection objects without any extra work.
Definition at line 72 of file database.cpp.
virtual db_planner::DatabaseConnection::~DatabaseConnection | ( | ) | [inline, virtual] |
The destructor of the DatabaseConnection closes the underlying database connection.
Definition at line 103 of file database.h.
bool db_planner::DatabaseConnection::isConnected | ( | ) | const [inline] |
Shows if the connection to the database was successful.
Definition at line 110 of file database.h.
bool db_planner::DatabaseConnection::Query | ( | const string & | sql, | |
Table * | table = NULL | |||
) | const |
Queries the database with a SQL string and populates a Table with the results.
Query the database using a SQL string and store the results in a provided Table.
If the query succeeds the table is populated with the results. If not, the function returns false and table's contents are undefined.
If the query is not expected to return any results, the table can be NULL
Definition at line 98 of file database.cpp.
bool db_planner::DatabaseConnection::connected_ [private] |
Shows if the connection was successful.
Definition at line 94 of file database.h.
int db_planner::DatabaseConnection::connection_num_ = 0 [static, private] |
A counter to distinguish connections.
Definition at line 92 of file database.h.
QSqlDatabase db_planner::DatabaseConnection::db_ [private] |
The QT database object that this manages.
Definition at line 90 of file database.h.