Logo ROOT  
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
21 PGconn *fConn;
22 PGresult *fRes;
23};
24
26
27private:
28
29
30 PgSQL_Stmt_t *fStmt{nullptr}; //! executed statement
31 Int_t fNumBuffers{0}; //! number of statement parameters
32 char **fBind{nullptr}; //! array of data for input
33 char **fFieldName{nullptr}; //! array of column names
34 Int_t fWorkingMode{0}; //! 1 - setting parameters, 2 - retrieving results
35 Int_t fIterationCount{0}; //! number of iteration
36 int *fParamLengths{nullptr}; //! length of column
37 int *fParamFormats{nullptr}; //! data type (OID)
40
41 Bool_t IsSetParsMode() const { return fWorkingMode==1; }
42 Bool_t IsResultSetMode() const { return fWorkingMode==2; }
43
44 Bool_t SetSQLParamType(Int_t npar, Bool_t isbinary = kFALSE, Int_t param_len = 0, Int_t maxsize = 0);
45
46 long double ConvertToNumeric(Int_t npar);
47 const char *ConvertToString(Int_t npar);
48
49 void FreeBuffers();
51
52 void ConvertTimeToUTC(const TString &PQvalue, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec);
53
54public:
56 virtual ~TPgSQLStatement();
57
58 void Close(Option_t * = "") final;
59
60 Int_t GetBufferLength() const final { return 1; }
61 Int_t GetNumParameters() final;
62
63 Bool_t SetNull(Int_t npar) final;
64 Bool_t SetInt(Int_t npar, Int_t value) final;
65 Bool_t SetUInt(Int_t npar, UInt_t value) final;
66 Bool_t SetLong(Int_t npar, Long_t value) final;
67 Bool_t SetLong64(Int_t npar, Long64_t value) final;
68 Bool_t SetULong64(Int_t npar, ULong64_t value) final;
69 Bool_t SetDouble(Int_t npar, Double_t value) final;
70 Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256) final;
71 Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final;
72 Bool_t SetLargeObject(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final;
73 Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final;
74 Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final;
75 Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) final;
76 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) final;
77 Bool_t SetTimestamp(Int_t npar, const TTimeStamp& tm) final;
78
79 Bool_t NextIteration() final;
80
81 Bool_t Process() final;
83
84 Bool_t StoreResult() final;
85 Int_t GetNumFields() final;
86 const char *GetFieldName(Int_t nfield) final;
87 Bool_t NextResultRow() final;
88
89 Bool_t IsNull(Int_t npar) final;
90 Int_t GetInt(Int_t npar) final;
91 UInt_t GetUInt(Int_t npar) final;
92 Long_t GetLong(Int_t npar) final;
93 Long64_t GetLong64(Int_t npar) final;
94 ULong64_t GetULong64(Int_t npar) final;
95 Double_t GetDouble(Int_t npar) final;
96 const char *GetString(Int_t npar) final;
97 Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size) final;
98 Bool_t GetLargeObject(Int_t npar, void* &mem, Long_t& size) final;
99 Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) final;
100 Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) final;
101 Bool_t GetDatime(Int_t npar, Int_t& year, Int_t& month, Int_t& day, Int_t& hour, Int_t& min, Int_t& sec) final;
102 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&) final;
103 Bool_t GetTimestamp(Int_t npar, TTimeStamp& tm) final;
104
105 ClassDefOverride(TPgSQLStatement, 0); // SQL statement class for PgSQL DB
106};
107
108#endif
int Int_t
Definition: RtypesCore.h:43
unsigned int UInt_t
Definition: RtypesCore.h:44
const Bool_t kFALSE
Definition: RtypesCore.h:90
long Long_t
Definition: RtypesCore.h:52
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
long long Long64_t
Definition: RtypesCore.h:71
unsigned long long ULong64_t
Definition: RtypesCore.h:72
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
PgSQL_Stmt_t * fStmt
Bool_t SetDatime(Int_t npar, Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec) final
Set parameter value as date & time.
void ConvertTimeToUTC(const TString &PQvalue, Int_t &year, Int_t &month, Int_t &day, Int_t &hour, Int_t &min, Int_t &sec)
void SetBuffersNumber(Int_t n)
Allocate buffers for statement parameters/ result fields.
Int_t fNumResultRows
data type (OID)
UInt_t GetUInt(Int_t npar) final
Return field value as unsigned integer.
Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final
Set parameter value as time.
long double ConvertToNumeric(Int_t npar)
Convert field to numeric value.
Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec) final
Return field value as time.
Bool_t SetLargeObject(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000) final
Set parameter value to large object and immediately insert the large object into DB.
Bool_t IsResultSetMode() const
TPgSQLStatement(PgSQL_Stmt_t *stmt, Bool_t errout=kTRUE)
Normal constructor.
int * fParamLengths
number of iteration
Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day) final
Return field value as date.
Int_t GetInt(Int_t npar) final
Return field value as integer.
Int_t GetNumParameters() final
Return number of statement parameters.
const char * GetString(Int_t npar) final
Return field value as string.
Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final
Set parameter value as date.
Bool_t GetLargeObject(Int_t npar, void *&mem, Long_t &size) final
Return large object whose oid is in the given field.
Bool_t SetInt(Int_t npar, Int_t value) final
Set parameter value as integer.
ULong64_t GetULong64(Int_t npar) final
Return field value as unsigned 64-bit integer.
Long_t GetLong(Int_t npar) final
Return field value as long integer.
Bool_t SetSQLParamType(Int_t npar, Bool_t isbinary=kFALSE, Int_t param_len=0, Int_t maxsize=0)
Set parameter type to be used as buffer.
Int_t fIterationCount
1 - setting parameters, 2 - retrieving results
Int_t fNumBuffers
executed statement
Int_t fWorkingMode
array of column names
Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size) final
Return field value as binary array.
Int_t GetBufferLength() const final
Bool_t IsSetParsMode() const
Bool_t IsNull(Int_t npar) final
Checks if field value is null.
Int_t GetNumFields() final
Return number of fields in result set.
Double_t GetDouble(Int_t npar) final
Return field value as double.
Bool_t SetDouble(Int_t npar, Double_t value) final
Set parameter value as double.
Bool_t NextResultRow() final
Shift cursor to nect row in result set.
Long64_t GetLong64(Int_t npar) final
Return field value as 64-bit integer.
Bool_t GetDatime(Int_t npar, Int_t &year, Int_t &month, Int_t &day, Int_t &hour, Int_t &min, Int_t &sec) final
Return field value as date & time.
ClassDefOverride(TPgSQLStatement, 0)
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) final
Set parameter value as timestamp.
Int_t GetNumAffectedRows() final
Return number of affected rows after statement is processed.
Bool_t SetLong(Int_t npar, Long_t value) final
Set parameter value as long integer.
Bool_t StoreResult() final
Store result of statement processing to access them via GetInt(), GetDouble() and so on methods.
Bool_t SetUInt(Int_t npar, UInt_t value) final
Set parameter value as unsigned integer.
const char * GetFieldName(Int_t nfield) final
Returns field name in result set.
Bool_t SetNull(Int_t npar) final
Set NULL as parameter value.
const char * ConvertToString(Int_t npar)
Convert field value to string.
Bool_t SetULong64(Int_t npar, ULong64_t value) final
Set parameter value as unsigned 64-bit integer.
char ** fBind
number of statement parameters
void FreeBuffers()
Release all buffers, used by statement.
Bool_t SetLong64(Int_t npar, Long64_t value) final
Set parameter value as 64-bit integer.
virtual ~TPgSQLStatement()
Destructor.
Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256) final
Set parameter value as string.
Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000) final
Set parameter value as binary data.
Bool_t Process() final
Process statement.
int * fParamFormats
length of column
char ** fFieldName
array of data for input
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 &) final
Return field value as time stamp.
Bool_t NextIteration() final
Increment iteration counter for statement, where parameter can be set.
void Close(Option_t *="") final
Close statement.
Basic string class.
Definition: TString.h:131
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition: TTimeStamp.h:71
const Int_t n
Definition: legend1.C:16
PGconn * fConn
PGresult * fRes