TPgSQLStatement.h

Go to the documentation of this file.
00001 // @(#)root/mysql:$Id: TPgSQLStatement.h 29976 2009-08-31 13:34:53Z rdm $
00002 // Author: Dennis Box (dbox@fnal.gov)  3/12/2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, 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_TPgSQLStatement
00013 #define ROOT_TPgSQLStatement
00014 
00015 #ifndef ROOT_TSQLStatement
00016 #include "TSQLStatement.h"
00017 #endif
00018 
00019 #if !defined(__CINT__)
00020 
00021 #ifdef R__WIN32
00022 #include <winsock2.h>
00023 #else
00024 #include <sys/time.h>
00025 #endif
00026 #include <libpq-fe.h>
00027 #include <pg_config.h> // to get PG_VERSION_NUM
00028 
00029 #define pgsql_success(x) (((x) == PGRES_EMPTY_QUERY) \
00030                         || ((x) == PGRES_COMMAND_OK) \
00031                         || ((x) == PGRES_TUPLES_OK))
00032 
00033 #else
00034 struct PGconn;
00035 struct PGresult;
00036 #endif
00037 
00038 
00039 
00040 struct PgSQL_Stmt_t {
00041    PGconn   *fConn;
00042    PGresult *fRes;
00043 };
00044 
00045 
00046 class TPgSQLStatement : public TSQLStatement {
00047 
00048 private:
00049    PgSQL_Stmt_t         *fStmt;          //! executed statement
00050    Int_t                 fNumBuffers;    //! number of statement parameters
00051    char                **fBind;          //! array of data for input
00052    char                **fFieldName;     //! array of column names
00053    Int_t                 fWorkingMode;   //! 1 - setting parameters, 2 - retrieving results
00054    Int_t                 fIterationCount;//! number of iteration
00055    int                  *fParamLengths;  //! length of column
00056    int                  *fParamFormats;  //! data type (OID)
00057    Int_t                 fNumResultRows;
00058    Int_t                 fNumResultCols;
00059 
00060    Bool_t      IsSetParsMode() const { return fWorkingMode==1; }
00061    Bool_t      IsResultSetMode() const { return fWorkingMode==2; }
00062 
00063    Bool_t      SetSQLParamType(Int_t npar, int sqltype, bool sig, int sqlsize = 0);
00064 
00065    long double ConvertToNumeric(Int_t npar);
00066    const char *ConvertToString(Int_t npar);
00067 
00068    void        FreeBuffers();
00069    void        SetBuffersNumber(Int_t n);
00070 
00071 public:
00072    TPgSQLStatement(PgSQL_Stmt_t* stmt, Bool_t errout = kTRUE);
00073    virtual ~TPgSQLStatement();
00074 
00075    virtual void        Close(Option_t * = "");
00076 
00077    virtual Int_t       GetBufferLength() const { return 1; }
00078    virtual Int_t       GetNumParameters();
00079 
00080    virtual Bool_t      SetNull(Int_t npar);
00081    virtual Bool_t      SetInt(Int_t npar, Int_t value);
00082    virtual Bool_t      SetUInt(Int_t npar, UInt_t value);
00083    virtual Bool_t      SetLong(Int_t npar, Long_t value);
00084    virtual Bool_t      SetLong64(Int_t npar, Long64_t value);
00085    virtual Bool_t      SetULong64(Int_t npar, ULong64_t value);
00086    virtual Bool_t      SetDouble(Int_t npar, Double_t value);
00087    virtual Bool_t      SetString(Int_t npar, const char* value, Int_t maxsize = 256);
00088    virtual Bool_t      SetBinary(Int_t npar, void* mem, Long_t size, Long_t maxsize = 0x1000);
00089    virtual Bool_t      SetDate(Int_t npar, Int_t year, Int_t month, Int_t day);
00090    virtual Bool_t      SetTime(Int_t npar, Int_t hour, Int_t min, Int_t sec);
00091    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);
00092    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);
00093 
00094    virtual Bool_t      NextIteration();
00095 
00096    virtual Bool_t      Process();
00097    virtual Int_t       GetNumAffectedRows();
00098 
00099    virtual Bool_t      StoreResult();
00100    virtual Int_t       GetNumFields();
00101    virtual const char *GetFieldName(Int_t nfield);
00102    virtual Bool_t      NextResultRow();
00103 
00104    virtual Bool_t      IsNull(Int_t npar);
00105    virtual Int_t       GetInt(Int_t npar);
00106    virtual UInt_t      GetUInt(Int_t npar);
00107    virtual Long_t      GetLong(Int_t npar);
00108    virtual Long64_t    GetLong64(Int_t npar);
00109    virtual ULong64_t   GetULong64(Int_t npar);
00110    virtual Double_t    GetDouble(Int_t npar);
00111    virtual const char *GetString(Int_t npar);
00112    virtual Bool_t      GetBinary(Int_t npar, void* &mem, Long_t& size);
00113    virtual Bool_t      GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day);
00114    virtual Bool_t      GetTime(Int_t npar, Int_t& hour, Int_t& min, Int_t& sec);
00115    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);
00116    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&);
00117 
00118    ClassDef(TPgSQLStatement, 0);  // SQL statement class for PgSQL DB
00119 };
00120 
00121 #endif

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