Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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{-1}; // port to which we are connected
48 Int_t fErrorCode{0}; // error code of last operation
49 TString fErrorMsg; // error message of last operation
50 Bool_t fErrorOut{kTRUE}; // enable error output
51
52 TSQLServer() {} // not allowed to use =default for TObject-derived classes
53
54 void ClearError();
55 void SetError(Int_t code, const char* msg, const char *method = nullptr);
56
57 static const char* fgFloatFmt; //! printf argument for floats and doubles, either "%f" or "%e" or "%10f" and so on
58
59public:
60 enum ESQLDataTypes { // data types, recognised by TSQLServer and other classes, extrction from ODBC
61 kSQL_NONE = -1, // data type unknown
62 kSQL_CHAR = 1, // CHAR(n) - string with fixed length n
63 kSQL_VARCHAR = 2, // VARCHAR(n) - string with variable length upto n
64 kSQL_INTEGER = 3, // INTEGER, INT - integer value
65 kSQL_FLOAT = 4, // FLOAT - float value
66 kSQL_DOUBLE = 5, // DOUBLE - double value
67 kSQL_NUMERIC = 6, // NUMERIC - numeric values with length and precion
68 kSQL_BINARY = 7, // BLOB - binary data
69 kSQL_TIMESTAMP = 8 // TIMESTAMP -
70 };
71
72 virtual ~TSQLServer() { }
73
74 virtual void Close(Option_t *option = "") = 0;
75 virtual TSQLResult *Query(const char *sql) = 0;
76 virtual Bool_t Exec(const char* sql);
77 virtual TSQLStatement *Statement(const char*, Int_t = 100)
78 { AbstractMethod("Statement"); return nullptr; }
79 virtual Bool_t HasStatement() const { return kFALSE; }
80 virtual Int_t SelectDataBase(const char *dbname) = 0;
81 virtual TSQLResult *GetDataBases(const char *wild = nullptr) = 0;
82 virtual TSQLResult *GetTables(const char *dbname, const char *wild = nullptr) = 0;
83 virtual TList *GetTablesList(const char* wild = nullptr);
84 virtual Bool_t HasTable(const char* tablename);
85 virtual TSQLTableInfo *GetTableInfo(const char* tablename);
86 virtual TSQLResult *GetColumns(const char *dbname, const char *table, const char *wild = nullptr) = 0;
87 virtual Int_t GetMaxIdentifierLength() { return 20; }
88 virtual Int_t CreateDataBase(const char *dbname) = 0;
89 virtual Int_t DropDataBase(const char *dbname) = 0;
90 virtual Int_t Reload() = 0;
91 virtual Int_t Shutdown() = 0;
92 virtual const char *ServerInfo() = 0;
93 virtual Bool_t IsConnected() const { return fPort == -1 ? kFALSE : kTRUE; }
94 const char *GetDBMS() const { return fType.Data(); }
95 const char *GetDB() const { return fDB.Data(); }
96 const char *GetHost() const { return fHost.Data(); }
97 Int_t GetPort() const { return fPort; }
98
99 virtual Bool_t IsError() const { return GetErrorCode()!=0; }
100 virtual Int_t GetErrorCode() const;
101 virtual const char* GetErrorMsg() const;
102 virtual void EnableErrorOutput(Bool_t on = kTRUE) { fErrorOut = on; }
103
104 virtual Bool_t StartTransaction();
106 virtual Bool_t Commit();
107 virtual Bool_t Rollback();
108
109 virtual Bool_t PingVerify() { return kFALSE; }
110 virtual Int_t Ping() { return -9999; }
111
112 static TSQLServer *Connect(const char *db, const char *uid, const char *pw);
113
114 static void SetFloatFormat(const char* fmt = "%e");
115 static const char* GetFloatFormat();
116
117 ClassDef(TSQLServer,0) // Connection to SQL server
118};
119
120#endif
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
bool Bool_t
Definition RtypesCore.h:63
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
A doubly linked list.
Definition TList.h:38
Mother of all ROOT objects.
Definition TObject.h:41
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:1005
virtual void EnableErrorOutput(Bool_t on=kTRUE)
Definition TSQLServer.h:102
virtual void Close(Option_t *option="")=0
const char * GetDB() const
Definition TSQLServer.h:95
virtual Int_t SelectDataBase(const char *dbname)=0
virtual Bool_t Commit()
submit "COMMIT" query to database return kTRUE, if successful
const char * GetHost() const
Definition TSQLServer.h:96
void ClearError()
reset error fields
virtual const char * GetErrorMsg() const
returns error message of last operation if no errors, return 0 Each specific implementation of TSQLSe...
TString fHost
Definition TSQLServer.h:45
const char * GetDBMS() const
Definition TSQLServer.h:94
virtual TSQLTableInfo * GetTableInfo(const char *tablename)
Produce TSQLTableInfo object, which contain info about table itself and each table column Object must...
void SetError(Int_t code, const char *msg, const char *method=nullptr)
set new values for error fields if method is specified, displays error message
virtual Int_t Shutdown()=0
virtual Int_t CreateDataBase(const char *dbname)=0
Int_t fPort
Definition TSQLServer.h:47
virtual Bool_t HasTransactionInFlight()
returns kTRUE when transaction is running Must be implemented in derived classes
virtual Bool_t HasStatement() const
Definition TSQLServer.h:79
virtual Int_t GetErrorCode() const
returns error code of last operation if res==0, no error Each specific implementation of TSQLServer p...
Bool_t fErrorOut
Definition TSQLServer.h:50
virtual Int_t GetMaxIdentifierLength()
Definition TSQLServer.h:87
virtual TSQLResult * GetColumns(const char *dbname, const char *table, const char *wild=nullptr)=0
Int_t fErrorCode
Definition TSQLServer.h:48
virtual ~TSQLServer()
Definition TSQLServer.h:72
virtual Bool_t HasTable(const char *tablename)
Tests if table of that name exists in database Return kTRUE, if table exists.
virtual TSQLResult * GetDataBases(const char *wild=nullptr)=0
virtual Bool_t Exec(const char *sql)
Execute sql query.
virtual Bool_t Rollback()
submit "ROLLBACK" query to database return kTRUE, if successful
virtual Bool_t PingVerify()
Definition TSQLServer.h:109
virtual Bool_t StartTransaction()
submit "START TRANSACTION" query to database return kTRUE, if successful
virtual TList * GetTablesList(const char *wild=nullptr)
Return list of user tables Parameter wild specifies wildcard for table names.
virtual const char * ServerInfo()=0
virtual TSQLResult * Query(const char *sql)=0
virtual TSQLResult * GetTables(const char *dbname, const char *wild=nullptr)=0
TString fErrorMsg
Definition TSQLServer.h:49
TString fDB
Definition TSQLServer.h:46
virtual Bool_t IsError() const
Definition TSQLServer.h:99
static void SetFloatFormat(const char *fmt="%e")
set printf format for float/double members, default "%e"
Int_t GetPort() const
Definition TSQLServer.h:97
static const char * fgFloatFmt
Definition TSQLServer.h:57
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.: mysql://pcroot....
virtual TSQLStatement * Statement(const char *, Int_t=100)
Definition TSQLServer.h:77
virtual Int_t Ping()
Definition TSQLServer.h:110
virtual Int_t DropDataBase(const char *dbname)=0
static const char * GetFloatFormat()
return current printf format for float/double members, default "%e"
virtual Bool_t IsConnected() const
Definition TSQLServer.h:93
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:60
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369