/*
 * EH_DB.h
 * Copyright by AirDream Co., Ltd. 2010-2011 All right reserved
 *
 * Description:
 *  Created on:2011-12-22
 * Modified on:2011-12-22
 *
 */
//#define NOT_X86
#ifndef NOT_X86

#ifndef EH_DB_H_
#define EH_DB_H_

#include <iostream>
#include <string>
#include <pqxx/pqxx>

#include "ace/Recursive_Thread_Mutex.h"

using namespace std;
using namespace pqxx;

typedef vector<map<string, string>*> 		DBRESVEC;
typedef vector<map<string, string>*>* 		DBRES;
typedef map<string, string> 				DBROWMAP;
typedef map<string, string>* 				DBROW;

class EH_DB {
public:
    EH_DB(string username,string passwd,string addr,string port,string dbname);
    ~EH_DB();

    void OpenConnection();
    void CloseConnection();
    void ResetConnection();

    void StartTransaction();
    void CommitTransaction();
    void AbortTransaction();
    void ExceptionInTransaction();

    DBRES ExecuteQuery(string sql);
    int ExecuteUpdate(string sql);

    static void ReleaseResultSet(DBRES& res);

private:
    connection* 					m_pConn;
    transaction<>* 					m_pAction;
    string 							m_strConnectionInfo;
    ACE_Recursive_Thread_Mutex		m_Lock;
};

#endif /* EH_DB_H_ */

#else
	#include "EH_DB_Sqlite.h"
#endif


