Belle II Software development
DBInterface Class Referenceabstract
Inheritance diagram for DBInterface:
PostgreSQLInterface

Public Member Functions

 DBInterface (const std::string &host, const std::string &database, const std::string &user, const std::string &password, int port)
 
virtual void connect ()=0
 
virtual bool isConnected ()=0
 
virtual void execute_imp (const char *command)=0
 
void execute (const char *command,...)
 
void execute (const std::string &command)
 
virtual void close ()=0
 
virtual void clear ()=0
 
virtual DBRecordList loadRecords ()=0
 
virtual bool checkTable (const std::string &tablename)=0
 
virtual DBFieldTypeList getTableContents (const std::string &tablename)=0
 
void clearRecords ()
 
DBRecordList & getRecords ()
 
const std::string & getHostName () const
 
const std::string & getDatabase () const
 
const std::string & getUserName () const
 
const std::string & getPassword () const
 
int getPort () const
 

Protected Member Functions

void init (const std::string &host, const std::string &database, const std::string &user, const std::string &password, int port)
 

Protected Attributes

DBRecordList m_record_v
 
std::string m_host
 
std::string m_database
 
std::string m_user
 
std::string m_password
 
int m_port
 

Private Attributes

Mutex m_mutex
 
char * m_buf
 

Static Private Attributes

static const int m_buf_size = 1024 * 1000
 

Detailed Description

Definition at line 26 of file DBInterface.h.

Constructor & Destructor Documentation

◆ DBInterface() [1/2]

DBInterface ( const std::string &  host,
const std::string &  database,
const std::string &  user,
const std::string &  password,
int  port 
)

Definition at line 19 of file DBInterface.cc.

23{
24 init(host, database, user, password, port);
25}

◆ ~DBInterface()

~DBInterface ( )
virtual

Definition at line 27 of file DBInterface.cc.

28{
29 delete [] m_buf;
30}

◆ DBInterface() [2/2]

DBInterface ( )
inlineprotected

Definition at line 56 of file DBInterface.h.

56{}

Member Function Documentation

◆ clearRecords()

void clearRecords ( )
inline

Definition at line 47 of file DBInterface.h.

47{ m_record_v.resize(0); }

◆ execute() [1/2]

void execute ( const char *  command,
  ... 
)

Definition at line 45 of file DBInterface.cc.

46{
47 StringList s;
48
49 {
50 LockGuard lockGuard(m_mutex);
51
52 va_list ap;
53 va_start(ap, text);
54 vsnprintf(m_buf, m_buf_size, text, ap);
55 va_end(ap);
56 //std::cout << m_buf << std::endl;
57 //execute_imp(m_buf);
58 s = StringUtil::split(m_buf, ';');
59 }
60
61 for (size_t i = 0; i < s.size(); i++)
62 execute_imp(s[i].c_str());
63}
Lock Guard for a Mutex instance.
Definition: LockGuard.h:47

◆ execute() [2/2]

void execute ( const std::string &  command)

Definition at line 65 of file DBInterface.cc.

66{
67 //std::cout << text << std::endl;
68 StringList s = StringUtil::split(text, ';');
69 for (size_t i = 0; i < s.size(); i++)
70 execute_imp(s[i].c_str());
71}

◆ getDatabase()

const std::string & getDatabase ( ) const
inline

Definition at line 50 of file DBInterface.h.

50{ return m_database; }

◆ getHostName()

const std::string & getHostName ( ) const
inline

Definition at line 49 of file DBInterface.h.

49{ return m_host; }

◆ getPassword()

const std::string & getPassword ( ) const
inline

Definition at line 52 of file DBInterface.h.

52{ return m_password; }

◆ getPort()

int getPort ( ) const
inline

Definition at line 53 of file DBInterface.h.

53{ return m_port; }

◆ getRecords()

DBRecordList & getRecords ( )
inline

Definition at line 48 of file DBInterface.h.

48{ return m_record_v; }

◆ getUserName()

const std::string & getUserName ( ) const
inline

Definition at line 51 of file DBInterface.h.

51{ return m_user; }

◆ init()

void init ( const std::string &  host,
const std::string &  database,
const std::string &  user,
const std::string &  password,
int  port 
)
protected

Definition at line 32 of file DBInterface.cc.

36{
37 m_host = host;
38 m_database = database;
39 m_user = user;
40 m_password = password;
41 m_port = port;
42 m_buf = new char[m_buf_size];
43}

Member Data Documentation

◆ m_buf

char* m_buf
private

Definition at line 74 of file DBInterface.h.

◆ m_buf_size

const int m_buf_size = 1024 * 1000
staticprivate

Definition at line 73 of file DBInterface.h.

◆ m_database

std::string m_database
protected

Definition at line 66 of file DBInterface.h.

◆ m_host

std::string m_host
protected

Definition at line 65 of file DBInterface.h.

◆ m_mutex

Mutex m_mutex
private

Definition at line 72 of file DBInterface.h.

◆ m_password

std::string m_password
protected

Definition at line 68 of file DBInterface.h.

◆ m_port

int m_port
protected

Definition at line 69 of file DBInterface.h.

◆ m_record_v

DBRecordList m_record_v
protected

Definition at line 64 of file DBInterface.h.

◆ m_user

std::string m_user
protected

Definition at line 67 of file DBInterface.h.


The documentation for this class was generated from the following files: