CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
ConnectionDBBase.cxx
Go to the documentation of this file.
2#include "facilities/Util.h"
5
8#include "rdbModel/Rdb.h"
13#include <iostream>
14#include <cstdio>
15
16
17//namespace RealDBUtil {
18
19
20 ConnectionDBBase::ConnectionDBBase(const std::string& host, const std::string& table, const std::string& dbName)
21 : m_readCxt(0), m_writeCxt(0),
22 m_host(host), m_table(table), m_dbName(dbName), m_userName("maqm"), m_password("12345"), m_man(0), m_rdb(0),
23 m_match(false) {
24 // if (table.compare("*") == 0) m_table = std::string("$(MYSQL_METATABLE)");
25 // if (host.compare("*") == 0) m_host = std::string("$(MYSQL_HOST)");
26
27 }
28 ConnectionDBBase::ConnectionDBBase(const std::string& host, const std::string& dbName, const std::string& userName, const std::string& password)
29 : m_readCxt(0), m_writeCxt(0),
30 m_host(host), m_dbName(dbName), m_userName(userName), m_password(password),
31 m_man(0), m_rdb(0), m_match(false) {
32 }
33
37 if (m_man) delete m_man;
38 }
39
40
41
42 // The next 5 methods concern connection to the server
43 bool ConnectionDBBase::connect(rdbModel::Connection* cxt, std::string& host,
44 const std::string& user,
45 const std::string& pw, eRet& err,
46 const std::string& dbName) {
47
48
49 bool connected = cxt->open(host, user, pw, dbName);
50 if (connected) {
51 err = RETOk;
52 return true;
53 }
54 else {
55 err = RETNoConnect;
56 return false;
57 }
58 }
59
61 if (m_readCxt == 0) {
62 // for now use std::cout, std::cerr
63 m_readCxt = new rdbModel::MysqlConnection();
64 bool ok = connect(m_readCxt, m_host, m_userName,
65 m_password, err, m_dbName);
66 if (!ok) {
67 delete m_readCxt;
68 m_readCxt = 0;
69 } else {
70 }
71 return ok;
72 }
73 else return true;
74 }
75
76 bool ConnectionDBBase::connectWrite(eRet& err) {
77 if (m_writeCxt == 0) {
78 m_writeCxt = new rdbModel::MysqlConnection();
79 bool ok;
80
81 ok = connect(m_writeCxt, m_host, m_userName,
82 m_password, err, m_dbName);
83
84 if (!ok) {
85 delete m_readCxt;
86 m_readCxt = 0;
87 } else {
88
89 }
90
91 return ok;
92 }
93 else return true;
94 }
95
97 if (m_readCxt) {
98 m_readCxt->close();
99 delete m_readCxt;
100 m_readCxt = 0;
101 }
102 }
103
105 if (m_writeCxt) {
106 m_writeCxt->close();
107 delete m_writeCxt;
108 m_writeCxt = 0;
109 }
110 }
111//}
bool connectRead(eRet &err)
ConnectionDBBase(const std::string &host, const std::string &table, const std::string &dbName)
Constructor keeps track of table of interest.
virtual bool open(const std::string &host, const std::string &userid, const std::string &password, const std::string &dbName)=0
virtual bool close()=0