TSQLServer.h

Go to the documentation of this file.
00001 // @(#)root/net:$Id: TSQLServer.h 29321 2009-07-03 10:42:10Z brun $
00002 // Author: Fons Rademakers   25/11/99
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TSQLServer
00013 #define ROOT_TSQLServer
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TSQLServer                                                           //
00019 //                                                                      //
00020 // Abstract base class defining interface to a SQL server.              //
00021 //                                                                      //
00022 // To open a connection to a server use the static method Connect().    //
00023 // The db argument of Connect() is of the form:                         //
00024 //    <dbms>://<host>[:<port>][/<database>], e.g.                       //
00025 // mysql://pcroot.cern.ch:3456/test, oracle://srv1.cern.ch/main, ...    //
00026 // Depending on the <dbms> specified an appropriate plugin library      //
00027 // will be loaded which will provide the real interface.                //
00028 //                                                                      //
00029 // Related classes are TSQLStatement, TSQLResult and TSQLRow.           //
00030 //                                                                      //
00031 //////////////////////////////////////////////////////////////////////////
00032 
00033 #ifndef ROOT_TObject
00034 #include "TObject.h"
00035 #endif
00036 #ifndef ROOT_TString
00037 #include "TString.h"
00038 #endif
00039 
00040 class TSQLResult;
00041 class TSQLStatement;
00042 class TSQLTableInfo;
00043 class TList;
00044 
00045 class TSQLServer : public TObject {
00046 
00047 protected:
00048    TString   fType;       // type of DBMS (MySQL, Oracle, SysBase, ...)
00049    TString   fHost;       // host to which we are connected
00050    TString   fDB;         // currently selected DB
00051    Int_t     fPort;       // port to which we are connected
00052    Int_t     fErrorCode;  // error code of last operation
00053    TString   fErrorMsg;   // error message of last operation
00054    Bool_t    fErrorOut;   // enable error output
00055 
00056    TSQLServer()
00057      : fType(), fHost(), fDB(), fPort(-1), fErrorCode(0),
00058      fErrorMsg(), fErrorOut(kTRUE) { ClearError(); }
00059 
00060    void                ClearError();
00061    void                SetError(Int_t code, const char* msg, const char* method = 0);
00062    
00063    static const char* fgFloatFmt;          //!  printf argument for floats and doubles, either "%f" or "%e" or "%10f" and so on
00064 
00065 public:
00066    enum ESQLDataTypes {  // data types, recognised by TSQLServer and other classes, extrction from ODBC
00067       kSQL_NONE = -1,      // data type unknown
00068       kSQL_CHAR = 1,       // CHAR(n) - string with fixed length n
00069       kSQL_VARCHAR = 2,    // VARCHAR(n) - string with variable length upto n
00070       kSQL_INTEGER = 3,    // INTEGER, INT - integer value
00071       kSQL_FLOAT = 4,      // FLOAT - float value
00072       kSQL_DOUBLE = 5,     // DOUBLE - double value
00073       kSQL_NUMERIC = 6,    // NUMERIC - numeric values with length and precion
00074       kSQL_BINARY = 7,     // BLOB - binary data
00075       kSQL_TIMESTAMP = 8   // TIMESTAMP -
00076    };
00077 
00078    virtual ~TSQLServer() { }
00079 
00080    virtual void        Close(Option_t *option="") = 0;
00081    virtual TSQLResult *Query(const char *sql) = 0;
00082    virtual Bool_t      Exec(const char* sql);
00083    virtual TSQLStatement *Statement(const char*, Int_t = 100)
00084                            { AbstractMethod("Statement"); return 0; }
00085    virtual Bool_t      HasStatement() const { return kFALSE; }
00086    virtual Int_t       SelectDataBase(const char *dbname) = 0;
00087    virtual TSQLResult *GetDataBases(const char *wild = 0) = 0;
00088    virtual TSQLResult *GetTables(const char *dbname, const char *wild = 0) = 0;
00089    virtual TList      *GetTablesList(const char* wild = 0);
00090    virtual Bool_t      HasTable(const char* tablename);
00091    virtual TSQLTableInfo *GetTableInfo(const char* tablename);
00092    virtual TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0) = 0;
00093    virtual Int_t       GetMaxIdentifierLength() { return 20; }
00094    virtual Int_t       CreateDataBase(const char *dbname) = 0;
00095    virtual Int_t       DropDataBase(const char *dbname) = 0;
00096    virtual Int_t       Reload() = 0;
00097    virtual Int_t       Shutdown() = 0;
00098    virtual const char *ServerInfo() = 0;
00099    virtual Bool_t      IsConnected() const { return fPort == -1 ? kFALSE : kTRUE; }
00100    const char         *GetDBMS() const { return fType.Data(); }
00101    const char         *GetDB() const { return fDB.Data(); }
00102    const char         *GetHost() const { return fHost.Data(); }
00103    Int_t               GetPort() const { return fPort; }
00104 
00105    virtual Bool_t      IsError() const { return GetErrorCode()!=0; }
00106    virtual Int_t       GetErrorCode() const;
00107    virtual const char* GetErrorMsg() const;
00108    virtual void        EnableErrorOutput(Bool_t on = kTRUE) { fErrorOut = on; }
00109 
00110    virtual Bool_t      StartTransaction();
00111    virtual Bool_t      Commit();
00112    virtual Bool_t      Rollback();
00113 
00114    virtual Bool_t      PingVerify() { return kFALSE; }
00115    virtual Int_t       Ping() { return -9999; }
00116 
00117    static TSQLServer *Connect(const char *db, const char *uid, const char *pw);
00118 
00119    static    void     SetFloatFormat(const char* fmt = "%e");
00120    static const char* GetFloatFormat();
00121 
00122    ClassDef(TSQLServer,0)  // Connection to SQL server
00123 };
00124 
00125 #endif

Generated on Tue Jul 5 14:28:13 2011 for ROOT_528-00b_version by  doxygen 1.5.1