kexi
cursor.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00092
00093
00094
00095
00096
00099 virtual bool close();
00100
00103 inline QuerySchema *query() const { return m_query; }
00104
00106 QValueList<QVariant> queryParameters() const;
00107
00109 void setQueryParameters(const QValueList<QVariant>& params);
00110
00113 inline QString rawStatement() const { return m_rawStatement; }
00114
00117 inline uint options() const { return m_options; }
00118
00120 inline bool isOpened() const { return m_opened; }
00121
00123 bool isBuffered() const;
00124
00130 void setBuffered(bool buffered);
00131
00135 bool moveFirst();
00136
00140 virtual bool moveLast();
00141
00143 virtual bool moveNext();
00144
00147 virtual bool movePrev();
00148
00150 bool eof() const;
00151
00153 bool bof() const;
00154
00160 Q_LLONG at() const;
00161
00164 inline uint fieldCount() const { return m_query ? m_logicalFieldCount : m_fieldCount; }
00165
00172 inline bool containsROWIDInfo() const { return m_containsROWIDInfo; }
00173
00180 virtual QVariant value(uint i) = 0;
00181
00183 virtual const char ** rowData() const = 0;
00184
00199 void setOrderByColumnList(const QStringList& columnNames);
00200
00202 void setOrderByColumnList(const QString& column1, const QString& column2 = QString::null,
00203 const QString& column3 = QString::null, const QString& column4 = QString::null,
00204 const QString& column5 = QString::null);
00205
00208 QueryColumnInfo::Vector orderByColumnList() const;
00209
00215 virtual void storeCurrentRow(RowData &data) const = 0;
00216
00217 bool updateRow(RowData& data, RowEditBuffer& buf, bool useROWID = false);
00218
00219 bool insertRow(RowData& data, RowEditBuffer& buf, bool getROWID = false);
00220
00221 bool deleteRow(RowData& data, bool useROWID = false);
00222
00223 bool deleteAllRows();
00224
00232 virtual int serverResult() { return 0; }
00233
00239 virtual QString serverResultName() { return QString::null; }
00240
00246 virtual QString serverErrorMsg() { return QString::null; }
00247
00249 QString debugString() const;
00250
00252 void debug() const;
00253
00254 protected:
00256 typedef enum FetchResult { FetchError=0, FetchOK=1, FetchEnd=2 };
00257
00259 Cursor(Connection* conn, const QString& statement, uint options = NoOptions );
00260
00262 Cursor(Connection* conn, QuerySchema& query, uint options = NoOptions );
00263
00264 void init();
00265
00268 bool getNextRecord();
00269
00270
00271
00272
00273
00274 virtual bool drv_open() = 0;
00275
00276 virtual bool drv_close() = 0;
00277
00278 virtual void drv_getNextRecord() = 0;
00279
00280
00293 virtual void drv_appendCurrentRecordToBuffer() = 0;
00297 virtual void drv_bufferMovePointerNext() = 0;
00299 virtual void drv_bufferMovePointerPrev() = 0;
00302 virtual void drv_bufferMovePointerTo(Q_LLONG at) = 0;
00303
00304
00305
00306
00307
00308
00309
00312 virtual void drv_clearBuffer() {}
00313
00315 void clearBuffer();
00316
00319 virtual void drv_clearServerResult() = 0;
00320
00321 QGuardedPtr<Connection> m_conn;
00322 QuerySchema *m_query;
00323
00324 QString m_rawStatement;
00325 bool m_opened : 1;
00326
00327 bool m_atLast : 1;
00328 bool m_afterLast : 1;
00329
00330 bool m_validRecord : 1;
00331 bool m_containsROWIDInfo : 1;
00332 Q_LLONG m_at;
00333 uint m_fieldCount;
00334 uint m_logicalFieldCount;
00335 uint m_options;
00336 char m_result;
00337
00338
00339 int m_records_in_buf;
00340 bool m_buffering_completed : 1;
00341
00342
00344 QueryColumnInfo::Vector* m_fieldsExpanded;
00345
00347 QueryColumnInfo::Vector* m_orderByColumnList;
00348
00349 QValueList<QVariant>* m_queryParameters;
00350
00351 private:
00352 bool m_readAhead : 1;
00353
00354
00355 bool m_at_buffer : 1;
00356
00357
00358
00359 class Private;
00360 Private *d;
00361 };
00362
00363 }
00364
00365 #endif
|