Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

FBwQuery.h

Go to the documentation of this file.
00001 
00007 //---------------------------------------------------------------------------
00008 
00009 #ifndef FBwH
00010 #define FBwH
00011 #include <FBwConfig.h>
00012 #include <FBwError.h>
00013 #include <FBwConect.h>
00014 #include <FBwDPB.h>
00015 #include <FBwTransac.h>
00016 #include <FBwDB.h>
00017 #include <FBwField.h>
00018 #include <FBwStringField.h>
00019 #include <FBwDateField.h>
00020 #include <FBwTimeField.h>
00021 #include <FBwDateTimeField.h>
00022 #include <FBwNumField.h>
00023 #include <FBwBlobField.h>
00024 #include <FBwFieldList.h>
00025 #include <iostream>
00026 //---------------------------------------------------------------------------
00027 
00029 namespace fbwrap
00030 {
00031 
00032 // What are we using from standard libraries
00033 using std::string;
00034 
00036 
00042 class FBwBQuery
00043 {
00044     XSQLDA *xsqlda;
00045     XSQLDA *inxsqlda;
00046     string sql;
00047     FBwDb *mdb;
00048     isc_stmt_handle stmt;
00049     FBwTransaction *mtr;
00050     ISC_STATUS *status;
00051     struct 
00052     {
00053         bool prepared:1;
00054         bool opened:1;
00055         bool eof:1;
00056         bool bof:1;
00057         bool error:1;
00058     } errst;
00059     struct 
00060     {
00061         bool checkparams:1;
00062         bool outparams:1;
00063         bool buffered:1;
00064         bool autocommit:1;
00065     } options;
00066     string cursor_name;
00067 protected:
00068     void ClearStatus()
00069     {
00070         errst.prepared=false;
00071         errst.opened=false;
00072         errst.bof=false;
00073         errst.eof=false;
00074         errst.error=false;
00075     }
00077 
00081     virtual char *GetSqlText()
00082     {
00083         return const_cast<char *>(sql.c_str());
00084     }
00085     int Fetch();                        
00086     XSQLDA *CreateSqlda();              
00087     void CreateParams();                
00088     bool XSQLDAResize(XSQLDA **qx);     
00089 
00090     bool Execute();                     
00092     void SqlStmtInfo();
00094     void VCommit();
00095     XSQLDA *GetXSQLDA()
00096     {
00097         return xsqlda;
00098     }
00100     void GenCursorName();
00101 public:
00103 
00106     FBwBQuery(FBwDb *pMdb):
00107             Fields(pMdb),Params(pMdb)
00108     {
00109         mdb=pMdb;
00110         ClearStatus();
00111         xsqlda=0;
00112         inxsqlda=0;
00113         stmt=0;
00114         options.buffered=false;
00115         options.autocommit=true;
00116         status = mdb->GetStatus();      // Use db status vector
00117         GenCursorName();
00118     }
00119     void Prepare();
00120     void UnPrepare();
00122     void SetSql(string sqltext);
00124     string GetSql() const
00125     {
00126         return sql;
00127     }
00129     void Open();
00131     void Close()
00132     {
00133         if( errst.prepared )
00134         {
00135             VCommit();
00136             Fields.DestroyFields();
00137             UnPrepare();
00138         }
00139     }
00141     void First();
00143     void Next();
00145     bool IsOpen() const
00146     {
00147         return errst.opened;
00148     }
00150     bool IsPrepared()
00151     {
00152         return errst.prepared;
00153     }
00155     bool Eof()
00156     {
00157         return errst.eof;
00158     }
00160     bool Bof()
00161     {
00162         return errst.bof;
00163     }
00165     bool Error()
00166     {
00167         return errst.error;
00168     }
00170     FieldList Fields;
00172     FieldList Params;
00173     string Text()
00174     {
00175         return sql;
00176     }
00177     void Debug();
00178     void GetLastError(BasicFBwErrorMgr *err)
00179     {
00180         err->Assign(status);
00181     }
00183     virtual ~FBwBQuery()
00184     {
00185         Close();
00186         if( xsqlda )
00187             delete xsqlda;
00188         if( inxsqlda )
00189             delete inxsqlda;
00190     }
00192     void DumpFields(std::ostream &o) const;
00193     void SetAutoCommit(bool how)
00194     {
00195         options.autocommit=how;
00196     }
00198     void ExecSQL()
00199     {
00200         Execute();
00201     }
00202 };
00204 std::ostream& operator<<(std::ostream &o, const FBwBQuery &q);
00205 //-------------------------------------------------------------------------
00206 }
00207 #endif

Generated on Fri Jan 31 08:30:02 2003 for fbwrap by doxygen1.2.17