Logo ROOT  
Reference Guide
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#include "TObject.h"
34#include "TString.h"
35
36class TSQLResult;
37class TSQLStatement;
38class TSQLTableInfo;
39class TList;
40
41class TSQLServer : public TObject {
42
43protected:
44 TString fType; // type of DBMS (MySQL, Oracle, SysBase, ...)
45 TString fHost; // host to which we are connected
46 TString fDB; // currently selected DB
47 Int_t fPort; // port to which we are connected
48 Int_t fErrorCode; // error code of last operation
49 TString fErrorMsg; // error message of last operation
50 Bool_t fErrorOut; // enable error output
51
53 : fType(), fHost(), fDB(), fPort(-1), fErrorCode(0),
55
56 void ClearError();
57 void SetError(Int_t code, const char* msg, const char* method = 0);
58
59 static const char* fgFloatFmt; //! printf argument for floats and doubles, either "%f" or "%e" or "%10f" and so on
60
61public:
62 enum ESQLDataTypes { // data types, recognised by TSQLServer and other classes, extrction from ODBC
63 kSQL_NONE = -1, // data type unknown
64 kSQL_CHAR = 1, // CHAR(n) - string with fixed length n
65 kSQL_VARCHAR = 2, // VARCHAR(n) - string with variable length upto n
66 kSQL_INTEGER = 3, // INTEGER, INT - integer value
67 kSQL_FLOAT = 4, // FLOAT - float value
68 kSQL_DOUBLE = 5, // DOUBLE - double value
69 kSQL_NUMERIC = 6, // NUMERIC - numeric values with length and precion
70 kSQL_BINARY = 7, // BLOB - binary data
71 kSQL_TIMESTAMP = 8 // TIMESTAMP -
72 };
73
74 virtual ~TSQLServer() { }
75
76 virtual void Close(Option_t *option="") = 0;
77 virtual TSQLResult *Query(const char *sql) = 0;
78 virtual Bool_t Exec(const char* sql);
79 virtual TSQLStatement *Statement(const char*, Int_t = 100)
80 { AbstractMethod("Statement"); return 0; }
81 virtual Bool_t HasStatement() const { return kFALSE; }
82 virtual Int_t SelectDataBase(const char *dbname) = 0;
83 virtual TSQLResult *GetDataBases(const char *wild = 0) = 0;
84 virtual TSQLResult *GetTables(const char *dbname, const char *wild = 0) = 0;
85 virtual TList *GetTablesList(const char* wild = 0);
86 virtual Bool_t HasTable(const char* tablename);
87 virtual TSQLTableInfo *GetTableInfo(const char* tablename);
88 virtual TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = 0) = 0;
89 virtual Int_t GetMaxIdentifierLength() { return 20; }
90 virtual Int_t CreateDataBase(const char *dbname) = 0;
91 virtual Int_t DropDataBase(const char *dbname) = 0;
92 virtual Int_t Reload() = 0;
93 virtual Int_t Shutdown() = 0;
94 virtual const char *ServerInfo() = 0;
95 virtual Bool_t IsConnected() const { return fPort == -1 ? kFALSE : kTRUE; }
96 const char *GetDBMS() const { return fType.Data(); }
97 const char *GetDB() const { return fDB.Data(); }
98 const char *GetHost() const { return fHost.Data(); }
99 Int_t GetPort() const { return fPort; }
100
101 virtual Bool_t IsError() const { return GetErrorCode()!=0; }
102 virtual Int_t GetErrorCode() const;
103 virtual const char* GetErrorMsg() const;
104 virtual void EnableErrorOutput(Bool_t on = kTRUE) { fErrorOut = on; }
105
106 virtual Bool_t StartTransaction();
107 virtual Bool_t Commit();
108 virtual Bool_t Rollback();
109
110 virtual Bool_t PingVerify() { return kFALSE; }
111 virtual Int_t Ping() { return -9999; }
112
113 static TSQLServer *Connect(const char *db, const char *uid, const char *pw);
114
115 static void SetFloatFormat(const char* fmt = "%e");
116 static const char* GetFloatFormat();
117
118 ClassDef(TSQLServer,0) // Connection to SQL server
119};
120
121#endif
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
A doubly linked list.
Definition: TList.h:44
Mother of all ROOT objects.
Definition: TObject.h:37
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:922
virtual void EnableErrorOutput(Bool_t on=kTRUE)
Definition: TSQLServer.h:104
virtual void Close(Option_t *option="")=0
const char * GetDB() const
Definition: TSQLServer.h:97
virtual Int_t SelectDataBase(const char *dbname)=0
virtual TList * GetTablesList(const char *wild=0)
Return list of user tables Parameter wild specifies wildcard for table names.
Definition: TSQLServer.cxx:182
virtual Bool_t Commit()
submit "COMMIT" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:150
const char * GetHost() const
Definition: TSQLServer.h:98
void ClearError()
reset error fields
Definition: TSQLServer.cxx:119
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
TString fHost
Definition: TSQLServer.h:45
const char * GetDBMS() const
Definition: TSQLServer.h:96
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
virtual Int_t Shutdown()=0
virtual Int_t CreateDataBase(const char *dbname)=0
Int_t fPort
Definition: TSQLServer.h:47
virtual Bool_t HasStatement() const
Definition: TSQLServer.h:81
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
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
Bool_t fErrorOut
Definition: TSQLServer.h:50
virtual Int_t GetMaxIdentifierLength()
Definition: TSQLServer.h:89
Int_t fErrorCode
Definition: TSQLServer.h:48
virtual ~TSQLServer()
Definition: TSQLServer.h:74
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
virtual Bool_t Exec(const char *sql)
Execute sql query.
Definition: TSQLServer.cxx:85
virtual Bool_t Rollback()
submit "ROLLBACK" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:159
virtual Bool_t PingVerify()
Definition: TSQLServer.h:110
virtual Bool_t StartTransaction()
submit "START TRANSACTION" query to database return kTRUE, if successful
Definition: TSQLServer.cxx:141
virtual const char * ServerInfo()=0
virtual TSQLResult * Query(const char *sql)=0
virtual TSQLResult * GetTables(const char *dbname, const char *wild=0)=0
TString fErrorMsg
Definition: TSQLServer.h:49
TString fDB
Definition: TSQLServer.h:46
virtual Bool_t IsError() const
Definition: TSQLServer.h:101
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e"
Definition: TSQLServer.cxx:260
Int_t GetPort() const
Definition: TSQLServer.h:99
static const char * fgFloatFmt
Definition: TSQLServer.h:59
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
The db should be of the form: <dbms>://<host>[:<port>][/<database>], e.g.
Definition: TSQLServer.cxx:61
virtual TSQLStatement * Statement(const char *, Int_t=100)
Definition: TSQLServer.h:79
virtual Int_t Ping()
Definition: TSQLServer.h:111
virtual Int_t DropDataBase(const char *dbname)=0
static const char * GetFloatFormat()
return current printf format for float/double members, default "%e"
Definition: TSQLServer.cxx:269
virtual Bool_t IsConnected() const
Definition: TSQLServer.h:95
virtual Int_t Reload()=0
TString fType
Definition: TSQLServer.h:44
ESQLDataTypes
printf argument for floats and doubles, either "%f" or "%e" or "%10f" and so on
Definition: TSQLServer.h:62
@ kSQL_VARCHAR
Definition: TSQLServer.h:65
@ kSQL_TIMESTAMP
Definition: TSQLServer.h:71
@ kSQL_INTEGER
Definition: TSQLServer.h:66
@ kSQL_NUMERIC
Definition: TSQLServer.h:69
virtual TSQLResult * GetDataBases(const char *wild=0)=0
virtual TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=0)=0
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364