Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DbSvc.h
Go to the documentation of this file.
1 #ifndef __DB_SVC_H__
2 #define __DB_SVC_H__
3 #include <vector>
4 #include <string>
5 #include <sstream>
6 class TSQLServer;
7 class TSQLStatement;
8 
9 class DbSvc {
10  public:
11  typedef enum { DB1, DB2, DB3, DB01, UIUC, LITE, LOCAL } SvrId_t;
12  typedef enum { Guest, Prod } UsrId_t;
13  class VarList {
14  std::vector<std::string> m_name;
15  std::vector<std::string> m_type;
16  std::vector<bool> m_is_key;
17  public:
18  unsigned int Size() const { return m_name.size(); }
19  void Add(const std::string name, const std::string type, const bool is_key=false);
20  void Get(const int idx, std::string& name, std::string& type, bool& is_key) const;
21  };
22 
23  DbSvc(const SvrId_t svr_id=DB1, const UsrId_t usr_id=Guest, const std::string my_cnf="");
24  explicit DbSvc(const SvrId_t svr_id, std::string dbfile); // this is only for sqlite db
25  ~DbSvc();
26 
27  void UseSchema(const char* name, const bool do_create=false, const bool do_drop=false);
28  void UseSchema(const std::string name, const bool do_create=false, const bool do_drop=false) { UseSchema(name.c_str(), do_create, do_drop); }
29 
30  void DropTable (const char* name);
31  void DropTable (const std::string name) { DropTable(name.c_str()); }
32  bool HasTable(const char* name, const bool exit_on_false=false);
33  bool HasTable(const std::string name, const bool exit_on_false=false) { return HasTable(name.c_str(), exit_on_false); }
34  void CreateTable(const std::string name, const std::vector<std::string> list_var, const std::vector<std::string> list_type, const std::vector<std::string> list_key);
35  void CreateTable(const std::string name, const int n_var, const char** list_var, const char** list_type, const int n_key=0, const char** list_key=0);
36  void CreateTable(const std::string name, const VarList list);
37 
38  TSQLServer* Con() { return m_con; }
39  TSQLStatement* Process(const char* query);
40  TSQLStatement* Process(const std::string query) { return Process(query.c_str()); }
41 
42  private:
43  SvrId_t m_svr_id;
44  UsrId_t m_usr_id;
45  std::string m_svr;
46  std::string m_my_cnf;
47  TSQLServer* m_con;
48 
49  void SelectServer();
50  void ConnectServer();
51 };
52 #endif // __DB_SVC_H__
void Get(const int idx, std::string &name, std::string &type, bool &is_key) const
Definition: DbSvc.cc:252
UsrId_t
Definition: DbSvc.h:12
Definition: DbSvc.h:9
void UseSchema(const char *name, const bool do_create=false, const bool do_drop=false)
Definition: DbSvc.cc:82
TSQLStatement * Process(const std::string query)
Definition: DbSvc.h:40
DbSvc(const SvrId_t svr_id=DB1, const UsrId_t usr_id=Guest, const std::string my_cnf="")
Definition: DbSvc.cc:39
void UseSchema(const std::string name, const bool do_create=false, const bool do_drop=false)
Definition: DbSvc.h:28
SvrId_t
Definition: DbSvc.h:11
TSQLStatement * Process(const char *query)
Definition: DbSvc.cc:206
void Add(const std::string name, const std::string type, const bool is_key=false)
Definition: DbSvc.cc:245
void DropTable(const std::string name)
Definition: DbSvc.h:31
TSQLServer * Con()
Definition: DbSvc.h:38
void CreateTable(const std::string name, const std::vector< std::string > list_var, const std::vector< std::string > list_type, const std::vector< std::string > list_key)
Definition: DbSvc.cc:132
unsigned int Size() const
Definition: DbSvc.h:18
bool HasTable(const char *name, const bool exit_on_false=false)
Definition: DbSvc.cc:122
~DbSvc()
Definition: DbSvc.cc:77
void DropTable(const char *name)
Definition: DbSvc.cc:112
bool HasTable(const std::string name, const bool exit_on_false=false)
Definition: DbSvc.h:33