TMySQLStatement.h

Go to the documentation of this file.
00001 // @(#)root/mysql:$Id: TMySQLStatement.h 29976 2009-08-31 13:34:53Z rdm $
00002 // Author: Sergey Linev   6/02/2006
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TMySQLStatement
00013 #define ROOT_TMySQLStatement
00014 
00015 #ifndef ROOT_TSQLStatement
00016 #include "TSQLStatement.h"
00017 #endif
00018 
00019 #if !defined(__CINT__)
00020 #ifdef R__WIN32
00021 #include <winsock2.h>
00022 #else
00023 #include <sys/time.h>
00024 #endif
00025 #include <mysql.h>
00026 
00027 #if MYSQL_VERSION_ID < 40100
00028 typedef struct { int dummy; } MYSQL_STMT;
00029 typedef struct { int dummy; } MYSQL_BIND;
00030 #endif
00031 
00032 #else
00033 struct MYSQL_STMT;
00034 struct MYSQL_BIND;
00035 typedef char my_bool;
00036 #endif
00037 
00038 class TMySQLStatement : public TSQLStatement {
00039 
00040 protected:
00041 
00042    struct TParamData {
00043       void*         fMem;        //! allocated data buffer
00044       Int_t         fSize;       //! size of allocated data
00045       Int_t         fSqlType;     //! sqltype of parameter
00046       Bool_t        fSign;        //! signed - not signed type
00047       ULong_t       fResLength;  //! length argument
00048       my_bool       fResNull;    //! indicates if argument is null
00049       char*         fStrBuffer;  //! special buffer to be used for string conversions
00050       char*         fFieldName;  //! buffer for field name
00051    };
00052 
00053    MYSQL_STMT           *fStmt;          //! executed statement
00054    Int_t                 fNumBuffers; //! number of statement parameters
00055    MYSQL_BIND           *fBind;          //! array of bind data
00056    TParamData           *fBuffer;         //! parameter definition structures
00057    Int_t                 fWorkingMode;   //! 1 - setting parameters, 2 - retrieving results
00058    Int_t                 fIterationCount;//! number of iteration
00059    Bool_t                fNeedParBind;   //! indicates when parameters bind should be called
00060 
00061    Bool_t      IsSetParsMode() const { return fWorkingMode==1; }
00062    Bool_t      IsResultSetMode() const { return fWorkingMode==2; }
00063 
00064    Bool_t      SetSQLParamType(Int_t npar, int sqltype, bool sig, unsigned long sqlsize = 0);
00065 
00066    long double ConvertToNumeric(Int_t npar);
00067    const char *ConvertToString(Int_t npar);
00068 
00069    void        FreeBuffers();
00070    void        SetBuffersNumber(Int_t n);
00071 
00072    void       *BeforeSet(const char* method, Int_t npar, Int_t sqltype, Bool_t sig = kTRUE, unsigned long size = 0);
00073    
00074    static ULong64_t fgAllocSizeLimit;
00075 
00076 public:
00077    TMySQLStatement(MYSQL_STMT* stmt, Bool_t errout = kTRUE);
00078    virtual ~TMySQLStatement();
00079    
00080    static unsigned long GetAllocSizeLimit() { return fgAllocSizeLimit; }
00081    static void SetAllocSizeLimit(unsigned long sz) { fgAllocSizeLimit = sz; }
00082 
00083    virtual void        Close(Option_t * = "");
00084 
00085    virtual Int_t       GetBufferLength() const { return 1; }
00086    virtual Int_t       GetNumParameters();
00087 
00088    virtual Bool_t      SetNull(Int_t npar);
00089    virtual Bool_t      SetInt(Int_t npar, Int_t value);
00090    virtual Bool_t      SetUInt(Int_t npar, UInt_t value);
00091    virtual Bool_t      SetLong(Int_t npar, Long_t value);
00092    virtual Bool_t      SetLong64(Int_t npar, Long64_t value);
00093    virtual Bool_t      SetULong64(Int_t npar, ULong64_t value);
00094    virtual Bool_t      SetDouble(Int_t npar, Double_t value);
00095    virtual Bool_t      SetString(Int_t npar, const char* value, Int_t maxsize = 256);
00096    virtual Bool_t      SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
00097    virtual Bool_t      SetDate(Int_t npar, Int_t year, Int_t month, Int_t day);
00098    virtual Bool_t      SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec);
00099    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);
00100    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);
00101 
00102    virtual Bool_t      NextIteration();
00103 
00104    virtual Bool_t      Process();
00105    virtual Int_t       GetNumAffectedRows();
00106 
00107    virtual Bool_t      StoreResult();
00108    virtual Int_t       GetNumFields();
00109    virtual const char *GetFieldName(Int_t nfield);
00110    virtual Bool_t      NextResultRow();
00111 
00112    virtual Bool_t      IsNull(Int_t npar);
00113    virtual Int_t       GetInt(Int_t npar);
00114    virtual UInt_t      GetUInt(Int_t npar);
00115    virtual Long_t      GetLong(Int_t npar);
00116    virtual Long64_t    GetLong64(Int_t npar);
00117    virtual ULong64_t   GetULong64(Int_t npar);
00118    virtual Double_t    GetDouble(Int_t npar);
00119    virtual const char *GetString(Int_t npar);
00120    virtual Bool_t      GetBinary(Int_t npar, void* &mem, Long_t& size);
00121    virtual Bool_t      GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day);
00122    virtual Bool_t      GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec);
00123    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);
00124    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&);
00125 
00126    ClassDef(TMySQLStatement, 0);  // SQL statement class for MySQL DB
00127 };
00128 
00129 #endif

Generated on Tue Jul 5 15:14:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1