00001 // 00002 // $Id: IDBconnect.cxx,v 1.8 2000/02/29 12:46:39 mueller Exp $ 00003 // 00004 00005 #include "CTB.hxx" 00006 #include "CTBodbc.hxx" 00007 #include "CTBodbcConnect.hxx" 00008 00009 #include "IDB.hxx" 00010 #include "IDBconnect.hxx" 00011 00017 //------------------------------------------+----------------------------------- 00019 00020 IDBconnect::IDBconnect() 00021 : mp_dbc(0) 00022 {} 00023 00024 //------------------------------------------+----------------------------------- 00026 00027 IDBconnect::~IDBconnect() 00028 { 00029 if (mp_dbc != 0) delete mp_dbc; 00030 } 00031 00032 //------------------------------------------+----------------------------------- 00034 00035 bool IDBconnect::Connect(const char* c_dcs) 00036 { 00037 if (mp_dbc == 0) mp_dbc = new CTBodbcConnect(); 00038 return mp_dbc->Connect(c_dcs); 00039 } 00040 00041 //------------------------------------------+----------------------------------- 00043 00044 bool IDBconnect::Disconnect() 00045 { 00046 return (mp_dbc == 0) ? false : mp_dbc->Disconnect(); 00047 } 00048 00049 //------------------------------------------+----------------------------------- 00051 00052 bool IDBconnect::Connected() const 00053 { 00054 return (mp_dbc == 0) ? false : mp_dbc->Connected(); 00055 } 00056 00057 //------------------------------------------+----------------------------------- 00059 00060 CTBodbcConnect& IDBconnect::Dbc() 00061 { 00062 if (mp_dbc == 0) { // still unconnected ? 00063 mp_dbc = new CTBodbcConnect(); // than create dbc 00064 mp_dbc->Connect(mc_defaultdcs); // and connect with default dcs 00065 } 00066 return *mp_dbc; 00067 } 00068 00069 //------------------------------------------+----------------------------------- 00071 00072 void IDBconnect::ToStream(ostream& os) const 00073 { 00074 if (mp_dbc != 0) mp_dbc->ToStream(os); 00075 return; 00076 } 00077 00078 //------------------------------------------+----------------------------------- 00080 00081 IDBconnect& IDBconnect::Default() 00082 { 00083 return m_defaultdbc; 00084 } 00085 00086 //------------------------------------------+----------------------------------- 00088 00089 bool IDBconnect::DefaultConnect() 00090 { 00091 return DefaultConnect(mc_defaultdcs); 00092 } 00093 00094 //------------------------------------------+----------------------------------- 00096 00097 bool IDBconnect::DefaultConnect(const char* c_dcs) 00098 { 00099 if (c_dcs == 0 || c_dcs[0] == 0) { // if null or empty string 00100 c_dcs = mc_defaultdcs; // use default dcs 00101 } 00102 00103 return m_defaultdbc.Connect(c_dcs); 00104 } 00105 00106 //------------------------------------------+----------------------------------- 00108 00109 bool IDBconnect::DefaultDisconnect() 00110 { 00111 return m_defaultdbc.Disconnect(); 00112 } 00113 00114 //------------------------------------------+----------------------------------- 00116 00117 bool IDBconnect::DefaultConnected() 00118 { 00119 return m_defaultdbc.Connected(); 00120 } 00121 00122 //------------------------------------------+----------------------------------- 00124 00125 void IDBconnect::DefaultDCS(const char* c_dcs) 00126 { 00127 mc_defaultdcs = c_dcs; 00128 return; 00129 } 00130 00131 //------------------------------------------+----------------------------------- 00133 00134 const char* IDBconnect::DefaultDCS() 00135 { 00136 return mc_defaultdcs; 00137 } 00138 00139 //------------------------------------------+----------------------------------- 00140 IDBconnect IDBconnect::m_defaultdbc; 00141 CTBcstring<256> IDBconnect::mc_defaultdcs("dsn=indra_lecture"); 00142 //------------------------------------------+----------------------------------- 00143 00144 #if (defined(CTB__OutLine) || defined(IDBconnect__OutLine)) 00145 #define inline 00146 #include "IDBconnect.icc" 00147 #undef inline 00148 #endif