BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
ConnectionDBBase.cxx
Go to the documentation of this file.
1#include "ReadDBBase/ConnectionDBBase.h"
2#include "facilities/Util.h"
3#include "rdbModel/Management/Manager.h"
4#include "rdbModel/Management/XercesBuilder.h"
5
6#include "rdbModel/Db/MysqlConnection.h"
7#include "rdbModel/Db/MysqlResults.h"
8#include "rdbModel/Rdb.h"
9#include "rdbModel/RdbException.h"
10#include "rdbModel/Tables/Assertion.h"
11#include "rdbModel/Tables/Column.h"
12#include "rdbModel/Tables/Table.h"
13#include <cstdio>
14#include <iostream>
15
16// namespace RealDBUtil {
17
18ConnectionDBBase::ConnectionDBBase( const std::string& host, const std::string& table,
19 const std::string& dbName )
20 : m_readCxt( 0 )
21 , m_writeCxt( 0 )
22 , m_host( host )
23 , m_table( table )
24 , m_dbName( dbName )
25 , m_userName( "maqm" )
26 , m_password( "12345" )
27 , m_man( 0 )
28 , m_rdb( 0 )
29 , m_match( false ) {
30 // if (table.compare("*") == 0) m_table = std::string("$(MYSQL_METATABLE)");
31 // if (host.compare("*") == 0) m_host = std::string("$(MYSQL_HOST)");
32}
33ConnectionDBBase::ConnectionDBBase( const std::string& host, const std::string& dbName,
34 const std::string& userName, const std::string& password )
35 : m_readCxt( 0 )
36 , m_writeCxt( 0 )
37 , m_host( host )
38 , m_dbName( dbName )
39 , m_userName( userName )
40 , m_password( password )
41 , m_man( 0 )
42 , m_rdb( 0 )
43 , m_match( false ) {}
44
48 if ( m_man ) delete m_man;
49}
50
51// The next 5 methods concern connection to the server
52bool ConnectionDBBase::connect( rdbModel::Connection* cxt, std::string& host,
53 const std::string& user, const std::string& pw, eRet& err,
54 const std::string& dbName ) {
55
56 bool connected = cxt->open( host, user, pw, dbName );
57 if ( connected )
58 {
59 err = RETOk;
60 return true;
61 }
62 else
63 {
64 err = RETNoConnect;
65 return false;
66 }
67}
68
70 if ( m_readCxt == 0 )
71 {
72 // for now use std::cout, std::cerr
73 m_readCxt = new rdbModel::MysqlConnection();
74 bool ok = connect( m_readCxt, m_host, m_userName, m_password, err, m_dbName );
75 if ( !ok )
76 {
77 delete m_readCxt;
78 m_readCxt = 0;
79 }
80 else {}
81 return ok;
82 }
83 else return true;
84}
85
86bool ConnectionDBBase::connectWrite( eRet& err ) {
87 if ( m_writeCxt == 0 )
88 {
89 m_writeCxt = new rdbModel::MysqlConnection();
90 bool ok;
91
92 ok = connect( m_writeCxt, m_host, m_userName, m_password, err, m_dbName );
93
94 if ( !ok )
95 {
96 delete m_readCxt;
97 m_readCxt = 0;
98 }
99 else {}
100
101 return ok;
102 }
103 else return true;
104}
105
107 if ( m_readCxt )
108 {
109 m_readCxt->close();
110 delete m_readCxt;
111 m_readCxt = 0;
112 }
113}
114
116 if ( m_writeCxt )
117 {
118 m_writeCxt->close();
119 delete m_writeCxt;
120 m_writeCxt = 0;
121 }
122}
123//}
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