ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TSQLServer.h
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fons Rademakers 25/11/99
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TSQLServer
13 #define ROOT_TSQLServer
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TSQLServer //
19 // //
20 // Abstract base class defining interface to a SQL server. //
21 // //
22 // To open a connection to a server use the static method Connect(). //
23 // The db argument of Connect() is of the form: //
24 // <dbms>://<host>[:<port>][/<database>], e.g. //
25 // mysql://pcroot.cern.ch:3456/test, oracle://srv1.cern.ch/main, ... //
26 // Depending on the <dbms> specified an appropriate plugin library //
27 // will be loaded which will provide the real interface. //
28 // //
29 // Related classes are TSQLStatement, TSQLResult and TSQLRow. //
30 // //
31 //////////////////////////////////////////////////////////////////////////
32 
33 #ifndef ROOT_TObject
34 #include "TObject.h"
35 #endif
36 #ifndef ROOT_TString
37 #include "TString.h"
38 #endif
39 
40 class TSQLResult;
41 class TSQLStatement;
42 class TSQLTableInfo;
43 class TList;
44 
45 class TSQLServer : public TObject {
46 
47 protected:
48  TString fType; // type of DBMS (MySQL, Oracle, SysBase, ...)
49  TString fHost; // host to which we are connected
50  TString fDB; // currently selected DB
51  Int_t fPort; // port to which we are connected
52  Int_t fErrorCode; // error code of last operation
53  TString fErrorMsg; // error message of last operation
54  Bool_t fErrorOut; // enable error output
55 
57  : fType(), fHost(), fDB(), fPort(-1), fErrorCode(0),
59 
60  void ClearError();
61  void SetError(Int_t code, const char* msg, const char* method = 0);
62 
63  static const char* fgFloatFmt; //! printf argument for floats and doubles, either "%f" or "%e" or "%10f" and so on
64 
65 public:
66  enum ESQLDataTypes { // data types, recognised by TSQLServer and other classes, extrction from ODBC
67  kSQL_NONE = -1, // data type unknown
68  kSQL_CHAR = 1, // CHAR(n) - string with fixed length n
69  kSQL_VARCHAR = 2, // VARCHAR(n) - string with variable length upto n
70  kSQL_INTEGER = 3, // INTEGER, INT - integer value
71  kSQL_FLOAT = 4, // FLOAT - float value
72  kSQL_DOUBLE = 5, // DOUBLE - double value
73  kSQL_NUMERIC = 6, // NUMERIC - numeric values with length and precion
74  kSQL_BINARY = 7, // BLOB - binary data
75  kSQL_TIMESTAMP = 8 // TIMESTAMP -
76  };
77 
78  virtual ~TSQLServer() { }
79 
80  virtual void Close(Option_t *option="") = 0;
81  virtual TSQLResult *Query(const char *sql) = 0;
82  virtual Bool_t Exec(const char* sql);
83  virtual TSQLStatement *Statement(const char*, Int_t = 100)
84  { AbstractMethod("Statement"); return 0; }
85  virtual Bool_t HasStatement() const { return kFALSE; }
86  virtual Int_t SelectDataBase(const char *dbname) = 0;
87  virtual TSQLResult *GetDataBases(const char *wild = 0) = 0;
88  virtual TSQLResult *GetTables(const char *dbname, const char *wild = 0) = 0;
89  virtual TList *GetTablesList(const char* wild = 0);
90  virtual Bool_t HasTable(const char* tablename);
91  virtual TSQLTableInfo *GetTableInfo(const char* tablename);
92  virtual TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0) = 0;
93  virtual Int_t GetMaxIdentifierLength() { return 20; }
94  virtual Int_t CreateDataBase(const char *dbname) = 0;
95  virtual Int_t DropDataBase(const char *dbname) = 0;
96  virtual Int_t Reload() = 0;
97  virtual Int_t Shutdown() = 0;
98  virtual const char *ServerInfo() = 0;
99  virtual Bool_t IsConnected() const { return fPort == -1 ? kFALSE : kTRUE; }
100  const char *GetDBMS() const { return fType.Data(); }
101  const char *GetDB() const { return fDB.Data(); }
102  const char *GetHost() const { return fHost.Data(); }
103  Int_t GetPort() const { return fPort; }
104 
105  virtual Bool_t IsError() const { return GetErrorCode()!=0; }
106  virtual Int_t GetErrorCode() const;
107  virtual const char* GetErrorMsg() const;
108  virtual void EnableErrorOutput(Bool_t on = kTRUE) { fErrorOut = on; }
109 
110  virtual Bool_t StartTransaction();
111  virtual Bool_t Commit();
112  virtual Bool_t Rollback();
113 
114  virtual Bool_t PingVerify() { return kFALSE; }
115  virtual Int_t Ping() { return -9999; }
116 
117  static TSQLServer *Connect(const char *db, const char *uid, const char *pw);
118 
119  static void SetFloatFormat(const char* fmt = "%e");
120  static const char* GetFloatFormat();
121 
122  ClassDef(TSQLServer,0) // Connection to SQL server
123 };
124 
125 #endif
virtual Bool_t Exec(const char *sql)
Execute sql query.
Definition: TSQLServer.cxx:85
virtual Bool_t IsError() const
Definition: TSQLServer.h:105
const char * GetDBMS() const
Definition: TSQLServer.h:100
static const char * fgFloatFmt
Definition: TSQLServer.h:63
TString fDB
Definition: TSQLServer.h:50
virtual Bool_t PingVerify()
Definition: TSQLServer.h:114
const char * dbname
Definition: sqlcanvas.C:7
virtual TSQLResult * GetDataBases(const char *wild=0)=0
const char Option_t
Definition: RtypesCore.h:62
virtual TSQLResult * Query(const char *sql)=0
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
virtual Bool_t StartTransaction()
submit "START TRANSACTION" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:141
virtual Int_t CreateDataBase(const char *dbname)=0
Basic string class.
Definition: TString.h:137
virtual const char * GetErrorMsg() const
returns error message of last operation if no errors, return 0 Each specific implementation of TSQLSe...
Definition: TSQLServer.cxx:111
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual ~TSQLServer()
Definition: TSQLServer.h:78
virtual TSQLStatement * Statement(const char *, Int_t=100)
Definition: TSQLServer.h:83
static const char * GetFloatFormat()
return current printf format for float/double members, default "%e"
Definition: TSQLServer.cxx:269
virtual Int_t DropDataBase(const char *dbname)=0
ESQLDataTypes
printf argument for floats and doubles, either "%f" or "%e" or "%10f" and so on
Definition: TSQLServer.h:66
TString fErrorMsg
Definition: TSQLServer.h:53
const char * Data() const
Definition: TString.h:349
#define ClassDef(name, id)
Definition: Rtypes.h:254
void ClearError()
reset error fields
Definition: TSQLServer.cxx:119
virtual Int_t GetErrorCode() const
returns error code of last operation if res==0, no error Each specific implementation of TSQLServer p...
Definition: TSQLServer.cxx:101
virtual Bool_t Rollback()
submit "ROLLBACK" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:159
virtual Int_t SelectDataBase(const char *dbname)=0
virtual TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)=0
virtual Bool_t IsConnected() const
Definition: TSQLServer.h:99
A doubly linked list.
Definition: TList.h:47
virtual Int_t Reload()=0
Int_t fErrorCode
Definition: TSQLServer.h:52
virtual const char * ServerInfo()=0
virtual Int_t GetMaxIdentifierLength()
Definition: TSQLServer.h:93
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e"
Definition: TSQLServer.cxx:260
virtual Bool_t Commit()
submit "COMMIT" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:150
void AbstractMethod(const char *method) const
Use this method to implement an "abstract" method that you don't want to leave purely abstract...
Definition: TObject.cxx:960
TString fHost
Definition: TSQLServer.h:49
virtual Int_t Shutdown()=0
Int_t GetPort() const
Definition: TSQLServer.h:103
Int_t fPort
Definition: TSQLServer.h:51
virtual TSQLResult * GetTables(const char *dbname, const char *wild=0)=0
const char * GetDB() const
Definition: TSQLServer.h:101
virtual void EnableErrorOutput(Bool_t on=kTRUE)
Definition: TSQLServer.h:108
virtual TSQLTableInfo * GetTableInfo(const char *tablename)
Producec TSQLTableInfo object, which contain info about table itself and each table column Object mus...
Definition: TSQLServer.cxx:236
void SetError(Int_t code, const char *msg, const char *method=0)
set new values for error fields if method is specified, displays error message
Definition: TSQLServer.cxx:129
Mother of all ROOT objects.
Definition: TObject.h:58
const char * GetHost() const
Definition: TSQLServer.h:102
virtual TList * GetTablesList(const char *wild=0)
Return list of user tables Parameter wild specifies wildcard for table names.
Definition: TSQLServer.cxx:182
virtual Int_t Ping()
Definition: TSQLServer.h:115
virtual void Close(Option_t *option="")=0
virtual Bool_t HasStatement() const
Definition: TSQLServer.h:85
virtual Bool_t HasTable(const char *tablename)
Tests if table of that name exists in database Return kTRUE, if table exists.
Definition: TSQLServer.cxx:208
TString fType
Definition: TSQLServer.h:48
const Bool_t kTRUE
Definition: Rtypes.h:91
Bool_t fErrorOut
Definition: TSQLServer.h:54