source: trunk/MagicSoft/Mars/msql/MSQLServer.h@ 3713

Last change on this file since 3713 was 3328, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 3.9 KB
Line 
1#ifndef MARS_MSQLServer
2#define MARS_MSQLServer
3
4#ifndef ROOT_TList
5#include <TList.h>
6#endif
7
8class TArrayI;
9class TSQLServer;
10class TSQLResult;
11
12class 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 void PrintLine(const TArrayI &max) const;
31 void PrintTable(TSQLResult *res) const;
32 TString GetFields() const;
33
34 void BrowseDataBase(TBrowser *b);
35 void BrowseTable(TBrowser *b);
36 void BrowseColumn(TBrowser *b);
37 void BrowseServer(TBrowser *b);
38
39 void Browse(TBrowser *b)
40 {
41 if (!b)
42 return;
43
44 switch (fType)
45 {
46 case kIsServer: BrowseServer(b); break;
47 case kIsDataBase: BrowseDataBase(b); break;
48 case kIsTable: BrowseTable(b); break;
49 case kIsColumn: BrowseColumn(b); break;
50 default:
51 break;
52 }
53 }
54
55 const char *GetNameDataBase() const { return fDataBase; }
56 const char *GetNameTable() const { return Form("%s/%s", (const char*)fDataBase, (const char*)fTable); }
57 const char *GetNameColumn() const { return Form("%s/%s/%s", (const char*)fDataBase, (const char*)fTable, (const char*)fColumn); }
58
59 const char *GetName() const
60 {
61 switch (fType)
62 {
63 case kIsDataBase: return GetNameDataBase();
64 case kIsTable: return GetNameTable();
65 case kIsColumn: return GetNameColumn();
66 default: return "n/a";
67 }
68 }
69
70 void Init(const char *connection, const char *user, const char *password);
71
72public:
73 MSQLServer(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
74 : fServ(serv), fDataBase(dbname), fTable(tname), fColumn(col)
75 {
76 fList.SetOwner();
77
78 fType = kIsColumn;
79
80 if (fColumn.IsNull())
81 fType = kIsTable;
82
83 if (fTable.IsNull() && fColumn.IsNull())
84 fType = kIsDataBase;
85
86 if (fDataBase.IsNull() && fTable.IsNull() && fColumn.IsNull())
87 fType = kIsZombie;
88
89 if (!serv)
90 fType = kIsZombie;
91 }
92
93 MSQLServer(const char *connection, const char *user, const char *password);
94 MSQLServer(const char *link);
95
96 ~MSQLServer();
97
98 void Print(Option_t *o) const;
99 void Print() const { Print(""); } //*MENU*
100 void PrintQuery(const char *query) const; //*MENU*
101 void ShowColumns() const; //*MENU*
102 void ShowStatus() const; //*MENU*
103 void ShowTableIndex() const; //*MENU*
104 void ShowTableCreate() const; //*MENU*
105 void ShowVariables() const { PrintQuery("SHOW VARIABLES"); } //*MENU*
106 void ShowProcesses() const { PrintQuery("SHOW PROCESSLIST"); } //*MENU*
107
108 void Close(Option_t *option="");
109 TSQLResult *Query(const char *sql);
110 Int_t SelectDataBase(const char *dbname);
111 TSQLResult *GetDataBases(const char *wild = 0);
112 TSQLResult *GetTables(const char *dbname, const char *wild = 0);
113 TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0);
114 Int_t CreateDataBase(const char *dbname);
115 Int_t DropDataBase(const char *dbname);
116 Int_t Reload();
117 Int_t Shutdown();
118 const char *ServerInfo();
119
120 TString GetEntry(const char *where, const char *col=0, const char *table=0) const;
121
122 ClassDef(MSQLServer, 0) // An enhancement of TSQLServer
123};
124
125class MSQLColumn : public MSQLServer
126{
127private:
128 Bool_t IsFolder() const { return kFALSE; }
129
130public:
131 MSQLColumn(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
132 : MSQLServer(serv, dbname, tname, col)
133 {
134 }
135 ClassDef(MSQLColumn, 0) // A workarount to let MSQLServer return kFALSE for IsFolder
136};
137
138#endif
Note: See TracBrowser for help on using the repository browser.