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