00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ODBCConnMgr.h"
00010
00011 ODBCConnMgr *ODBCConnMgr::mgr=0;
00012
00013 ODBCConnMgr::ODBCConnMgr(){
00014 mgr=this;
00015 handles.clear();
00016 }
00017
00018 ODBCConnMgr::~ODBCConnMgr(){
00019 mgr=0;
00020 while(!handles.empty()){
00021 delete handles.front();
00022 handles.pop_front();
00023 }
00024 }
00025
00026 ODBCConnMgr *ODBCConnMgr::GetMgr(){
00027 if(mgr == 0) return new ODBCConnMgr();
00028 return mgr;
00029 }
00030
00031 ODBCConnHandle *ODBCConnMgr::ConnectToHost(char *hostname, char *uid, char *pwd){
00032 if(!handles.empty()){
00033 list<ODBCConnHandle *>::iterator itr=handles.begin();
00034 do{
00035 if(0 == (*itr)->CheckName(hostname)) return *itr;
00036 } while(itr!=handles.end());
00037 }
00038
00039
00040
00041 odbc::Connection *conn=odbc::DriverManager::getConnection(hostname, uid, pwd);
00042 if(conn != 0){
00043 handles.push_back(new ODBCConnHandle(conn, hostname));
00044 } else {
00045 printf("WARNING:\tODBCConnMgr::ConnectToHost: unable to connect to host %s with uid %s!\n", hostname, uid);
00046 return 0;
00047 }
00048 return handles.back();
00049 }
00050
00051 int ODBCConnMgr::DisconnectFromHost(char *hostname){
00052 if(!handles.empty()){
00053 list<ODBCConnHandle *>::iterator itr=handles.begin();
00054 do{
00055 if(0 == (*itr)->CheckName(hostname)){
00056 (*itr)->Disconnect();
00057 handles.erase(itr);
00058 return 1;
00059 }
00060 } while(itr!=handles.end());
00061 }
00062 printf("WARNING:\tODBCConnMgr::DisconnectFromHost(%s): we're not connected to that host!\n", hostname);
00063 return 0;
00064 }
00065
00066