kexi

cursor.h
1/* This file is part of the KDE project
2 Copyright (C) 2003-2006 Jaroslaw Staniek <js@iidea.pl>
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KEXIDB_CURSOR_H
21#define KEXIDB_CURSOR_H
22
23#include <tqstring.h>
24#include <tqvariant.h>
25#include <tqptrvector.h>
26#include <tqvaluevector.h>
27
28#include <kexidb/connection.h>
29#include <kexidb/object.h>
30
31namespace KexiDB {
32
33class RowEditBuffer;
34
36
66class KEXI_DB_EXPORT Cursor: public TQObject, public Object
67{
68 TQ_OBJECT
69
70
71 public:
73 enum Options {
74 NoOptions = 0,
75 Buffered = 1
76 };
77
78 virtual ~Cursor();
79
81 inline Connection* connection() const { return m_conn; }
82
85 bool open();
86
90 bool reopen();
91
92// /*! Opens the cursor using \a statement.
93// Omit \a statement if cursor is already initialized with statement
94// at creation time. If \a statement is not empty, existing statement
95// (if any) is overwritten. */
96// bool open( const TQString& statement = TQString() );
97
100 virtual bool close();
101
104 inline QuerySchema *query() const { return m_query; }
105
107 TQValueList<TQVariant> queryParameters() const;
108
110 void setQueryParameters(const TQValueList<TQVariant>& params);
111
114 inline TQString rawStatement() const { return m_rawStatement; }
115
118 inline uint options() const { return m_options; }
119
121 inline bool isOpened() const { return m_opened; }
122
124 bool isBuffered() const;
125
131 void setBuffered(bool buffered);
132
136 bool moveFirst();
137
141 virtual bool moveLast();
142
144 virtual bool moveNext();
145
148 virtual bool movePrev();
149
151 bool eof() const;
152
154 bool bof() const;
155
161 TQ_LLONG at() const;
162
165 inline uint fieldCount() const { return m_query ? m_logicalFieldCount : m_fieldCount; }
166
173 inline bool containsROWIDInfo() const { return m_containsROWIDInfo; }
174
181 virtual TQVariant value(uint i) = 0;
182
184 virtual const char ** rowData() const = 0;
185
200 void setOrderByColumnList(const TQStringList& columnNames);
201
203 void setOrderByColumnList(const TQString& column1, const TQString& column2 = TQString(),
204 const TQString& column3 = TQString(), const TQString& column4 = TQString(),
205 const TQString& column5 = TQString());
206
209 QueryColumnInfo::Vector orderByColumnList() const;
210
216 virtual void storeCurrentRow(RowData &data) const = 0;
217
218 bool updateRow(RowData& data, RowEditBuffer& buf, bool useROWID = false);
219
220 bool insertRow(RowData& data, RowEditBuffer& buf, bool getROWID = false);
221
222 bool deleteRow(RowData& data, bool useROWID = false);
223
224 bool deleteAllRows();
225
233 virtual int serverResult() { return 0; }
234
240 virtual TQString serverResultName() { return TQString(); }
241
247 virtual TQString serverErrorMsg() { return TQString(); }
248
250 TQString debugString() const;
251
253 void debug() const;
254
255 protected:
257 enum FetchResult { FetchError=0, FetchOK=1, FetchEnd=2 };
258
260 Cursor(Connection* conn, const TQString& statement, uint options = NoOptions );
261
263 Cursor(Connection* conn, QuerySchema& query, uint options = NoOptions );
264
265 void init();
266
269 bool getNextRecord();
270
271 /* Note for driver developers: this method should initialize engine-specific cursor's
272 resources using m_sql statement. It is not required to store \a statement somewhere
273 in your Cursor subclass (it is already stored in m_query or m_rawStatement,
274 depending query type) - only pass it to proper engine's function. */
275 virtual bool drv_open() = 0;
276
277 virtual bool drv_close() = 0;
278// virtual bool drv_moveFirst() = 0;
279 virtual void drv_getNextRecord() = 0;
280//unused virtual bool drv_getPrevRecord() = 0;
281
298 virtual void drv_bufferMovePointerNext() = 0;
300 virtual void drv_bufferMovePointerPrev() = 0;
303 virtual void drv_bufferMovePointerTo(TQ_LLONG at) = 0;
304
305 /*DISABLED: ! This is called only once in open(), after successful drv_open().
306 Reimplement this if you need (or not) to do get the first record after drv_open(),
307 eg. to know if there are any records in table. Value returned by this method
308 will be assigned to m_readAhead.
309 Default implementation just calls drv_getNextRecord(). */
310
313 virtual void drv_clearBuffer() {}
314
316 void clearBuffer();
317
320 virtual void drv_clearServerResult() = 0;
321
322 TQGuardedPtr<Connection> m_conn;
323 QuerySchema *m_query;
324// CursorData *m_data;
325 TQString m_rawStatement;
326 bool m_opened : 1;
327//js (m_at==0 is enough) bool m_beforeFirst : 1;
328 bool m_atLast : 1;
329 bool m_afterLast : 1;
330// bool m_atLast;
331 bool m_validRecord : 1;
332 bool m_containsROWIDInfo : 1;
333 TQ_LLONG m_at;
337 char m_result;
338
339 //<members related to buffering>
342 //</members related to buffering>
343
345 QueryColumnInfo::Vector* m_fieldsExpanded;
346
348 QueryColumnInfo::Vector* m_orderByColumnList;
349
350 TQValueList<TQVariant>* m_queryParameters;
351
352 private:
353 bool m_readAhead : 1;
354
355 //<members related to buffering>
356 bool m_at_buffer : 1;
357 //</members related to buffering>
358
359
360 class Private;
361 Private *d;
362};
363
364} //namespace KexiDB
365
366#endif
Provides database connection, allowing queries and data modification.
Definition connection.h:62
Provides database cursor functionality.
Definition cursor.h:67
bool insertRow(RowData &data, RowEditBuffer &buf, bool getROWID=false)
Definition cursor.cpp:470
bool deleteRow(RowData &data, bool useROWID=false)
Definition cursor.cpp:479
int m_records_in_buf
number of records currently stored in the buffer
Definition cursor.h:340
virtual void drv_clearBuffer()
Definition cursor.h:313
bool isOpened() const
Definition cursor.h:121
TQString rawStatement() const
Definition cursor.h:114
bool deleteAllRows()
Definition cursor.cpp:488
bool containsROWIDInfo() const
Definition cursor.h:173
virtual TQString serverResultName()
Definition cursor.h:240
QueryColumnInfo::Vector orderByColumnList() const
Definition cursor.cpp:553
char m_result
result of a row fetching
Definition cursor.h:337
TQ_LLONG at() const
Definition cursor.cpp:349
FetchResult
possible results of row fetching, used for m_result
Definition cursor.h:257
bool updateRow(RowData &data, RowEditBuffer &buf, bool useROWID=false)
Definition cursor.cpp:461
virtual TQVariant value(uint i)=0
Cursor(Connection *conn, const TQString &statement, uint options=NoOptions)
Definition cursor.cpp:40
virtual void storeCurrentRow(RowData &data) const =0
QueryColumnInfo::Vector * m_fieldsExpanded
Useful e.g. for value(int) method when we need access to schema def.
Definition cursor.h:345
virtual void drv_appendCurrentRecordToBuffer()=0
virtual void drv_bufferMovePointerTo(TQ_LLONG at)=0
Options
Cursor options that describes its behaviour.
Definition cursor.h:73
virtual int serverResult()
Definition cursor.h:233
void setOrderByColumnList(const TQStringList &columnNames)
Definition cursor.cpp:529
uint m_fieldCount
cached field count information
Definition cursor.h:334
QueryColumnInfo::Vector * m_orderByColumnList
Used by setOrderByColumnList().
Definition cursor.h:348
uint fieldCount() const
Definition cursor.h:165
Connection * connection() const
Definition cursor.h:81
uint m_logicalFieldCount
logical field count, i.e. without intrernal values like ROWID or lookup
Definition cursor.h:335
virtual void drv_bufferMovePointerNext()=0
virtual void drv_bufferMovePointerPrev()=0
uint options() const
Definition cursor.h:118
virtual const char ** rowData() const =0
virtual TQString serverErrorMsg()
Definition cursor.h:247
uint m_options
cursor options that describes its behaviour
Definition cursor.h:336
bool m_validRecord
true if valid record is currently retrieved @ current position
Definition cursor.h:331
QuerySchema * query() const
Definition cursor.h:104
bool m_buffering_completed
true if we already have all records stored in the buffer
Definition cursor.h:341
virtual void drv_clearServerResult()=0
KexiDB::QuerySchema provides information about database query.
provides data for single edited database row KexiDB::RowEditBuffer provides data for single edited ro...
High-level database connectivity library with database backend drivers.
TQValueVector< TQVariant > RowData
structure for storing single record with type information
Definition connection.h:47
KEXI_DB_EXPORT void debug(const QuerySchemaParameterList &list)
Shows debug information for list.