Changeset 7940 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
08/25/06 17:17:50 (18 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r7939 r7940  
    6565   * resources/sequences.rc:
    6666     - resource file how to build sequences... added.
     67
     68   * msql/MSQLMagic.[h,cc]:
     69     - added
     70
     71   * msql/MSQLServer.[h,cc]:
     72     - added copy constructor
     73     - allow fServ to be NULL (added sanity checks)
     74     - Implemented Exec-command
     75
     76   * msql/Makefile, msql/SqlLinkDef.h:
     77     - added MSQLMagic
    6778
    6879
  • trunk/MagicSoft/Mars/msql/MSQLServer.cc

    r7842 r7940  
    6464void MSQLServer::BrowseColumn(TBrowser *b) /*FOLD00*/
    6565{
     66    if (!fServ)
     67        return;
     68
    6669    const TString query0(Form("EXPLAIN %s.%s %s", (const char*)fDataBase, (const char*)fTable, (const char*)fColumn));
    6770    const TString query1(Form("SELECT %s FROM %s.%s", (const char*)fColumn, (const char*)fDataBase, (const char*)fTable));
     
    161164void MSQLServer::BrowseTable(TBrowser *b) /*FOLD00*/
    162165{
     166    if (!fServ)
     167        return;
     168
    163169    TSQLResult *res = fServ->GetColumns(fDataBase, fTable);
    164170    if (!res)
     
    182188void MSQLServer::BrowseDataBase(TBrowser *b) /*FOLD00*/
    183189{
     190    if (!fServ)
     191        return;
     192
    184193    TSQLResult *res = fServ->GetTables(fDataBase);
    185194    if (!res)
     
    203212void MSQLServer::BrowseServer(TBrowser *b) /*FOLD00*/
    204213{
     214    if (!fServ)
     215        return;
     216
    205217    TSQLResult *res = fServ->GetDataBases();
    206218    if (!res)
     
    278290TString MSQLServer::GetFields() const /*FOLD00*/
    279291{
     292    if (!fServ)
     293        return "";
     294
    280295    TSQLResult *res = fServ->GetColumns(fDataBase, fTable);
    281296    if (!res)
     
    303318void MSQLServer::PrintQuery(const char *query) const /*FOLD00*/
    304319{
     320    if (!fServ)
     321        return;
     322
    305323    TSQLResult *res = fServ->Query(query);
    306324    if (res)
     
    407425void MSQLServer::Close(Option_t *option) /*FOLD00*/
    408426{
    409     if (fType==kIsServer)
     427    if (fType==kIsServer && fServ)
     428    {
    410429        fServ->Close(option);
     430        if (TestBit(kIsOwner))
     431        {
     432            delete fServ;
     433            fServ=0;
     434            ResetBit(kIsOwner);
     435            fType=kIsZombie;
     436        }
     437    }
    411438}
    412439
    413440// --------------------------------------------------------------------------
    414441//
    415 // Send a SQL query to the SQl server.
     442// Send a SQL query to the SQL server.
    416443//
    417444// If MSQLServer is no server (column, row, ...) NULL is returned and an
     
    426453TSQLResult *MSQLServer::Query(const char *sql) /*FOLD00*/
    427454{
     455    if (!fServ)
     456        return NULL;
     457
    428458    if (fType!=kIsServer)
    429459    {
     
    435465    if (!res)
    436466    {
    437         cout << "ERROR: MSQLServer::Query - Query failed: " << sql << endl;
     467        cout << /*"ERROR: MSQLServer::Query - Query failed: " <<*/ sql << endl;
    438468        return NULL;
    439469    }
     
    442472}
    443473
     474// --------------------------------------------------------------------------
     475//
     476// Send a SQL query to the SQL server.
     477//
     478// If MSQLServer is no server (column, row, ...) NULL is returned and an
     479//  error message is send to stdout.
     480//
     481// If the query failed kFALSE is returned.
     482//
     483// On success kTRUE is returned.
     484//
     485Bool_t MSQLServer::Exec(const char* sql)
     486{
     487    if (!fServ)
     488        return kFALSE;
     489
     490#if ROOT_VERSION_CODE < ROOT_VERSION(5,12,00)
     491    TSQLResult *res = fServ->Query(sql);
     492    if (!res)
     493    {
     494        cout << "ERROR: MSQLServer::Exec - Query failed: " << sql << endl;
     495        return kFALSE;
     496    }
     497    delete res;
     498    return kTRUE;
     499#else
     500    if (fType!=kIsServer)
     501    {
     502        cout << "ERROR: MSQLServer::Exec - this is not a server!" << endl;
     503        return kFALSE;
     504    }
     505
     506    return fServ->Exec(sql);
     507#endif
     508}
     509
    444510Int_t MSQLServer::SelectDataBase(const char *dbname) /*FOLD00*/
    445511{
    446512    fDataBase = dbname;
    447     return fType==kIsServer ? fServ->SelectDataBase(dbname) : 0;
     513    return fType==kIsServer && fServ ? fServ->SelectDataBase(dbname) : 0;
    448514}
    449515
    450516TSQLResult *MSQLServer::GetDataBases(const char *wild) /*FOLD00*/
    451517{
    452     return fType==kIsServer ? fServ->GetDataBases(wild) : NULL;
     518    return fType==kIsServer && fServ ? fServ->GetDataBases(wild) : NULL;
    453519}
    454520
    455521TSQLResult *MSQLServer::GetTables(const char *dbname, const char *wild) /*FOLD00*/
    456522{
    457     return fType==kIsServer ? fServ->GetTables(dbname, wild) : NULL;
     523    return fType==kIsServer && fServ ? fServ->GetTables(dbname, wild) : NULL;
    458524}
    459525
    460526TSQLResult *MSQLServer::GetColumns(const char *dbname, const char *table, const char *wild) /*FOLD00*/
    461527{
    462     return fType==kIsServer ? fServ->GetColumns(dbname, table, wild) : NULL;
     528    return fType==kIsServer && fServ ? fServ->GetColumns(dbname, table, wild) : NULL;
    463529}
    464530
    465531Int_t MSQLServer::CreateDataBase(const char *dbname) /*FOLD00*/
    466532{
    467     return fType==kIsServer ? fServ->CreateDataBase(dbname) : 0;
     533    return fType==kIsServer && fServ ? fServ->CreateDataBase(dbname) : 0;
    468534}
    469535
    470536Int_t MSQLServer::DropDataBase(const char *dbname) /*FOLD00*/
    471537{
    472     return fType==kIsServer ? fServ->DropDataBase(dbname) : 0;
     538    return fType==kIsServer && fServ ? fServ->DropDataBase(dbname) : 0;
    473539}
    474540
    475541Int_t MSQLServer::Reload() /*FOLD00*/
    476542{
    477     return fType==kIsServer ? fServ->Reload() : 0;
     543    return fType==kIsServer && fServ ? fServ->Reload() : 0;
    478544}
    479545
    480546Int_t MSQLServer::Shutdown() /*FOLD00*/
    481547{
    482     return fType==kIsServer ? fServ->Shutdown() : 0;
     548    return fType==kIsServer && fServ ? fServ->Shutdown() : 0;
    483549}
    484550
    485551const char *MSQLServer::ServerInfo() /*FOLD00*/
    486552{
    487     return fType==kIsServer ? fServ->ServerInfo() : "";
     553    return fType==kIsServer && fServ ? fServ->ServerInfo() : "";
    488554}
    489555
    490556Bool_t MSQLServer::IsConnected() const
    491557{
    492     return fType==kIsServer ? fServ->IsConnected() : kFALSE;
     558    return fType==kIsServer && fServ ? fServ->IsConnected() : kFALSE;
    493559}
    494560
    495561const char *MSQLServer::GetName() const
    496562{
     563    if (!fServ)
     564        return "Unconnected!";
     565
    497566    switch (fType)
    498567    {
     
    531600        gROOT->GetListOfBrowsables()->Add(this, connection);
    532601        fType = kIsServer;
     602        SetBit(kIsOwner);
     603        SetBit(kMustCleanup);
    533604    }
    534605    else
     
    567638        if (!Split(url, user, pass))
    568639        {
    569             SetBit(kIsZombie);
     640            fType = kIsZombie;
    570641            return;
    571642        }
     
    590661    if (!Split(url, user, pasw))
    591662    {
    592         SetBit(kIsZombie);
     663        fType = kIsZombie;
    593664        return;
    594665    }
     
    607678}
    608679
     680MSQLServer::MSQLServer(MSQLServer &serv)
     681{
     682    fServ = serv.fServ;
     683
     684    fDataBase = serv.fDataBase;
     685    fTable = serv.fTable;
     686    fColumn = serv.fColumn;
     687
     688    fType = serv.fType;
     689}
     690
    609691MSQLServer::~MSQLServer() /*FOLD00*/
    610692{
    611     Close();
    612693    if (gDebug>0)
    613694        cout << "Delete: " << GetName() << endl;
     695    Close();
    614696}
    615697
     
    666748    return rc;
    667749}
     750
     751void MSQLServer::RecursiveRemove(TObject *obj)
     752{
     753    if (fServ==obj)
     754    {
     755        fServ=NULL;
     756        fType = kIsZombie;
     757        ResetBit(kIsOwner);
     758    }
     759}
  • trunk/MagicSoft/Mars/msql/MSQLServer.h

    r7388 r7940  
    1414class MSQLServer : public TObject
    1515{
     16private:
    1617    TSQLServer *fServ;
    1718
     
    2526
    2627    Type_t  fType;
     28
     29    enum { kIsOwner=BIT(14) };
    2730
    2831    Bool_t IsFolder() const { return kTRUE; }
     
    8588    MSQLServer(const char *link);
    8689    MSQLServer(TEnv &env, const char *prefix=0);
     90    MSQLServer(MSQLServer &serv);
    8791    MSQLServer();
    8892    ~MSQLServer();
     
    106110    void Close(Option_t *option="");
    107111    TSQLResult *Query(const char *sql);
     112    Bool_t      Exec(const char* sql);
    108113    Int_t       SelectDataBase(const char *dbname);
    109114    TSQLResult *GetDataBases(const char *wild = 0);
     
    118123
    119124    TString     GetEntry(const char *where, const char *col=0, const char *table=0) const;
     125
     126    void RecursiveRemove(TObject *obj);
    120127
    121128    ClassDef(MSQLServer, 0) // An enhancement of TSQLServer
  • trunk/MagicSoft/Mars/msql/Makefile

    r6849 r7940  
    2222
    2323SRCFILES = \
    24         MSQLServer.cc
     24        MSQLServer.cc \
     25        MSQLMagic.cc
    2526
    2627############################################################
  • trunk/MagicSoft/Mars/msql/SqlLinkDef.h

    r6856 r7940  
    88#pragma link C++ class MSQLServer+;
    99
     10#pragma link C++ class MSQLMagic+;
     11
    1012#endif
Note: See TracChangeset for help on using the changeset viewer.