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

dbquery.h

00001 /* liblookdb: dbquery.h - A database query
00002     Copyright (C) 1998-2001 LOOK Systems
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this library; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 */
00018 #ifndef LIBLOOKDB_DBQUERY_H
00019 #define LIBLOOKDB_DBQUERY_H
00020 
00021 // $Id: dbquery.h,v 1.8 2001/07/19 17:51:50 clive Exp $
00022 
00023 #include "lookdblibrary.h"
00024 #include "looktypebaselist.h"
00025 #include "dbrowlist.h"
00026 #include "lkstring.h"
00027 #include "lookdbinterface.h"
00028 
00029 namespace look {
00030 
00031 class DbConnection;
00032 
00034 
00049 class LOOKDBLIBRARY_DLL DbQuery
00050 {
00051 public:
00052 
00053         enum QueryState
00054         {
00055                 Q_CREATED,
00056                 Q_PREPARED,
00057                 Q_EXECUTED,
00058                 Q_CURSOR_OPEN,
00059                 Q_FINISHED
00060         };
00061 
00062         DbQuery( const LookString& theQueryText = "",
00063                 DbConnection* theConnection = NULL );
00064         virtual ~DbQuery();
00065 
00066         bool Prepare(void);
00067         bool Describe(void);
00068         bool Execute(void);
00069 
00070         long ColumnCount( void ) const;
00071         long RowCount( bool countNow = false );
00072 
00073         LookString GetColumnName( long theColumnNo );
00074         bool GetColumnNullable( long theColumnNo );
00075 
00076         // this returns the LookTypeBase id of the column
00077         // it's then up to the user to deal with it as they please
00078         long GetColumnTypeID( long theColumnNo );
00079 
00080         DbRow* Fetch();
00081         DbRow* GetRow(long theRowNumber);
00082 
00083         void Close(void);
00084 
00085         void AddParameter( LookTypeBase* theParameter, bool isLong = false );
00086         void ClearParameters( void );
00087 
00088         // need to call this if you ever want to use GetRow by number
00089         // rather than just fetch
00090         void UseRowCache( void )
00091         {
00092                 itHasRowCache = true;
00093         }
00094 
00095         int GetNRowsAffected( void )
00096         {
00097                 return itsRowsAffected;
00098         }
00099 
00100 protected:
00101         void UploadParameters( void );
00102 
00103         void TidyCursor(void);
00104 
00105 // state queries
00106         bool IsPrepared( void ) const
00107         {
00108                 return (itsState >= Q_PREPARED);
00109         }
00110 
00111         bool IsExecuted( void ) const
00112         {
00113                 return (itsState >= Q_EXECUTED);
00114         }
00115 
00116         bool CursorIsOpen( void ) const
00117         {
00118                 return (itsState == Q_CURSOR_OPEN);
00119         }
00120 
00121         DbConnection* itsConnection;
00122 #ifndef WIN32
00123         bool itOwnsConnection;
00124 #endif
00125 
00126         LookString itsQueryText;
00127 
00128         QueryState itsState;
00129 
00130         long    itsCurrentRowNumber;
00131         long    itsRowCount;
00132         bool itHasRowCache;
00133         DbRow* itsLastFetchedRow;
00134 
00135         DbRowPtrList itsRows;
00136         LookTypePtrList itsParameters;
00137         long itsLongParameterIndex;
00138 
00139         LOOK_STMT       itsStmt;
00140 
00141         // the number of rows affected by an update or whatever
00142         int itsRowsAffected;
00143 
00144         static long itsNextStatementId;
00145 };
00146 
00147 
00148 } // end of "look" namespace
00149 #endif 

Generated at Thu Jan 17 12:53:06 2002 for liblookdb by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001