Hazy_Database Class Reference

This class provides database connection, executes update and select queries. More...

#include <postgres_util.h>

List of all members.

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.


Detailed Description

This class provides database connection, executes update and select queries.


Constructor & Destructor Documentation

Hazy_Database::Hazy_Database ( std::string  dbname  ) 

Default constructor that takes only database name (needs to consider username and password, too!).


Member Function Documentation

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.

Parameters:
[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
Returns:
success

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.

Parameters:
[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
Returns:
success

int Hazy_Database::execute_query_msg_double ( const char *  query,
const char *  msg,
double &  result 
)

Executes given statement and retrieve double value.

Parameters:
[in] query query statement
[in] msg error msg to print in case of error
[out] result double value to be retrieved
Returns:
success

int Hazy_Database::execute_query_msg_int ( const char *  query,
const char *  msg,
int &  result 
)

Executes given statement and retrieve int value.

Parameters:
[in] query query statement
[in] msg error msg to print in case of error
[out] result int value to be retrieved
Returns:
success

int Hazy_Database::execute_query_msg_text ( const char *  query,
const char *  msg,
std::string &  result 
)

Executes given statement and retrieve string value.

Parameters:
[in] query query statement
[in] msg error msg to print in case of error
[out] result string value to be retrieved
Returns:
success

int Hazy_Database::execute_statement_msg ( const char *  stmt,
const char *  msg 
)

Executes given statement.

Parameters:
[in] stmt query statement
[in] msg error msg to print in case of error
Returns:
success

void Hazy_Database::exit_nicely (  )  [inline, private]

When query gives error, then it closes database connection.

template<class K, class T>
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.

Parameters:
[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
Returns:
success

template<class T>
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.

Parameters:
[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
Returns:
success


Member Data Documentation

PGconn* Hazy_Database::conn [private]

Connection object.

PGresult* Hazy_Database::res [private]

Result object.


The documentation for this class was generated from the following files:
Generated on Wed Dec 15 10:46:16 2010 for Hazy_System by  doxygen 1.4.7