Belle II Software  release-05-02-19
DBInterface.cc
1 #include "daq/slc/database/DBInterface.h"
2 
3 #include <daq/slc/base/StringUtil.h>
4 #include <daq/slc/system/LockGuard.h>
5 #include <daq/slc/system/LogFile.h>
6 
7 #include <cstdarg>
8 #include <cstdio>
9 
10 using namespace Belle2;
11 
12 DBInterface::DBInterface(const std::string& host,
13  const std::string& database,
14  const std::string& user,
15  const std::string& password, int port)
16 {
17  init(host, database, user, password, port);
18 }
19 
20 DBInterface::~DBInterface()
21 {
22  delete [] m_buf;
23 }
24 
25 void DBInterface::init(const std::string& host,
26  const std::string& database,
27  const std::string& user,
28  const std::string& password, int port)
29 {
30  m_host = host;
31  m_database = database;
32  m_user = user;
33  m_password = password;
34  m_port = port;
35  m_buf = new char[m_buf_size];
36 }
37 
38 void DBInterface::execute(const char* text, ...)
39 {
40  StringList s;
41 
42  {
43  LockGuard lockGuard(m_mutex);
44 
45  va_list ap;
46  va_start(ap, text);
47  vsnprintf(m_buf, m_buf_size, text, ap);
48  va_end(ap);
49  //std::cout << m_buf << std::endl;
50  //execute_imp(m_buf);
51  s = StringUtil::split(m_buf, ';');
52  }
53 
54  for (size_t i = 0; i < s.size(); i++)
55  execute_imp(s[i].c_str());
56 }
57 
58 void DBInterface::execute(const std::string& text)
59 {
60  //std::cout << text << std::endl;
61  StringList s = StringUtil::split(text, ';');
62  for (size_t i = 0; i < s.size(); i++)
63  execute_imp(s[i].c_str());
64 }
65 
Belle2::GenericLockGuard
Lock Guard for a Mutex instance.
Definition: LockGuard.h:40
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19