Logo ROOT   6.10/09
Reference Guide
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 #include "TSQLStatement.h"
16 
17 #include <libpq-fe.h>
18 #include <pg_config.h> // to get PG_VERSION_NUM
19 #ifdef USE_LDAP
20 #undef USE_LDAP
21 #endif
22 
23 #define pgsql_success(x) (((x) == PGRES_EMPTY_QUERY) \
24  || ((x) == PGRES_COMMAND_OK) \
25  || ((x) == PGRES_TUPLES_OK))
26 
27 struct PgSQL_Stmt_t {
28  PGconn *fConn;
29  PGresult *fRes;
30 };
31 
32 
34 
35 private:
36  PgSQL_Stmt_t *fStmt; //! executed statement
37  Int_t fNumBuffers; //! number of statement parameters
38  char **fBind; //! array of data for input
39  char **fFieldName; //! array of column names
40  Int_t fWorkingMode; //! 1 - setting parameters, 2 - retrieving results
41  Int_t fIterationCount;//! number of iteration
42  int *fParamLengths; //! length of column
43  int *fParamFormats; //! data type (OID)
46 
47  Bool_t IsSetParsMode() const { return fWorkingMode==1; }
48  Bool_t IsResultSetMode() const { return fWorkingMode==2; }
49 
50  Bool_t SetSQLParamType(Int_t npar, int sqltype, bool sig, int sqlsize = 0);
51 
52  long double ConvertToNumeric(Int_t npar);
53  const char *ConvertToString(Int_t npar);
54 
55  void FreeBuffers();
56  void SetBuffersNumber(Int_t n);
57 
58  void ConvertTimeToUTC(const TString &PQvalue, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec);
59 
60 public:
61  TPgSQLStatement(PgSQL_Stmt_t* stmt, Bool_t errout = kTRUE);
62  virtual ~TPgSQLStatement();
63 
64  virtual void Close(Option_t * = "");
65 
66  virtual Int_t GetBufferLength() const { return 1; }
67  virtual Int_t GetNumParameters();
68 
69  virtual Bool_t SetNull(Int_t npar);
70  virtual Bool_t SetInt(Int_t npar, Int_t value);
71  virtual Bool_t SetUInt(Int_t npar, UInt_t value);
72  virtual Bool_t SetLong(Int_t npar, Long_t value);
73  virtual Bool_t SetLong64(Int_t npar, Long64_t value);
74  virtual Bool_t SetULong64(Int_t npar, ULong64_t value);
75  virtual Bool_t SetDouble(Int_t npar, Double_t value);
76  virtual Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256);
77  virtual Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
78  virtual Bool_t SetLargeObject(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
79  virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day);
80  virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec);
81  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);
82  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);
83 
84  virtual Bool_t NextIteration();
85 
86  virtual Bool_t Process();
87  virtual Int_t GetNumAffectedRows();
88 
89  virtual Bool_t StoreResult();
90  virtual Int_t GetNumFields();
91  virtual const char *GetFieldName(Int_t nfield);
92  virtual Bool_t NextResultRow();
93 
94  virtual Bool_t IsNull(Int_t npar);
95  virtual Int_t GetInt(Int_t npar);
96  virtual UInt_t GetUInt(Int_t npar);
97  virtual Long_t GetLong(Int_t npar);
98  virtual Long64_t GetLong64(Int_t npar);
99  virtual ULong64_t GetULong64(Int_t npar);
100  virtual Double_t GetDouble(Int_t npar);
101  virtual const char *GetString(Int_t npar);
102  virtual Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size);
103  virtual Bool_t GetLargeObject(Int_t npar, void* &mem, Long_t& size);
104  virtual Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day);
105  virtual Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec);
106  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);
107  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&);
108 
109  ClassDef(TPgSQLStatement, 0); // SQL statement class for PgSQL DB
110 };
111 
112 #endif
Int_t fWorkingMode
array of column names
long long Long64_t
Definition: RtypesCore.h:69
int * fParamFormats
length of column
const char Option_t
Definition: RtypesCore.h:62
Int_t fIterationCount
1 - setting parameters, 2 - retrieving results
char ** fBind
number of statement parameters
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
PGresult * fRes
PGconn * fConn
char ** fFieldName
array of data for input
#define ClassDef(name, id)
Definition: Rtypes.h:297
Int_t fNumBuffers
executed statement
const int maxsize
virtual Int_t GetBufferLength() const
Bool_t IsSetParsMode() const
PgSQL_Stmt_t * fStmt
unsigned int UInt_t
Definition: RtypesCore.h:42
int * fParamLengths
number of iteration
long Long_t
Definition: RtypesCore.h:50
double Double_t
Definition: RtypesCore.h:55
unsigned long long ULong64_t
Definition: RtypesCore.h:70
Bool_t IsResultSetMode() const
Int_t fNumResultRows
data type (OID)
const Bool_t kTRUE
Definition: RtypesCore.h:91
const Int_t n
Definition: legend1.C:16