#include <postgres_util.h>
Public Member Functions | |
Hazy_Database (std::string dbname) | |
Default constructor that takes only database name (needs to consider username and password, too!). | |
int | execute_statement_msg (const char *stmt, const char *msg) |
Executes given statement. | |
int | execute_query_msg_text (const char *query, const char *msg, std::string &result) |
Executes given statement and retrieve string value. | |
int | execute_query_msg_double (const char *query, const char *msg, double &result) |
Executes given statement and retrieve double value. | |
int | execute_query_msg_int (const char *query, const char *msg, int &result) |
Executes given statement and retrieve int value. | |
int | copy_to_table (std::istream &s, std::string &table_name, std::string &delimiter) |
Copies given content of the stream to the given table. | |
int | copy_from_table (std::ostream &s, std::string &table_name, std::string &delimiter) |
Copies content of the database table to the output stream. | |
template<class T> | |
int | postgresTupleParser (const char *szQuery, int(*tuple_parser)(PGresult *r, int index, T &out), std::vector< T > &_out) |
Parses the postgres tuples and stores them in a vector. | |
template<class K, class T> | |
int | postgresMapParser (const char *szQuery, int(*tuple_parser)(PGresult *r, int index, K &k, T &v), std::map< K, T > &_out) |
Parses the postgres tuples in hybrid approach and stores them in a map. | |
void | closeConnection () |
Closes database connection. | |
Private Member Functions | |
void | exit_nicely () |
When query gives error, then it closes database connection. | |
Private Attributes | |
PGconn * | conn |
Connection object. | |
PGresult * | res |
Result object. |
Hazy_Database::Hazy_Database | ( | std::string | dbname | ) |
Default constructor that takes only database name (needs to consider username and password, too!).
void Hazy_Database::closeConnection | ( | ) |
Closes database connection.
int Hazy_Database::copy_from_table | ( | std::ostream & | s, | |
std::string & | table_name, | |||
std::string & | delimiter | |||
) |
Copies content of the database table to the output stream.
[in] | s | output stream that the table content will be written to |
[in] | table_name | name of the table in the database that has the data |
[in] | delimiter | delimiter that will be used to format data in the output stream |
int Hazy_Database::copy_to_table | ( | std::istream & | s, | |
std::string & | table_name, | |||
std::string & | delimiter | |||
) |
Copies given content of the stream to the given table.
[in] | s | input stream that holds data |
[in] | table_name | table name in the database that data will be copied |
[in] | delimiter | delimiter that used to format data in the input stream |
int Hazy_Database::execute_query_msg_double | ( | const char * | query, | |
const char * | msg, | |||
double & | result | |||
) |
Executes given statement and retrieve double value.
[in] | query | query statement |
[in] | msg | error msg to print in case of error |
[out] | result | double value to be retrieved |
int Hazy_Database::execute_query_msg_int | ( | const char * | query, | |
const char * | msg, | |||
int & | result | |||
) |
Executes given statement and retrieve int value.
[in] | query | query statement |
[in] | msg | error msg to print in case of error |
[out] | result | int value to be retrieved |
int Hazy_Database::execute_query_msg_text | ( | const char * | query, | |
const char * | msg, | |||
std::string & | result | |||
) |
Executes given statement and retrieve string value.
[in] | query | query statement |
[in] | msg | error msg to print in case of error |
[out] | result | string value to be retrieved |
int Hazy_Database::execute_statement_msg | ( | const char * | stmt, | |
const char * | msg | |||
) |
Executes given statement.
[in] | stmt | query statement |
[in] | msg | error msg to print in case of error |
void Hazy_Database::exit_nicely | ( | ) | [inline, private] |
When query gives error, then it closes database connection.
int Hazy_Database::postgresMapParser | ( | const char * | szQuery, | |
int(*)(PGresult *r, int index, K &k, T &v) | tuple_parser, | |||
std::map< K, T > & | _out | |||
) | [inline] |
Parses the postgres tuples in hybrid approach and stores them in a map.
[in] | szQuery | query to retrieve tuples from postgres |
[in] | tuple_parser | function pointer to parse the tuples |
[out] | _out | the map that parsed tuples will be stored |
int Hazy_Database::postgresTupleParser | ( | const char * | szQuery, | |
int(*)(PGresult *r, int index, T &out) | tuple_parser, | |||
std::vector< T > & | _out | |||
) | [inline] |
Parses the postgres tuples and stores them in a vector.
[in] | szQuery | query to retrieve tuples from postgres |
[in] | tuple_parser | function pointer to parse the tuples |
[out] | _out | the vector that parsed tuples will be stored |
PGconn* Hazy_Database::conn [private] |
Connection object.
PGresult* Hazy_Database::res [private] |
Result object.