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

Last change on this file since 7510 was 7388, checked in by tbretz, 19 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 *GetNameTable() const { return Form("%s/%s", (const char*)fDataBase, (const char*)fTable); }
56 const char *GetNameColumn() const { return Form("%s/%s/%s", (const char*)fDataBase, (const char*)fTable, (const char*)fColumn); }
57
58 Bool_t Split(TString &url, TString &user, TString &pasw) const;
59
60 void Init(const char *connection, const char *user, const char *password);
61 void InitEnv(TEnv &env, const char *prefix=0);
62
63public:
64 MSQLServer(TSQLServer *serv, const char *dbname=0, const char *tname=0, const char *col=0)
65 : fServ(serv), fDataBase(dbname), fTable(tname), fColumn(col), fType(kIsZombie)
66 {
67 fList.SetOwner();
68
69 fType = kIsColumn;
70
71 if (fColumn.IsNull())
72 fType = kIsTable;
73
74 if (fTable.IsNull() && fColumn.IsNull())
75 fType = kIsDataBase;
76
77 if (fDataBase.IsNull() && fTable.IsNull() && fColumn.IsNull())
78 fType = kIsZombie;
79
80 if (!serv)
81 fType = kIsZombie;
82 }
83
84 MSQLServer(const char *connection, const char *user, const char *password);
85 MSQLServer(const char *link);
86 MSQLServer(TEnv &env, const char *prefix=0);
87 MSQLServer();
88 ~MSQLServer();
89
90 static void PrintLine(const TArrayI &max);
91 static void PrintTable(TSQLResult &res);
92
93 const char *GetName() const;
94 const char *GetNameDataBase() const { return fDataBase; }
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.