source: trunk/Mars/msql/MSQLServer.h@ 19869

Last change on this file since 19869 was 15440, checked in by tbretz, 12 years ago
Support more than one MTreeSQL per database connection.
File size: 4.2 KB
Line 
1#ifndef MARS_MSQLServer
2#define MARS_MSQLServer
3
4#ifndef ROOT_TList
5#include <TList.h>
6#endif
7
8class TEnv;
9class TArrayI;
10
11class TSQLServer;
12class TSQLResult;
13
14class MTreeSQL;
15
16class MSQLServer : public TObject
17{
18private:
19 TSQLServer *fServ;
20 TList fTrees;
21
22 TString fDataBase;
23 TString fTable;
24 TString fColumn;
25
26 TList fList;
27
28 enum Type_t { kIsZombie, kIsServer, kIsDataBase, kIsTable, kIsColumn };
29
30 Type_t fType;
31
32 enum { kIsOwner=BIT(14) };
33
34 Bool_t IsFolder() const { return kTRUE; }
35
36 Bool_t PrintError(const char *txt, const char *q) const;
37
38 TString GetFields() const;
39
40 void BrowseDataBase(TBrowser *b);
41 void BrowseTable(TBrowser *b);
42 void BrowseColumn(TBrowser *b);
43 void BrowseServer(TBrowser *b);
44
45 void Browse(TBrowser *b)
46 {
47 if (!b)
48 return;
49
50 switch (fType)
51 {
52 case kIsServer: BrowseServer(b); break;
53 case kIsDataBase: BrowseDataBase(b); break;
54 case kIsTable: BrowseTable(b); break;
55 case kIsColumn: BrowseColumn(b); break;
56 default:
57 break;
58 }
59 }
60
61 const char *GetNameTable() const { return Form("%s/%s", (const char*)fDataBase, (const char*)fTable); }
62 const char *GetNameColumn() const { return Form("%s/%s/%s", (const char*)fDataBase, (const char*)fTable, (const char*)fColumn); }
63
64 Bool_t Split(TString &url, TString &user, TString &pasw) const;
65
66 void Init(const char *connection, const char *user, const char *password);
67 void InitEnv(TEnv &env, const char *prefix=0);
68
69public:
70 MSQLServer(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
71 : fServ(serv), fDataBase(dbname), fTable(tname), fColumn(col), fType(kIsZombie)
72 {
73 fList.SetOwner();
74
75 fType = kIsColumn;
76
77 if (fColumn.IsNull())
78 fType = kIsTable;
79
80 if (fTable.IsNull() && fColumn.IsNull())
81 fType = kIsDataBase;
82
83 if (fDataBase.IsNull() && fTable.IsNull() && fColumn.IsNull())
84 fType = kIsZombie;
85
86 if (!serv)
87 fType = kIsZombie;
88 }
89
90 MSQLServer(const char *connection, const char *user, const char *password);
91 MSQLServer(const char *link);
92 MSQLServer(TEnv &env, const char *prefix=0);
93 MSQLServer(MSQLServer &serv);
94 MSQLServer();
95 ~MSQLServer();
96
97 static void PrintLine(const TArrayI &max);
98 static void PrintTable(TSQLResult &res);
99
100 const char *GetName() const;
101 const char *GetNameDataBase() const { return fDataBase; }
102
103 void Print(Option_t *o) const;
104 void Print() const { Print(""); } //*MENU*
105 void PrintQuery(const char *query) const; //*MENU*
106 void ShowColumns() const; //*MENU*
107 void ShowStatus() const; //*MENU*
108 void ShowTableIndex() const; //*MENU*
109 void ShowTableCreate() const; //*MENU*
110 void ShowVariables() const { PrintQuery("SHOW VARIABLES"); } //*MENU*
111 void ShowProcesses() const { PrintQuery("SHOW PROCESSLIST"); } //*MENU*
112
113 void Close(Option_t *option="");
114 TSQLResult *Query(const char *sql);
115 Bool_t Exec(const char* sql);
116 Int_t SelectDataBase(const char *dbname);
117 TSQLResult *GetDataBases(const char *wild = 0);
118 TSQLResult *GetTables(const char *wild = 0, const char *dbname = 0);
119 TSQLResult *GetColumns(const char *table, const char *wild = 0, const char *dbname = 0);
120 Int_t CreateDataBase(const char *dbname);
121 Int_t DropDataBase(const char *dbname);
122 Int_t Reload();
123 Int_t Shutdown();
124 const char *ServerInfo();
125 Bool_t IsConnected() const;
126
127 TString GetEntry(const char *where, const char *col=0, const char *table=0) const;
128 TString GetPrimaryKeys(const char *table);
129 TString GetJoins(const char *table, const TString text);
130
131 void RecursiveRemove(TObject *obj);
132
133 MTreeSQL *GetTree(TString table, TString addon="");
134
135 ClassDef(MSQLServer, 0) // An enhancement of TSQLServer
136};
137
138class MSQLColumn : public MSQLServer
139{
140private:
141 Bool_t IsFolder() const { return kFALSE; }
142
143public:
144 MSQLColumn(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
145 : MSQLServer(serv, dbname, tname, col)
146 {
147 }
148 ClassDef(MSQLColumn, 0) // A workarount to let MSQLServer return kFALSE for IsFolder
149};
150
151#endif
Note: See TracBrowser for help on using the repository browser.