Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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#include "TSQLStatement.h"
16
17
18#include <mysql.h>
19
20#if MYSQL_VERSION_ID < 40100
21typedef struct { int dummy; } MYSQL_STMT;
22typedef struct { int dummy; } MYSQL_BIND;
23#endif
24
25// MariaDB is fork of MySQL and still include definition of my_bool
26// MariaDB major version is 10, therefore it confuses version ID here
27#ifndef MARIADB_VERSION_ID
28#if MYSQL_VERSION_ID > 80000 && MYSQL_VERSION_ID < 100000
29typedef bool my_bool;
30#endif
31#endif
32
34
35protected:
36
37 struct TParamData {
38 void *fMem{nullptr}; //! allocated data buffer
39 Int_t fSize{0}; //! size of allocated data
40 Int_t fSqlType{0}; //! sqltype of parameter
41 Bool_t fSign{kFALSE}; //! signed - not signed type
42 ULong_t fResLength{0}; //! length argument
43 my_bool fResNull{false}; //! indicates if argument is null
44 std::string fStrBuffer; //! special buffer to be used for string conversions
45 std::string fFieldName; //! buffer for field name
46 };
47
48 MYSQL_STMT *fStmt{nullptr}; //! executed statement
49 Int_t fNumBuffers{0}; //! number of statement parameters
50 MYSQL_BIND *fBind{nullptr}; //! array of bind data
51 TParamData *fBuffer{nullptr}; //! parameter definition structures
52 Int_t fWorkingMode{0}; //! 1 - setting parameters, 2 - retrieving results
53 Int_t fIterationCount{-1}; //! number of iteration
54 Bool_t fNeedParBind{kFALSE}; //! indicates when parameters bind should be called
55
56 Bool_t IsSetParsMode() const { return fWorkingMode==1; }
57 Bool_t IsResultSetMode() const { return fWorkingMode==2; }
58
59 Bool_t SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t sqlsize = 0);
60
61 long double ConvertToNumeric(Int_t npar);
62 const char *ConvertToString(Int_t npar);
63
64 void FreeBuffers();
66
67 void *BeforeSet(const char* method, Int_t npar, Int_t sqltype, Bool_t sig = kTRUE, ULong_t size = 0);
68
70
71private:
74
75public:
76 TMySQLStatement(MYSQL_STMT* stmt, Bool_t errout = kTRUE);
77 virtual ~TMySQLStatement();
78
80 static void SetAllocSizeLimit(ULong_t sz);
81
82 void Close(Option_t * = "") final;
83
84 Int_t GetBufferLength() const final { return 1; }
85 Int_t GetNumParameters() final;
86
87 Bool_t SetNull(Int_t npar) final;
88 Bool_t SetInt(Int_t npar, Int_t value) final;
89 Bool_t SetUInt(Int_t npar, UInt_t value) final;
90 Bool_t SetLong(Int_t npar, Long_t value) final;
91 Bool_t SetLong64(Int_t npar, Long64_t value) final;
92 Bool_t SetULong64(Int_t npar, ULong64_t value) final;
93 Bool_t SetDouble(Int_t npar, Double_t value) final;
94 Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256) final;
95 Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000) final;
96 Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final;
97 Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final;
98 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;
100 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;
101
102 Bool_t NextIteration() final;
103
104 Bool_t Process() final;
106
107 Bool_t StoreResult() final;
108 Int_t GetNumFields() final;
109 const char *GetFieldName(Int_t nfield) final;
110 Bool_t NextResultRow() final;
111
112 Bool_t IsNull(Int_t npar) final;
113 Int_t GetInt(Int_t npar) final;
114 UInt_t GetUInt(Int_t npar) final;
115 Long_t GetLong(Int_t npar) final;
116 Long64_t GetLong64(Int_t npar) final;
117 ULong64_t GetULong64(Int_t npar) final;
118 Double_t GetDouble(Int_t npar) final;
119 const char *GetString(Int_t npar) final;
120 Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size) final;
121 Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) final;
122 Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec) final;
123 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;
125 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;
126
127 ClassDefOverride(TMySQLStatement, 0); // SQL statement class for MySQL DB
128};
129
130#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
bool Bool_t
Definition RtypesCore.h:63
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:80
unsigned long long ULong64_t
Definition RtypesCore.h:81
const Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:329
static ULong64_t fgAllocSizeLimit
void SetBuffersNumber(Int_t n)
Allocate buffers for statement parameters/ result fields.
Bool_t SetInt(Int_t npar, Int_t value) final
Set parameter value as integer.
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.
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.
UInt_t GetUInt(Int_t npar) final
Return field value as unsigned integer.
Bool_t NextIteration() final
Increment iteration counter for statement, where parameter can be set.
Double_t GetDouble(Int_t npar) final
Return field value as double.
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.
Int_t GetBufferLength() const final
Bool_t IsSetParsMode() const
indicates when parameters bind should be called
const char * ConvertToString(Int_t npar)
Convert field value to string.
Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day) final
Return field value as date.
Bool_t SetDouble(Int_t npar, Double_t value) final
Set parameter value as double.
MYSQL_STMT * fStmt
Bool_t SetUInt(Int_t npar, UInt_t value) final
Set parameter value as unsigned integer.
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.
Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec) final
Return field value as time.
Bool_t Process() final
Process statement.
Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000) final
Set parameter value as binary data.
TMySQLStatement & operator=(const TMySQLStatement &)=delete
static void SetAllocSizeLimit(ULong_t sz)
Set limit for maximal allocated memory for single parameter.
void Close(Option_t *="") final
Close statement.
Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec) final
Set parameter value as time.
Int_t fWorkingMode
parameter definition structures
Int_t GetNumParameters() final
Return number of statement parameters.
void FreeBuffers()
Release all buffers, used by statement.
Bool_t IsNull(Int_t npar) final
Checks if field value is null.
Int_t fIterationCount
1 - setting parameters, 2 - retrieving results
ULong64_t GetULong64(Int_t npar) final
Return field value as unsigned 64-bit integer.
Long64_t GetLong64(Int_t npar) final
Return field value as 64-bit integer.
static ULong_t GetAllocSizeLimit()
Return limit for maximal allocated memory for single parameter.
Bool_t IsResultSetMode() const
virtual ~TMySQLStatement()
Destructor.
const char * GetFieldName(Int_t nfield) final
Returns field name in result set.
Bool_t SetSQLParamType(Int_t npar, int sqltype, Bool_t sig, ULong_t sqlsize=0)
Set parameter type to be used as buffer.
Int_t GetInt(Int_t npar) final
Return field value as integer.
TParamData * fBuffer
array of bind data
Int_t GetNumFields() final
Return number of fields in result set.
Bool_t fNeedParBind
number of iteration
Bool_t SetLong(Int_t npar, Long_t value) final
Set parameter value as long integer.
Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day) final
Set parameter value as date.
Bool_t StoreResult() final
Store result of statement processing to access them via GetInt(), GetDouble() and so on methods.
Int_t fNumBuffers
executed statement
Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256) final
Set parameter value as string.
Long_t GetLong(Int_t npar) final
Return field value as long integer.
TMySQLStatement(const TMySQLStatement &)=delete
Bool_t SetLong64(Int_t npar, Long64_t value) final
Set parameter value as 64-bit integer.
Int_t GetNumAffectedRows() final
Return number of affected rows after statement is processed.
Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size) final
Return field value as binary array.
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.
long double ConvertToNumeric(Int_t npar)
Convert field to numeric value.
const char * GetString(Int_t npar) final
Return field value as string.
Bool_t SetNull(Int_t npar) final
Set NULL as parameter value.
Bool_t SetULong64(Int_t npar, ULong64_t value) final
Set parameter value as unsigned 64-bit integer.
Bool_t NextResultRow() final
Shift cursor to nect row in result set.
MYSQL_BIND * fBind
number of statement parameters
const Int_t n
Definition legend1.C:16
Bool_t fSign
sqltype of parameter
std::string fFieldName
special buffer to be used for string conversions
ULong_t fResLength
signed - not signed type
Int_t fSize
allocated data buffer
my_bool fResNull
length argument
std::string fStrBuffer
indicates if argument is null
Int_t fSqlType
size of allocated data