1 | #ifndef MARS_MSQLServer
|
---|
2 | #define MARS_MSQLServer
|
---|
3 |
|
---|
4 | #ifndef ROOT_TList
|
---|
5 | #include <TList.h>
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | class TArrayI;
|
---|
9 | class TSQLServer;
|
---|
10 | class TSQLResult;
|
---|
11 |
|
---|
12 | class MSQLServer : public TObject
|
---|
13 | {
|
---|
14 | TSQLServer *fServ;
|
---|
15 |
|
---|
16 | TString fDataBase;
|
---|
17 | TString fTable;
|
---|
18 | TString fColumn;
|
---|
19 |
|
---|
20 | TList fList;
|
---|
21 |
|
---|
22 | enum Type_t { kIsZombie, kIsServer, kIsDataBase, kIsTable, kIsColumn };
|
---|
23 |
|
---|
24 | Type_t fType;
|
---|
25 |
|
---|
26 | Bool_t IsFolder() const { return kTRUE; }
|
---|
27 |
|
---|
28 | Bool_t PrintError(const char *txt, const char *q) const;
|
---|
29 |
|
---|
30 | TString GetFields() const;
|
---|
31 |
|
---|
32 | void BrowseDataBase(TBrowser *b);
|
---|
33 | void BrowseTable(TBrowser *b);
|
---|
34 | void BrowseColumn(TBrowser *b);
|
---|
35 | void BrowseServer(TBrowser *b);
|
---|
36 |
|
---|
37 | void Browse(TBrowser *b)
|
---|
38 | {
|
---|
39 | if (!b)
|
---|
40 | return;
|
---|
41 |
|
---|
42 | switch (fType)
|
---|
43 | {
|
---|
44 | case kIsServer: BrowseServer(b); break;
|
---|
45 | case kIsDataBase: BrowseDataBase(b); break;
|
---|
46 | case kIsTable: BrowseTable(b); break;
|
---|
47 | case kIsColumn: BrowseColumn(b); break;
|
---|
48 | default:
|
---|
49 | break;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | const char *GetNameDataBase() const { return fDataBase; }
|
---|
54 | const char *GetNameTable() const { return Form("%s/%s", (const char*)fDataBase, (const char*)fTable); }
|
---|
55 | const char *GetNameColumn() const { return Form("%s/%s/%s", (const char*)fDataBase, (const char*)fTable, (const char*)fColumn); }
|
---|
56 |
|
---|
57 | void Init(const char *connection, const char *user, const char *password);
|
---|
58 |
|
---|
59 | public:
|
---|
60 | MSQLServer(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
|
---|
61 | : fServ(serv), fDataBase(dbname), fTable(tname), fColumn(col), fType(kIsZombie)
|
---|
62 | {
|
---|
63 | fList.SetOwner();
|
---|
64 |
|
---|
65 | fType = kIsColumn;
|
---|
66 |
|
---|
67 | if (fColumn.IsNull())
|
---|
68 | fType = kIsTable;
|
---|
69 |
|
---|
70 | if (fTable.IsNull() && fColumn.IsNull())
|
---|
71 | fType = kIsDataBase;
|
---|
72 |
|
---|
73 | if (fDataBase.IsNull() && fTable.IsNull() && fColumn.IsNull())
|
---|
74 | fType = kIsZombie;
|
---|
75 |
|
---|
76 | if (!serv)
|
---|
77 | fType = kIsZombie;
|
---|
78 | }
|
---|
79 |
|
---|
80 | MSQLServer(const char *connection, const char *user, const char *password);
|
---|
81 | MSQLServer(const char *link);
|
---|
82 | ~MSQLServer();
|
---|
83 |
|
---|
84 | static void PrintLine(const TArrayI &max);
|
---|
85 | static void PrintTable(TSQLResult &res);
|
---|
86 |
|
---|
87 | const char *GetName() const;
|
---|
88 |
|
---|
89 | void Print(Option_t *o) const;
|
---|
90 | void Print() const { Print(""); } //*MENU*
|
---|
91 | void PrintQuery(const char *query) const; //*MENU*
|
---|
92 | void ShowColumns() const; //*MENU*
|
---|
93 | void ShowStatus() const; //*MENU*
|
---|
94 | void ShowTableIndex() const; //*MENU*
|
---|
95 | void ShowTableCreate() const; //*MENU*
|
---|
96 | void ShowVariables() const { PrintQuery("SHOW VARIABLES"); } //*MENU*
|
---|
97 | void ShowProcesses() const { PrintQuery("SHOW PROCESSLIST"); } //*MENU*
|
---|
98 |
|
---|
99 | void Close(Option_t *option="");
|
---|
100 | TSQLResult *Query(const char *sql);
|
---|
101 | Int_t SelectDataBase(const char *dbname);
|
---|
102 | TSQLResult *GetDataBases(const char *wild = 0);
|
---|
103 | TSQLResult *GetTables(const char *dbname, const char *wild = 0);
|
---|
104 | TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0);
|
---|
105 | Int_t CreateDataBase(const char *dbname);
|
---|
106 | Int_t DropDataBase(const char *dbname);
|
---|
107 | Int_t Reload();
|
---|
108 | Int_t Shutdown();
|
---|
109 | const char *ServerInfo();
|
---|
110 | Bool_t IsConnected() const;
|
---|
111 |
|
---|
112 | TString GetEntry(const char *where, const char *col=0, const char *table=0) const;
|
---|
113 |
|
---|
114 | ClassDef(MSQLServer, 0) // An enhancement of TSQLServer
|
---|
115 | };
|
---|
116 |
|
---|
117 | class MSQLColumn : public MSQLServer
|
---|
118 | {
|
---|
119 | private:
|
---|
120 | Bool_t IsFolder() const { return kFALSE; }
|
---|
121 |
|
---|
122 | public:
|
---|
123 | MSQLColumn(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
|
---|
124 | : MSQLServer(serv, dbname, tname, col)
|
---|
125 | {
|
---|
126 | }
|
---|
127 | ClassDef(MSQLColumn, 0) // A workarount to let MSQLServer return kFALSE for IsFolder
|
---|
128 | };
|
---|
129 |
|
---|
130 | #endif
|
---|