ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TPgSQLStatement.h
Go to the documentation of this file.
1 // @(#)root/mysql:$Id$
2 // Author: Dennis Box (dbox@fnal.gov) 3/12/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, 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_TPgSQLStatement
13 #define ROOT_TPgSQLStatement
14 
15 #ifndef ROOT_TSQLStatement
16 #include "TSQLStatement.h"
17 #endif
18 
19 #include <libpq-fe.h>
20 #include <pg_config.h> // to get PG_VERSION_NUM
21 #ifdef USE_LDAP
22 #undef USE_LDAP
23 #endif
24 
25 #define pgsql_success(x) (((x) == PGRES_EMPTY_QUERY) \
26  || ((x) == PGRES_COMMAND_OK) \
27  || ((x) == PGRES_TUPLES_OK))
28 
29 struct PgSQL_Stmt_t {
30  PGconn *fConn;
31  PGresult *fRes;
32 };
33 
34 
36 
37 private:
38  PgSQL_Stmt_t *fStmt; //! executed statement
39  Int_t fNumBuffers; //! number of statement parameters
40  char **fBind; //! array of data for input
41  char **fFieldName; //! array of column names
42  Int_t fWorkingMode; //! 1 - setting parameters, 2 - retrieving results
43  Int_t fIterationCount;//! number of iteration
44  int *fParamLengths; //! length of column
45  int *fParamFormats; //! data type (OID)
48 
49  Bool_t IsSetParsMode() const { return fWorkingMode==1; }
50  Bool_t IsResultSetMode() const { return fWorkingMode==2; }
51 
52  Bool_t SetSQLParamType(Int_t npar, int sqltype, bool sig, int sqlsize = 0);
53 
54  long double ConvertToNumeric(Int_t npar);
55  const char *ConvertToString(Int_t npar);
56 
57  void FreeBuffers();
58  void SetBuffersNumber(Int_t n);
59 
60  void ConvertTimeToUTC(const TString &PQvalue, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec);
61 
62 public:
63  TPgSQLStatement(PgSQL_Stmt_t* stmt, Bool_t errout = kTRUE);
64  virtual ~TPgSQLStatement();
65 
66  virtual void Close(Option_t * = "");
67 
68  virtual Int_t GetBufferLength() const { return 1; }
69  virtual Int_t GetNumParameters();
70 
71  virtual Bool_t SetNull(Int_t npar);
72  virtual Bool_t SetInt(Int_t npar, Int_t value);
73  virtual Bool_t SetUInt(Int_t npar, UInt_t value);
74  virtual Bool_t SetLong(Int_t npar, Long_t value);
75  virtual Bool_t SetLong64(Int_t npar, Long64_t value);
76  virtual Bool_t SetULong64(Int_t npar, ULong64_t value);
77  virtual Bool_t SetDouble(Int_t npar, Double_t value);
78  virtual Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256);
79  virtual Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
80  virtual Bool_t SetLargeObject(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
81  virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day);
82  virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec);
83  virtual Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec);
84  virtual Bool_t SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t frac = 0);
85 
86  virtual Bool_t NextIteration();
87 
88  virtual Bool_t Process();
89  virtual Int_t GetNumAffectedRows();
90 
91  virtual Bool_t StoreResult();
92  virtual Int_t GetNumFields();
93  virtual const char *GetFieldName(Int_t nfield);
94  virtual Bool_t NextResultRow();
95 
96  virtual Bool_t IsNull(Int_t npar);
97  virtual Int_t GetInt(Int_t npar);
98  virtual UInt_t GetUInt(Int_t npar);
99  virtual Long_t GetLong(Int_t npar);
100  virtual Long64_t GetLong64(Int_t npar);
101  virtual ULong64_t GetULong64(Int_t npar);
102  virtual Double_t GetDouble(Int_t npar);
103  virtual const char *GetString(Int_t npar);
104  virtual Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size);
105  virtual Bool_t GetLargeObject(Int_t npar, void* &mem, Long_t& size);
106  virtual Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day);
107  virtual Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec);
108  virtual Bool_t GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec);
109  virtual Bool_t GetTimestamp(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec, Int_t&);
110 
111  ClassDef(TPgSQLStatement, 0); // SQL statement class for PgSQL DB
112 };
113 
114 #endif
Bool_t SetSQLParamType(Int_t npar, int sqltype, bool sig, int sqlsize=0)
Set parameter type to be used as buffer.
virtual Bool_t StoreResult()
Store result of statement processing to access them via GetInt(), GetDouble() and so on methods...
Int_t fWorkingMode
array of column names
const char * ConvertToString(Int_t npar)
Convert field value to string.
virtual Int_t GetNumAffectedRows()
Return number of affected rows after statement is processed.
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
long long Long64_t
Definition: RtypesCore.h:69
virtual const char * GetString(Int_t npar)
Return field value as string.
virtual Bool_t SetDouble(Int_t npar, Double_t value)
Set parameter value as double.
int * fParamFormats
length of column
const char Option_t
Definition: RtypesCore.h:62
virtual Int_t GetInt(Int_t npar)
Return field value as integer.
virtual Bool_t SetNull(Int_t npar)
Set NULL as parameter value.
virtual Bool_t NextResultRow()
Shift cursor to nect row in result set.
virtual Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec)
Return field value as time.
virtual UInt_t GetUInt(Int_t npar)
Return field value as unsigned integer.
Int_t fIterationCount
1 - setting parameters, 2 - retrieving results
char ** fBind
number of statement parameters
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t GetLargeObject(Int_t npar, void *&mem, Long_t &size)
Return large object whose oid is in the given field.
PGresult * fRes
void ConvertTimeToUTC(const TString &PQvalue, Int_t &year, Int_t &month, Int_t &day, Int_t &hour, Int_t &min, Int_t &sec)
virtual Bool_t SetTimestamp(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t frac=0)
Set parameter value as timestamp.
PGconn * fConn
virtual Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256)
Set parameter value as string.
virtual Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size)
Return field value as binary array.
Bool_t IsSetParsMode() const
virtual Bool_t IsNull(Int_t npar)
Checks if field value is null.
virtual void Close(Option_t *="")
Close statement.
char ** fFieldName
array of data for input
long double ConvertToNumeric(Int_t npar)
Convert field to numeric value.
virtual Int_t GetNumFields()
Return number of fields in result set.
Int_t fNumBuffers
executed statement
virtual Bool_t SetULong64(Int_t npar, ULong64_t value)
Set parameter value as unsigned 64-bit integer.
const int maxsize
virtual Bool_t Process()
Process statement.
virtual Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec)
Set parameter value as date & time.
virtual ULong64_t GetULong64(Int_t npar)
Return field value as unsigned 64-bit integer.
virtual Bool_t GetDatime(Int_t npar, Int_t &year, Int_t &month, Int_t &day, Int_t &hour, Int_t &min, Int_t &sec)
Return field value as date & time.
virtual Double_t GetDouble(Int_t npar)
Return field value as double.
virtual Bool_t SetInt(Int_t npar, Int_t value)
Set parameter value as integer.
virtual Bool_t SetLargeObject(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000)
Set parameter value to large object and immediately insert the large object into DB.
virtual Bool_t SetLong(Int_t npar, Long_t value)
Set parameter value as long integer.
PgSQL_Stmt_t * fStmt
unsigned int UInt_t
Definition: RtypesCore.h:42
int * fParamLengths
number of iteration
ClassDef(TPgSQLStatement, 0)
virtual const char * GetFieldName(Int_t nfield)
Returns field name in result set.
long Long_t
Definition: RtypesCore.h:50
void FreeBuffers()
Release all buffers, used by statement.
double Double_t
Definition: RtypesCore.h:55
virtual Long_t GetLong(Int_t npar)
Return field value as long integer.
unsigned long long ULong64_t
Definition: RtypesCore.h:70
virtual Long64_t GetLong64(Int_t npar)
Return field value as 64-bit integer.
virtual Bool_t GetTimestamp(Int_t npar, Int_t &year, Int_t &month, Int_t &day, Int_t &hour, Int_t &min, Int_t &sec, Int_t &)
Return field value as time stamp.
virtual Int_t GetNumParameters()
Return number of statement parameters.
virtual Bool_t SetUInt(Int_t npar, UInt_t value)
Set parameter value as unsigned integer.
Bool_t IsResultSetMode() const
virtual Int_t GetBufferLength() const
virtual Bool_t NextIteration()
Increment iteration counter for statement, where parameter can be set.
Int_t fNumResultRows
data type (OID)
virtual Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000)
Set parameter value as binary data.
virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec)
Set parameter value as time.
void SetBuffersNumber(Int_t n)
Allocate buffers for statement parameters/ result fields.
virtual ~TPgSQLStatement()
Destructor.
const Bool_t kTRUE
Definition: Rtypes.h:91
float value
Definition: math.cpp:443
const Int_t n
Definition: legend1.C:16
TPgSQLStatement(PgSQL_Stmt_t *stmt, Bool_t errout=kTRUE)
virtual Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day)
Return field value as date.
virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day)
Set parameter value as date.
virtual Bool_t SetLong64(Int_t npar, Long64_t value)
Set parameter value as 64-bit integer.