Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TSQLServer.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/net:$Id$
0002 // Author: Fons Rademakers   25/11/99
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TSQLServer
0013 #define ROOT_TSQLServer
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TSQLServer                                                           //
0019 //                                                                      //
0020 // Abstract base class defining interface to a SQL server.              //
0021 //                                                                      //
0022 // To open a connection to a server use the static method Connect().    //
0023 // The db argument of Connect() is of the form:                         //
0024 //    <dbms>://<host>[:<port>][/<database>], e.g.                       //
0025 // mysql://pcroot.cern.ch:3456/test, oracle://srv1.cern.ch/main, ...    //
0026 // Depending on the <dbms> specified an appropriate plugin library      //
0027 // will be loaded which will provide the real interface.                //
0028 //                                                                      //
0029 // Related classes are TSQLStatement, TSQLResult and TSQLRow.           //
0030 //                                                                      //
0031 //////////////////////////////////////////////////////////////////////////
0032 
0033 #include "TObject.h"
0034 #include "TString.h"
0035 
0036 class TSQLResult;
0037 class TSQLStatement;
0038 class TSQLTableInfo;
0039 class TList;
0040 
0041 class TSQLServer : public TObject {
0042 
0043 protected:
0044    TString   fType;             // type of DBMS (MySQL, Oracle, SysBase, ...)
0045    TString   fHost;             // host to which we are connected
0046    TString   fDB;               // currently selected DB
0047    Int_t     fPort{-1};         // port to which we are connected
0048    Int_t     fErrorCode{0};     // error code of last operation
0049    TString   fErrorMsg;         // error message of last operation
0050    Bool_t    fErrorOut{kTRUE}; // enable error output
0051 
0052    TSQLServer() {} // not allowed to use =default for TObject-derived classes
0053 
0054    void                ClearError();
0055    void                SetError(Int_t code, const char* msg, const char *method = nullptr);
0056 
0057    static const char* fgFloatFmt;          //!  printf argument for floats and doubles, either "%f" or "%e" or "%10f" and so on
0058 
0059 public:
0060    enum ESQLDataTypes {  // data types, recognised by TSQLServer and other classes, extrction from ODBC
0061       kSQL_NONE = -1,      // data type unknown
0062       kSQL_CHAR = 1,       // CHAR(n) - string with fixed length n
0063       kSQL_VARCHAR = 2,    // VARCHAR(n) - string with variable length upto n
0064       kSQL_INTEGER = 3,    // INTEGER, INT - integer value
0065       kSQL_FLOAT = 4,      // FLOAT - float value
0066       kSQL_DOUBLE = 5,     // DOUBLE - double value
0067       kSQL_NUMERIC = 6,    // NUMERIC - numeric values with length and precion
0068       kSQL_BINARY = 7,     // BLOB - binary data
0069       kSQL_TIMESTAMP = 8   // TIMESTAMP -
0070    };
0071 
0072    virtual ~TSQLServer() { }
0073 
0074    virtual void        Close(Option_t *option = "") = 0;
0075    virtual TSQLResult *Query(const char *sql) = 0;
0076    virtual Bool_t      Exec(const char* sql);
0077    virtual TSQLStatement *Statement(const char*, Int_t = 100)
0078                            { AbstractMethod("Statement"); return nullptr; }
0079    virtual Bool_t      HasStatement() const { return kFALSE; }
0080    virtual Int_t       SelectDataBase(const char *dbname) = 0;
0081    virtual TSQLResult *GetDataBases(const char *wild = nullptr) = 0;
0082    virtual TSQLResult *GetTables(const char *dbname, const char *wild = nullptr) = 0;
0083    virtual TList      *GetTablesList(const char* wild = nullptr);
0084    virtual Bool_t      HasTable(const char* tablename);
0085    virtual TSQLTableInfo *GetTableInfo(const char* tablename);
0086    virtual TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = nullptr) = 0;
0087    virtual Int_t       GetMaxIdentifierLength() { return 20; }
0088    virtual Int_t       CreateDataBase(const char *dbname) = 0;
0089    virtual Int_t       DropDataBase(const char *dbname) = 0;
0090    virtual Int_t       Reload() = 0;
0091    virtual Int_t       Shutdown() = 0;
0092    virtual const char *ServerInfo() = 0;
0093    virtual Bool_t      IsConnected() const { return fPort == -1 ? kFALSE : kTRUE; }
0094    const char         *GetDBMS() const { return fType.Data(); }
0095    const char         *GetDB() const { return fDB.Data(); }
0096    const char         *GetHost() const { return fHost.Data(); }
0097    Int_t               GetPort() const { return fPort; }
0098 
0099    virtual Bool_t      IsError() const { return GetErrorCode() != 0; }
0100    virtual Int_t       GetErrorCode() const;
0101    virtual const char* GetErrorMsg() const;
0102    virtual void        EnableErrorOutput(Bool_t on = kTRUE) { fErrorOut = on; }
0103 
0104    virtual Bool_t      StartTransaction();
0105    virtual Bool_t      HasTransactionInFlight();
0106    virtual Bool_t      Commit();
0107    virtual Bool_t      Rollback();
0108 
0109    virtual Bool_t      PingVerify() { return kFALSE; }
0110    virtual Int_t       Ping() { return -9999; }
0111 
0112    static TSQLServer *Connect(const char *db, const char *uid, const char *pw);
0113 
0114    static    void     SetFloatFormat(const char* fmt = "%e");
0115    static const char* GetFloatFormat();
0116 
0117    ClassDefOverride(TSQLServer,0)  // Connection to SQL server
0118 };
0119 
0120 #endif