/*************************************************************************** Database Class ----------------------------------------- begin : 2010/03/11 copyright : (C) 2010 SolutionBox Inc. author : Service 1 Team email : svc1@solbox.com version : 1.0 CopyRight(C) 2010 SolutionBox Inc. All Rights reserved. Redistribution and use in source and binary forms, with or with out modification, are not permitted in outside of SolutionBox Inc. ***************************************************************************/ #ifndef __DATABASE_H__ #define __DATABASE_H__ #include #include #include "libpq-fe.h" #define MaxSizeOfDBQuery 1024*9 using namespace std; class DataBase { public: enum CFLAG { CLEAR = 1, NOT_CLEAR }; DataBase() { m_PGconn = NULL; m_pRes = NULL;} ~DataBase(); PGconn *PgOpenDB(string &strHost, int Port, string &strDBName, string &strAcct, string &strPasswd, int timeout = 10); PGconn *PgOpenDB(const char *pszDBName); void PgCloseDB(); int PgResult(CFLAG flag); PGconn *GetPgConn(){ return m_PGconn;} PGresult *GetRes(); void SetRes(PGresult * v) {m_pRes = v;} int GetCmdTuples(); int GetNoTuples(); int GetNoFields(); int GetResultCode() { return m_ResultCode; } char *GetValue(int tuple, int field); void PgClear(); int PgDoExec(string &strQuery); int PgDoExec(const char *pszQuery); int PgDoExec(const char *pszQuery, CFLAG flag); int PgDoExecParams(char *pszQuery, int nParamCnt, const char * const *paramValues ,CFLAG flag = NOT_CLEAR); int PgEscapeString(char *to, const char *from, size_t length); string &GetErrorMessage(); private: int m_ResultCode; PGconn *m_PGconn; PGresult *m_pRes; string m_ErrorMessage; }; #endif // ~__DATABASE_H__