ROOT  6.06/09
Reference Guide
TMySQLStatement.h
Go to the documentation of this file.
1 // @(#)root/mysql:$Id$
2 // Author: Sergey Linev 6/02/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, 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_TMySQLStatement
13 #define ROOT_TMySQLStatement
14 
15 #ifndef ROOT_TSQLStatement
16 #include "TSQLStatement.h"
17 #endif
18 
19 
20 #include <mysql.h>
21 
22 #if MYSQL_VERSION_ID < 40100
23 typedef struct { int dummy; } MYSQL_STMT;
24 typedef struct { int dummy; } MYSQL_BIND;
25 #endif
26 
28 
29 protected:
30 
31  struct TParamData {
32  void* fMem; //! allocated data buffer
33  Int_t fSize; //! size of allocated data
34  Int_t fSqlType; //! sqltype of parameter
35  Bool_t fSign; //! signed - not signed type
36  ULong_t fResLength; //! length argument
37  my_bool fResNull; //! indicates if argument is null
38  char* fStrBuffer; //! special buffer to be used for string conversions
39  char* fFieldName; //! buffer for field name
40  };
41 
42  MYSQL_STMT *fStmt; //! executed statement
43  Int_t fNumBuffers; //! number of statement parameters
44  MYSQL_BIND *fBind; //! array of bind data
45  TParamData *fBuffer; //! parameter definition structures
46  Int_t fWorkingMode; //! 1 - setting parameters, 2 - retrieving results
47  Int_t fIterationCount;//! number of iteration
48  Bool_t fNeedParBind; //! indicates when parameters bind should be called
49 
50  Bool_t IsSetParsMode() const { return fWorkingMode==1; }
51  Bool_t IsResultSetMode() const { return fWorkingMode==2; }
52 
53  Bool_t SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t sqlsize = 0);
54 
55  long double ConvertToNumeric(Int_t npar);
56  const char *ConvertToString(Int_t npar);
57 
58  void FreeBuffers();
59  void SetBuffersNumber(Int_t n);
60 
61  void *BeforeSet(const char* method, Int_t npar, Int_t sqltype, Bool_t sig = kTRUE, ULong_t size = 0);
62 
64 
65 private:
66  TMySQLStatement(const TMySQLStatement&); // Not implemented.
67  TMySQLStatement &operator=(const TMySQLStatement&); // Not implemented.
68 
69 public:
70  TMySQLStatement(MYSQL_STMT* stmt, Bool_t errout = kTRUE);
71  virtual ~TMySQLStatement();
72 
74  static void SetAllocSizeLimit(ULong_t sz) { fgAllocSizeLimit = sz; }
75 
76  virtual void Close(Option_t * = "");
77 
78  virtual Int_t GetBufferLength() const { return 1; }
79  virtual Int_t GetNumParameters();
80 
81  virtual Bool_t SetNull(Int_t npar);
82  virtual Bool_t SetInt(Int_t npar, Int_t value);
83  virtual Bool_t SetUInt(Int_t npar, UInt_t value);
84  virtual Bool_t SetLong(Int_t npar, Long_t value);
85  virtual Bool_t SetLong64(Int_t npar, Long64_t value);
86  virtual Bool_t SetULong64(Int_t npar, ULong64_t value);
87  virtual Bool_t SetDouble(Int_t npar, Double_t value);
88  virtual Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256);
89  virtual Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
90  virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day);
91  virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec);
92  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);
93  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);
94 
95  virtual Bool_t NextIteration();
96 
97  virtual Bool_t Process();
98  virtual Int_t GetNumAffectedRows();
99 
100  virtual Bool_t StoreResult();
101  virtual Int_t GetNumFields();
102  virtual const char *GetFieldName(Int_t nfield);
103  virtual Bool_t NextResultRow();
104 
105  virtual Bool_t IsNull(Int_t npar);
106  virtual Int_t GetInt(Int_t npar);
107  virtual UInt_t GetUInt(Int_t npar);
108  virtual Long_t GetLong(Int_t npar);
109  virtual Long64_t GetLong64(Int_t npar);
110  virtual ULong64_t GetULong64(Int_t npar);
111  virtual Double_t GetDouble(Int_t npar);
112  virtual const char *GetString(Int_t npar);
113  virtual Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size);
114  virtual Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day);
115  virtual Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec);
116  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);
117  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&);
118 
119  ClassDef(TMySQLStatement, 0); // SQL statement class for MySQL DB
120 };
121 
122 #endif
virtual Bool_t SetLong64(Int_t npar, Long64_t value)
Set parameter value as 64-bit integer.
virtual Int_t GetNumParameters()
Return number of statement parameters.
virtual Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000)
Set parameter value as binary data.
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
const char * ConvertToString(Int_t npar)
Convert field value to string.
const char Option_t
Definition: RtypesCore.h:62
virtual ULong64_t GetULong64(Int_t npar)
Return field value as unsigned 64-bit integer.
virtual Int_t GetNumAffectedRows()
Return number of affected rows after statement is processed.
virtual Bool_t SetNull(Int_t npar)
Set NULL as parameter value.
virtual Bool_t SetLong(Int_t npar, Long_t value)
Set parameter value as long integer.
Bool_t IsSetParsMode() const
indicates when parameters bind should be called
virtual Bool_t NextResultRow()
Shift cursor to nect row in result set.
virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec)
Set parameter value as time.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
char * fStrBuffer
indicates if argument is null
MYSQL_STMT * fStmt
void FreeBuffers()
Release all buffers, used by statement.
virtual Bool_t SetULong64(Int_t npar, ULong64_t value)
Set parameter value as unsigned 64-bit integer.
Bool_t fNeedParBind
number of iteration
ClassDef(TMySQLStatement, 0)
virtual void Close(Option_t *="")
Close 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.
const int maxsize
void SetBuffersNumber(Int_t n)
Allocate buffers for statement parameters/ result fields.
virtual Int_t GetInt(Int_t npar)
Return field value as integer.
virtual Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day)
Return field value as date.
static void SetAllocSizeLimit(ULong_t sz)
Int_t fIterationCount
1 - setting parameters, 2 - retrieving results
virtual Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256)
Set parameter value as string.
virtual Int_t GetNumFields()
Return number of fields in result set.
virtual Bool_t SetDouble(Int_t npar, Double_t value)
Set parameter value as double.
my_bool fResNull
length argument
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.
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t fSize
allocated data buffer
virtual Double_t GetDouble(Int_t npar)
Return field value as double.
TMySQLStatement & operator=(const TMySQLStatement &)
MYSQL_BIND * fBind
number of statement parameters
Int_t fNumBuffers
executed statement
TMySQLStatement(const TMySQLStatement &)
virtual Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec)
Return field value as time.
Bool_t IsResultSetMode() const
long Long_t
Definition: RtypesCore.h:50
Bool_t fSign
sqltype of parameter
long double ConvertToNumeric(Int_t npar)
Convert field to numeric value.
double Double_t
Definition: RtypesCore.h:55
virtual Bool_t SetUInt(Int_t npar, UInt_t value)
Set parameter value as unsigned integer.
unsigned long long ULong64_t
Definition: RtypesCore.h:70
virtual Bool_t SetInt(Int_t npar, Int_t value)
Set parameter value as integer.
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual Bool_t Process()
Process statement.
virtual Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size)
Return field value as binary array.
virtual const char * GetFieldName(Int_t nfield)
Returns field name in result set.
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 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.
virtual Long_t GetLong(Int_t npar)
Return field value as long integer.
virtual Int_t GetBufferLength() const
Int_t fWorkingMode
parameter definition structures
TParamData * fBuffer
array of bind data
virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day)
Set parameter value as date.
virtual const char * GetString(Int_t npar)
Return field value as string.
virtual Bool_t IsNull(Int_t npar)
Checks if field value is null.
char * fFieldName
special buffer to be used for string conversions
virtual UInt_t GetUInt(Int_t npar)
Return field value as unsigned integer.
virtual Bool_t NextIteration()
Increment iteration counter for statement, where parameter can be set.
const Bool_t kTRUE
Definition: Rtypes.h:91
static ULong64_t fgAllocSizeLimit
float value
Definition: math.cpp:443
ULong_t fResLength
signed - not signed type
void * BeforeSet(const char *method, Int_t npar, Int_t sqltype, Bool_t sig=kTRUE, ULong_t size=0)
Check boundary condition before setting value of parameter.
const Int_t n
Definition: legend1.C:16
Int_t fSqlType
size of allocated data
Bool_t SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t 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...
static ULong_t GetAllocSizeLimit()
virtual ~TMySQLStatement()
Destructor.