Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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
21 typedef struct { int dummy; } MYSQL_STMT;
22 typedef 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
29 typedef bool my_bool;
30 #endif
31 #endif
32 
33 class TMySQLStatement : public TSQLStatement {
34 
35 protected:
36 
37  struct TParamData {
38  void* fMem; //! allocated data buffer
39  Int_t fSize; //! size of allocated data
40  Int_t fSqlType; //! sqltype of parameter
41  Bool_t fSign; //! signed - not signed type
42  ULong_t fResLength; //! length argument
43  my_bool fResNull; //! indicates if argument is null
44  char* fStrBuffer; //! special buffer to be used for string conversions
45  char* fFieldName; //! buffer for field name
46  };
47 
48  MYSQL_STMT *fStmt; //! executed statement
49  Int_t fNumBuffers; //! number of statement parameters
50  MYSQL_BIND *fBind; //! array of bind data
51  TParamData *fBuffer; //! parameter definition structures
52  Int_t fWorkingMode; //! 1 - setting parameters, 2 - retrieving results
53  Int_t fIterationCount;//! number of iteration
54  Bool_t fNeedParBind; //! 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();
65  void SetBuffersNumber(Int_t n);
66 
67  void *BeforeSet(const char* method, Int_t npar, Int_t sqltype, Bool_t sig = kTRUE, ULong_t size = 0);
68 
69  static ULong64_t fgAllocSizeLimit;
70 
71 private:
72  TMySQLStatement(const TMySQLStatement&); // Not implemented.
73  TMySQLStatement &operator=(const TMySQLStatement&); // Not implemented.
74 
75 public:
76  TMySQLStatement(MYSQL_STMT* stmt, Bool_t errout = kTRUE);
77  virtual ~TMySQLStatement();
78 
79  static ULong_t GetAllocSizeLimit() { return fgAllocSizeLimit; }
80  static void SetAllocSizeLimit(ULong_t sz) { fgAllocSizeLimit = sz; }
81 
82  virtual void Close(Option_t * = "");
83 
84  virtual Int_t GetBufferLength() const { return 1; }
85  virtual Int_t GetNumParameters();
86 
87  virtual Bool_t SetNull(Int_t npar);
88  virtual Bool_t SetInt(Int_t npar, Int_t value);
89  virtual Bool_t SetUInt(Int_t npar, UInt_t value);
90  virtual Bool_t SetLong(Int_t npar, Long_t value);
91  virtual Bool_t SetLong64(Int_t npar, Long64_t value);
92  virtual Bool_t SetULong64(Int_t npar, ULong64_t value);
93  virtual Bool_t SetDouble(Int_t npar, Double_t value);
94  virtual Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256);
95  virtual Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
96  virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day);
97  virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec);
98  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);
99  using TSQLStatement::SetTimestamp;
100  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);
101 
102  virtual Bool_t NextIteration();
103 
104  virtual Bool_t Process();
105  virtual Int_t GetNumAffectedRows();
106 
107  virtual Bool_t StoreResult();
108  virtual Int_t GetNumFields();
109  virtual const char *GetFieldName(Int_t nfield);
110  virtual Bool_t NextResultRow();
111 
112  virtual Bool_t IsNull(Int_t npar);
113  virtual Int_t GetInt(Int_t npar);
114  virtual UInt_t GetUInt(Int_t npar);
115  virtual Long_t GetLong(Int_t npar);
116  virtual Long64_t GetLong64(Int_t npar);
117  virtual ULong64_t GetULong64(Int_t npar);
118  virtual Double_t GetDouble(Int_t npar);
119  virtual const char *GetString(Int_t npar);
120  virtual Bool_t GetBinary(Int_t npar, void* &mem, Long_t& size);
121  virtual Bool_t GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day);
122  virtual Bool_t GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec);
123  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);
124  using TSQLStatement::GetTimestamp;
125  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&);
126 
127  ClassDef(TMySQLStatement, 0); // SQL statement class for MySQL DB
128 };
129 
130 #endif