ROOT logo
// @(#)root/net:$Id: TSQLServer.h 26487 2008-11-26 16:52:50Z rdm $
// Author: Fons Rademakers   25/11/99

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TSQLServer
#define ROOT_TSQLServer


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TSQLServer                                                           //
//                                                                      //
// Abstract base class defining interface to a SQL server.              //
//                                                                      //
// To open a connection to a server use the static method Connect().    //
// The db argument of Connect() is of the form:                         //
//    <dbms>://<host>[:<port>][/<database>], e.g.                       //
// mysql://pcroot.cern.ch:3456/test, oracle://srv1.cern.ch/main, ...    //
// Depending on the <dbms> specified an appropriate plugin library      //
// will be loaded which will provide the real interface.                //
//                                                                      //
// Related classes are TSQLStatement, TSQLResult and TSQLRow.           //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif

class TSQLResult;
class TSQLStatement;
class TSQLTableInfo;
class TList;

class TSQLServer : public TObject {

protected:
   TString   fType;       // type of DBMS (MySQL, Oracle, SysBase, ...)
   TString   fHost;       // host to which we are connected
   TString   fDB;         // currently selected DB
   Int_t     fPort;       // port to which we are connected
   Int_t     fErrorCode;  // error code of last operation
   TString   fErrorMsg;   // error message of last operation
   Bool_t    fErrorOut;   // enable error output

   TSQLServer()
     : fType(), fHost(), fDB(), fPort(-1), fErrorCode(0),
     fErrorMsg(), fErrorOut(kTRUE) { ClearError(); }

   void                ClearError();
   void                SetError(Int_t code, const char* msg, const char* method = 0);

public:
   enum ESQLDataTypes {  // data types, recognised by TSQLServer and other classes, extrction from ODBC
      kSQL_NONE = -1,      // data type unknown
      kSQL_CHAR = 1,       // CHAR(n) - string with fixed length n
      kSQL_VARCHAR = 2,    // VARCHAR(n) - string with variable length upto n
      kSQL_INTEGER = 3,    // INTEGER, INT - integer value
      kSQL_FLOAT = 4,      // FLOAT - float value
      kSQL_DOUBLE = 5,     // DOUBLE - double value
      kSQL_NUMERIC = 6,    // NUMERIC - numeric values with length and precion
      kSQL_BINARY = 7,     // BLOB - binary data
      kSQL_TIMESTAMP = 8   // TIMESTAMP -
   };

   virtual ~TSQLServer() { }

   virtual void        Close(Option_t *option="") = 0;
   virtual TSQLResult *Query(const char *sql) = 0;
   virtual Bool_t      Exec(const char* sql);
   virtual TSQLStatement *Statement(const char*, Int_t = 100)
                           { AbstractMethod("Statement"); return 0; }
   virtual Bool_t      HasStatement() const { return kFALSE; }
   virtual Int_t       SelectDataBase(const char *dbname) = 0;
   virtual TSQLResult *GetDataBases(const char *wild = 0) = 0;
   virtual TSQLResult *GetTables(const char *dbname, const char *wild = 0) = 0;
   virtual TList      *GetTablesList(const char* wild = 0);
   virtual Bool_t      HasTable(const char* tablename);
   virtual TSQLTableInfo *GetTableInfo(const char* tablename);
   virtual TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0) = 0;
   virtual Int_t       GetMaxIdentifierLength() { return 20; }
   virtual Int_t       CreateDataBase(const char *dbname) = 0;
   virtual Int_t       DropDataBase(const char *dbname) = 0;
   virtual Int_t       Reload() = 0;
   virtual Int_t       Shutdown() = 0;
   virtual const char *ServerInfo() = 0;
   virtual Bool_t      IsConnected() const { return fPort == -1 ? kFALSE : kTRUE; }
   const char         *GetDBMS() const { return fType.Data(); }
   const char         *GetDB() const { return fDB.Data(); }
   const char         *GetHost() const { return fHost.Data(); }
   Int_t               GetPort() const { return fPort; }

   virtual Bool_t      IsError() const { return GetErrorCode()!=0; }
   virtual Int_t       GetErrorCode() const;
   virtual const char* GetErrorMsg() const;
   virtual void        EnableErrorOutput(Bool_t on = kTRUE) { fErrorOut = on; }

   virtual Bool_t      StartTransaction();
   virtual Bool_t      Commit();
   virtual Bool_t      Rollback();

   virtual Bool_t      PingVerify() { return kFALSE; }
   virtual Int_t       Ping() { return -9999; }

   static TSQLServer *Connect(const char *db, const char *uid, const char *pw);

   ClassDef(TSQLServer,0)  // Connection to SQL server
};

