kexi

cursor.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program 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    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KEXIDB_CURSOR_H
00021 #define KEXIDB_CURSOR_H
00022 
00023 #include <qstring.h>
00024 #include <qvariant.h>
00025 #include <qptrvector.h>
00026 #include <qvaluevector.h>
00027 
00028 #include <kexidb/connection.h>
00029 #include <kexidb/object.h>
00030 
00031 namespace KexiDB {
00032 
00033 class RowEditBuffer;
00034 
00036 
00066 class KEXI_DB_EXPORT Cursor: public QObject, public Object
00067 {
00068     Q_OBJECT
00069 
00070     public:
00072         enum Options {
00073             NoOptions = 0,
00074             Buffered = 1
00075         };
00076 
00077         virtual ~Cursor();
00078 
00080         inline Connection* connection() const { return m_conn; }
00081 
00084         bool open();
00085 
00089         bool reopen();
00090 
00091 //      /*! Opens the cursor using \a statement. 
00092 //       Omit \a statement if cursor is already initialized with statement 
00093 //       at creation time. If \a statement is not empty, existing statement
00094 //       (if any) is overwritten. */
00095 //      bool open( const QString& statement = QString::null );
00096 
00099         virtual bool close();
00100 
00103         inline QuerySchema *query() const { return m_query; }
00104 
00107         inline QString rawStatement() const { return m_rawStatement; }
00108 
00111         inline uint options() const { return m_options; }
00112 
00114         inline bool isOpened() const { return m_opened; }
00115 
00117         bool isBuffered() const;
00118 
00124         void setBuffered(bool buffered);
00125 
00129         bool moveFirst();
00130 
00134         virtual bool moveLast();
00135 
00137         virtual bool moveNext();
00138 
00141         virtual bool movePrev();
00142 
00144         bool eof() const;
00145 
00147         bool bof() const;
00148 
00154         Q_LLONG at() const;
00155 
00158         inline uint fieldCount() const { return m_fieldCount; }
00159 
00166         inline bool containsROWIDInfo() const { return m_containsROWIDInfo; }
00167 
00174         virtual QVariant value(uint i) = 0;
00175 
00177         virtual const char ** rowData() const = 0;
00178 
00193         void setOrderByColumnList(const QStringList& columnNames);
00194 
00196         void setOrderByColumnList(const QString& column1, const QString& column2 = QString::null, 
00197             const QString& column3 = QString::null, const QString& column4 = QString::null, 
00198             const QString& column5 = QString::null);
00199 
00202         QueryColumnInfo::Vector orderByColumnList() const;
00203 
00209         virtual void storeCurrentRow(RowData &data) const = 0;
00210 
00211         bool updateRow(RowData& data, RowEditBuffer& buf, bool useROWID = false);
00212 
00213         bool insertRow(RowData& data, RowEditBuffer& buf, bool getROWID = false);
00214 
00215         bool deleteRow(RowData& data, bool useROWID = false);
00216 
00217         bool deleteAllRows();
00218 
00226         virtual int serverResult() { return 0; }
00227         
00233         virtual QString serverResultName() { return QString::null; }
00234 
00240         virtual QString serverErrorMsg() { return QString::null; }
00241     
00243         QString debugString() const;
00244         
00246         void debug() const;
00247 
00248     protected:
00250         typedef enum FetchResult { FetchError=0, FetchOK=1, FetchEnd=2 };
00251 
00253         Cursor(Connection* conn, const QString& statement, uint options = NoOptions );
00254 
00256         Cursor(Connection* conn, QuerySchema& query, uint options = NoOptions );
00257 
00258         void init();
00259 
00262         bool getNextRecord();
00263 
00264         /* Note for driver developers: this method should initialize engine-specific cursor's
00265          resources using m_sql statement. It is not required to store \a statement somewhere
00266          in your Cursor subclass (it is already stored in m_query or m_rawStatement, 
00267          depending query type) - only pass it to proper engine's function. */
00268         virtual bool drv_open() = 0;
00269 
00270         virtual bool drv_close() = 0;
00271 //      virtual bool drv_moveFirst() = 0;
00272         virtual void drv_getNextRecord() = 0;
00273 //unused        virtual bool drv_getPrevRecord() = 0;
00274 
00287         virtual void drv_appendCurrentRecordToBuffer() = 0;
00291         virtual void drv_bufferMovePointerNext() = 0;
00293         virtual void drv_bufferMovePointerPrev() = 0;
00296         virtual void drv_bufferMovePointerTo(Q_LLONG at) = 0;
00297 
00298         /*DISABLED: ! This is called only once in open(), after successful drv_open().
00299             Reimplement this if you need (or not) to do get the first record after drv_open(),
00300             eg. to know if there are any records in table. Value returned by this method
00301             will be assigned to m_readAhead.
00302             Default implementation just calls drv_getNextRecord(). */
00303 
00306         virtual void drv_clearBuffer() {}
00307 
00309         void clearBuffer();
00310 
00313         virtual void drv_clearServerResult() = 0;
00314 
00315         QGuardedPtr<Connection> m_conn;
00316         QuerySchema *m_query;
00317 //      CursorData *m_data;
00318         QString m_rawStatement;
00319         bool m_opened : 1;
00320 //js (m_at==0 is enough)        bool m_beforeFirst : 1;
00321         bool m_atLast : 1;
00322         bool m_afterLast : 1;
00323 //      bool m_atLast;
00324         bool m_validRecord : 1; 
00325         bool m_containsROWIDInfo : 1;
00326         Q_LLONG m_at;
00327         uint m_fieldCount; 
00328         uint m_options; 
00329 
00330         char m_result; 
00331         
00332         //<members related to buffering>
00333         int m_records_in_buf;          
00334         bool m_buffering_completed : 1;   
00335         //</members related to buffering>
00336 
00338         QueryColumnInfo::Vector* m_fieldsExpanded;
00339 
00341         QueryColumnInfo::Vector* m_orderByColumnList;
00342 
00343 
00344 //      QValueList<bool> m_detailedVisibility;
00345 
00346     private:
00347         bool m_readAhead : 1;
00348         
00349         //<members related to buffering>
00350         bool m_at_buffer : 1;             
00351         //</members related to buffering>
00352 
00353 
00354         class Private;
00355         Private *d;
00356 };
00357 
00358 } //namespace KexiDB
00359 
00360 #endif
00361 
00362 
KDE Home | KDE Accessibility Home | Description of Access Keys