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

Last change on this file since 6217 was 4877, checked in by tbretz, 20 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 TEnv;
9class TArrayI;
10
11class TSQLServer;
12class TSQLResult;
13
14class MSQLServer : public TObject
15{
16 TSQLServer *fServ;
17
18 TString fDataBase;
19 TString fTable;
20 TString fColumn;
21
22 TList fList;
23
24 enum Type_t { kIsZombie, kIsServer, kIsDataBase, kIsTable, kIsColumn };
25
26 Type_t fType;
27
28 Bool_t IsFolder() const { return kTRUE; }
29
30 Bool_t PrintError(const char *txt, const char *q) const;
31
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 Bool_t Split(TString &url, TString &user, TString &pasw) const;
60
61 void Init(const char *connection, const char *user, const char *password);
62 void InitEnv(TEnv &env, const char *prefix=0);
63
64public:
65 MSQLServer(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
66 : fServ(serv), fDataBase(dbname), fTable(tname), fColumn(col), fType(kIsZombie)
67 {
68 fList.SetOwner();
69
70 fType = kIsColumn;
71
72 if (fColumn.IsNull())
73 fType = kIsTable;
74
75 if (fTable.IsNull() && fColumn.IsNull())
76 fType = kIsDataBase;
77
78 if (fDataBase.IsNull() && fTable.IsNull() && fColumn.IsNull())
79 fType = kIsZombie;
80
81 if (!serv)
82 fType = kIsZombie;
83 }
84
85 MSQLServer(const char *connection, const char *user, const char *password);
86 MSQLServer(const char *link);
87 MSQLServer(TEnv &env, const char *prefix=0);
88 MSQLServer();
89 ~MSQLServer();
90
91 static void PrintLine(const TArrayI &max);
92 static void PrintTable(TSQLResult &res);
93
94 const char *GetName() const;
95
96 void Print(Option_t *o) const;
97 void Print() const { Print(""); } //*MENU*
98 void PrintQuery(const char *query) const; //*MENU*
99 void ShowColumns() const; //*MENU*
100 void ShowStatus() const; //*MENU*
101 void ShowTableIndex() const; //*MENU*
102 void ShowTableCreate() const; //*MENU*
103 void ShowVariables() const { PrintQuery("SHOW VARIABLES"); } //*MENU*
104 void ShowProcesses() const { PrintQuery("SHOW PROCESSLIST"); } //*MENU*
105
106 void Close(Option_t *option="");
107 TSQLResult *Query(const char *sql);
108 Int_t SelectDataBase(const char *dbname);
109 TSQLResult *GetDataBases(const char *wild = 0);
110 TSQLResult *GetTables(const char *dbname, const char *wild = 0);
111 TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0);
112 Int_t CreateDataBase(const char *dbname);
113 Int_t DropDataBase(const char *dbname);
114 Int_t Reload();
115 Int_t Shutdown();
116 const char *ServerInfo();
117 Bool_t IsConnected() const;
118
119 TString GetEntry(const char *where, const char *col=0, const char *table=0) const;
120
121 ClassDef(MSQLServer, 0) // An enhancement of TSQLServer
122};
123
124class MSQLColumn : public MSQLServer
125{
126private:
127 Bool_t IsFolder() const { return kFALSE; }
128
129public:
130 MSQLColumn(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
131 : MSQLServer(serv, dbname, tname, col)
132 {
133 }
134 ClassDef(MSQLColumn, 0) // A workarount to let MSQLServer return kFALSE for IsFolder
135};
136
137#endif
Note: See TracBrowser for help on using the repository browser.