Logo ROOT   6.07/09
Reference Guide
TODBCStatement.h
Go to the documentation of this file.
1 // @(#)root/odbc:$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_TODBCStatement
13 #define ROOT_TODBCStatement
14 
15 #ifndef ROOT_TSQLStatement
16 #include "TSQLStatement.h"
17 #endif
18 
19 
20 #ifdef __CLING__
21 typedef void * SQLHSTMT;
22 typedef UShort_t SQLUSMALLINT;
23 typedef UInt_t SQLUINTEGER;
24 typedef Short_t SQLSMALLINT;
25 typedef Short_t SQLRETURN;
26 #else
27 #ifdef WIN32
28 #include "windows.h"
29 #endif
30 #include <sql.h>
31 #endif
32 
33 class TODBCStatement : public TSQLStatement {
34 
35 protected:
36  #ifdef __CLING__
37  struct ODBCBufferRec_t;
38  #else
39  struct ODBCBufferRec_t {
43  void *fBbuffer;
45  SQLLEN *fBlenarray;
46  char *fBstrbuffer;
47  char *fBnamebuffer;
48  };
49  #endif
50 
51 protected:
52  SQLHSTMT fHstmt;
56  Int_t fBufferLength; // number of entries for each parameter/column
57  Int_t fBufferCounter; // used to indicate position in buffers
58  SQLUSMALLINT *fStatusBuffer;
59  Int_t fWorkingMode; // 1 - setting parameters, 2 - reading results, 0 - unknown
60  SQLUINTEGER fNumParsProcessed; // contains number of parameters, affected by last operation
61  SQLUINTEGER fNumRowsFetched; // indicates number of fetched rows
62  ULong64_t fLastResultRow; // stores values of row number after last fetch operation
63 
64  void *GetParAddr(Int_t npar, Int_t roottype = 0, Int_t length = 0);
65  long double ConvertToNumeric(Int_t npar);
66  const char *ConvertToString(Int_t npar);
67 
68  Bool_t BindColumn(Int_t ncol, SQLSMALLINT sqltype, SQLUINTEGER size);
69  Bool_t BindParam(Int_t n, Int_t type, Int_t size = 1024);
70 
71  Bool_t ExtractErrors(SQLRETURN retcode, const char* method);
72 
73  void SetNumBuffers(Int_t isize, Int_t ilen);
74  void FreeBuffers();
75 
76  Bool_t IsParSettMode() const { return fWorkingMode==1; }
77  Bool_t IsResultSet() const { return fWorkingMode==2; }
78 
79 public:
80  TODBCStatement(SQLHSTMT stmt, Int_t rowarrsize, Bool_t errout = kTRUE);
81  virtual ~TODBCStatement();
82 
83  virtual void Close(Option_t * = "");
84 
85  virtual Int_t GetBufferLength() const { return fBufferLength; }
86  virtual Int_t GetNumParameters();
87 
88  virtual Bool_t SetNull(Int_t npar);
89  virtual Bool_t SetInt(Int_t npar, Int_t value);
90  virtual Bool_t SetUInt(Int_t npar, UInt_t value);
91  virtual Bool_t SetLong(Int_t npar, Long_t value);
92  virtual Bool_t SetLong64(Int_t npar, Long64_t value);
93  virtual Bool_t SetULong64(Int_t npar, ULong64_t value);
94  virtual Bool_t SetDouble(Int_t npar, Double_t value);
95  virtual Bool_t SetString(Int_t npar, const char* value, Int_t maxsize = 256);
96  virtual Bool_t SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
97  virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day);
98  virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec);
99  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);
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);
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  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&);
125 
126  ClassDef(TODBCStatement, 0); //ODBC implementation of TSQLStatement
127 };
128 
129 #endif
virtual const char * GetFieldName(Int_t nfield)
return field name
SQLUINTEGER fNumRowsFetched
Bool_t IsParSettMode() const
Int_t fBufferPreferredSize
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
long long Long64_t
Definition: RtypesCore.h:69
virtual const char * GetString(Int_t npar)
get parameter as string
virtual Int_t GetBufferLength() const
const char Option_t
Definition: RtypesCore.h:62
virtual Bool_t NextResultRow()
next result row
unsigned short UShort_t
Definition: RtypesCore.h:36
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 Bool_t GetDate(Int_t npar, Int_t &year, Int_t &month, Int_t &day)
return field value as date
virtual Bool_t SetInt(Int_t npar, Int_t value)
set parameter as Int_t
virtual Bool_t SetDate(Int_t npar, Int_t year, Int_t month, Int_t day)
set parameter value as date
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual UInt_t GetUInt(Int_t npar)
get parameter as unsigned integer
SQLUINTEGER fNumParsProcessed
virtual Bool_t SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec)
set parameter value as time
Bool_t IsResultSet() const
virtual Bool_t SetLong(Int_t npar, Long_t value)
set parameter as Long_t
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual Int_t GetInt(Int_t npar)
get parameter as integer
virtual ~TODBCStatement()
destructor
const int maxsize
Bool_t BindParam(Int_t n, Int_t type, Int_t size=1024)
Bind query parameter with buffer. Creates buffer of appropriate type.
virtual Int_t GetNumAffectedRows()
get number of affected rows
Bool_t ExtractErrors(SQLRETURN retcode, const char *method)
Extract errors, produced by last ODBC function call.
void * GetParAddr(Int_t npar, Int_t roottype=0, Int_t length=0)
Get parameter address.
virtual Double_t GetDouble(Int_t npar)
get parameter as Double_t
TODBCStatement(SQLHSTMT stmt, Int_t rowarrsize, Bool_t errout=kTRUE)
constructor
const char * ConvertToString(Int_t npar)
convert to string
virtual Bool_t SetString(Int_t npar, const char *value, Int_t maxsize=256)
set parameter as string
Bool_t BindColumn(Int_t ncol, SQLSMALLINT sqltype, SQLUINTEGER size)
Bind result column to buffer. Allocate buffer of appropriate type.
long double ConvertToNumeric(Int_t npar)
convert to numeric type
virtual Bool_t Process()
process statement
ODBCBufferRec_t * fBuffer
unsigned int UInt_t
Definition: RtypesCore.h:42
short Short_t
Definition: RtypesCore.h:35
virtual Int_t GetNumParameters()
return number of parameters
virtual Bool_t SetLong64(Int_t npar, Long64_t value)
set parameter as Long64_t
virtual ULong64_t GetULong64(Int_t npar)
get parameter as ULong64_t
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
long Long_t
Definition: RtypesCore.h:50
virtual Bool_t IsNull(Int_t)
Verifies if field value is NULL.
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
unsigned long long ULong64_t
Definition: RtypesCore.h:70
virtual Bool_t SetNull(Int_t npar)
Set NULL as parameter value If NULL should be set for statement parameter during first iteration...
virtual Bool_t GetBinary(Int_t npar, void *&mem, Long_t &size)
return parameter as binary data
virtual Bool_t GetTime(Int_t npar, Int_t &hour, Int_t &min, Int_t &sec)
return field value as time
virtual Bool_t SetDouble(Int_t npar, Double_t value)
set parameter as Double_t
void FreeBuffers()
Free allocated buffers.
ULong64_t fLastResultRow
virtual Bool_t SetBinary(Int_t npar, void *mem, Long_t size, Long_t maxsize=0x1000)
set parameter value as binary data
virtual Bool_t SetULong64(Int_t npar, ULong64_t value)
set parameter as ULong64_t
virtual Long64_t GetLong64(Int_t npar)
get parameter as Long64_t
virtual void Close(Option_t *="")
Close statement.
virtual Bool_t SetUInt(Int_t npar, UInt_t value)
set parameter as UInt_t
SQLUSMALLINT * fStatusBuffer
const Bool_t kTRUE
Definition: Rtypes.h:91
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
void SetNumBuffers(Int_t isize, Int_t ilen)
set number of buffers
const Int_t n
Definition: legend1.C:16
virtual Bool_t NextIteration()
run next iteration
virtual Int_t GetNumFields()
return number of fields
virtual Bool_t StoreResult()
Store result of statement processing.
virtual Long_t GetLong(Int_t npar)
get parameter as Long_t