56 lines
940 B
C++
Executable File
56 lines
940 B
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#ifndef headerfile_winix_db_dbconn
|
|
#define headerfile_winix_db_dbconn
|
|
|
|
#include <string>
|
|
#include <libpq-fe.h>
|
|
#include "dbtextstream.h"
|
|
|
|
|
|
|
|
|
|
class DbConn
|
|
{
|
|
public:
|
|
|
|
DbConn();
|
|
~DbConn();
|
|
|
|
void SetConnParam(const std::string & database, const std::string & user, const std::string & pass);
|
|
void Connect();
|
|
void WaitForConnection();
|
|
void Close();
|
|
bool AssertConnection(bool put_log = true, bool throw_if_no_connection = true);
|
|
void SetDbParameters();
|
|
PGconn * GetPgConn();
|
|
|
|
private:
|
|
|
|
void LogConnectionSocket();
|
|
|
|
PGconn * pg_conn;
|
|
std::string db_database, db_user, db_pass;
|
|
DbTextStream conn_info;
|
|
|
|
// a helper method for escaping strings
|
|
template<class RawType>
|
|
DbTextStream::RawText<RawType> R(const RawType & par)
|
|
{
|
|
return DbTextStream::RawText<RawType>(par);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|