#endif
 TSQLServer.h:1
 TSQLServer.h:2
 TSQLServer.h:3
 TSQLServer.h:4
 TSQLServer.h:5
 TSQLServer.h:6
 TSQLServer.h:7
 TSQLServer.h:8
 TSQLServer.h:9
 TSQLServer.h:10
 TSQLServer.h:11
 TSQLServer.h:12
 TSQLServer.h:13
 TSQLServer.h:14
 TSQLServer.h:15
 TSQLServer.h:16
 TSQLServer.h:17
 TSQLServer.h:18
 TSQLServer.h:19
 TSQLServer.h:20
 TSQLServer.h:21
 TSQLServer.h:22
 TSQLServer.h:23
 TSQLServer.h:24
 TSQLServer.h:25
 TSQLServer.h:26
 TSQLServer.h:27
 TSQLServer.h:28
 TSQLServer.h:29
 TSQLServer.h:30
 TSQLServer.h:31
 TSQLServer.h:32
 TSQLServer.h:33
 TSQLServer.h:34
 TSQLServer.h:35
 TSQLServer.h:36
 TSQLServer.h:37
 TSQLServer.h:38
 TSQLServer.h:39
 TSQLServer.h:40
 TSQLServer.h:41
 TSQLServer.h:42
 TSQLServer.h:43
 TSQLServer.h:44
 TSQLServer.h:45
 TSQLServer.h:46
 TSQLServer.h:47
 TSQLServer.h:48
 TSQLServer.h:49
 TSQLServer.h:50
 TSQLServer.h:51
 TSQLServer.h:52
 TSQLServer.h:53
 TSQLServer.h:54
 TSQLServer.h:55
 TSQLServer.h:56
 TSQLServer.h:57
 TSQLServer.h:58
 TSQLServer.h:59
 TSQLServer.h:60
 TSQLServer.h:61
 TSQLServer.h:62
 TSQLServer.h:63
 TSQLServer.h:64
 TSQLServer.h:65
 TSQLServer.h:66
 TSQLServer.h:67
 TSQLServer.h:68
 TSQLServer.h:69
 TSQLServer.h:70
 TSQLServer.h:71
 TSQLServer.h:72
 TSQLServer.h:73
 TSQLServer.h:74
 TSQLServer.h:75
 TSQLServer.h:76
 TSQLServer.h:77
 TSQLServer.h:78
 TSQLServer.h:79
 TSQLServer.h:80
 TSQLServer.h:81
 TSQLServer.h:82
 TSQLServer.h:83
 TSQLServer.h:84
 TSQLServer.h:85
 TSQLServer.h:86
 TSQLServer.h:87
 TSQLServer.h:88
 TSQLServer.h:89
 TSQLServer.h:90
 TSQLServer.h:91
 TSQLServer.h:92
 TSQLServer.h:93
 TSQLServer.h:94
 TSQLServer.h:95
 TSQLServer.h:96
 TSQLServer.h:97
 TSQLServer.h:98
 TSQLServer.h:99
 TSQLServer.h:100
 TSQLServer.h:101
 TSQLServer.h:102
 TSQLServer.h:103
 TSQLServer.h:104
 TSQLServer.h:105
 TSQLServer.h:106
 TSQLServer.h:107
 TSQLServer.h:108
 TSQLServer.h:109
 TSQLServer.h:110
 TSQLServer.h:111
 TSQLServer.h:112
 TSQLServer.h:113
 TSQLServer.h:114
 TSQLServer.h:115
 TSQLServer.h:116
 TSQLServer.h:117
 TSQLServer.h:118
 TSQLServer.h:119
 TSQLServer.h:120