kexi
KexiDB::Cursor Class Reference
#include <cursor.h>
Inheritance diagram for KexiDB::Cursor:

Detailed Description
Provides database cursor functionality.Cursor can be defined in two ways:
- by passing QuerySchema object to Connection::executeQuery() or Connection::prepareQuery(); then query is defined for in engine-independent way -- this is recommended usage
- by passing raw query statement string to Connection::executeQuery() or Connection::prepareQuery(); then query may be defined for in engine-dependent way -- this is not recommended usage, but convenient when we can't or do not want to allocate QuerySchema object, while we know that the query statement is syntactically and logically ok in our context.
You can move cursor to next record with moveNext() and move back with movePrev(). The cursor is always positioned on record, not between records, with exception that ofter open() it is positioned before first record (if any) -- then bof() equals true, and can be positioned after the last record (if any) with moveNext() -- then eof() equals true, For example, if you have four records 1, 2, 3, 4, then after calling moveNext(), moveNext(), moveNext(), movePrev() you are going through records: 1, 2, 3, 2.
Cursor can be buffered or unbuferred. Buffering in this class is not related to any SQL engine capatibilities for server-side cursors (eg. like 'DECLARE CURSOR' statement) - buffered data is at client (application) side. Any record retrieved in buffered cursor will be stored inside an internal buffer and reused when needed. Unbuffered cursor always requires one record fetching from db connection at every step done with moveNext(), movePrev(), etc.
Notes:
- Do not use delete operator for Cursor objects - this will fail; use Connection::deleteCursor() instead.
- QuerySchema object is not owned by Cursor object that uses it.
Definition at line 66 of file cursor.h.
Public Types | |
enum | Options { NoOptions = 0, Buffered = 1 } |
Public Member Functions | |
virtual | ~Cursor () |
Connection * | connection () const |
bool | open () |
bool | reopen () |
virtual bool | close () |
QuerySchema * | query () const |
QString | rawStatement () const |
uint | options () const |
bool | isOpened () const |
bool | isBuffered () const |
void | setBuffered (bool buffered) |
bool | moveFirst () |
virtual bool | moveLast () |
virtual bool | moveNext () |
virtual bool | movePrev () |
bool | eof () const |
bool | bof () const |
Q_LLONG | at () const |
uint | fieldCount () const |
bool | containsROWIDInfo () const |
virtual QVariant | value (uint i)=0 |
virtual const char ** | rowData () const =0 |
void | setOrderByColumnList (const QStringList &columnNames) |
void | setOrderByColumnList (const QString &column1, const QString &column2=QString::null, const QString &column3=QString::null, const QString &column4=QString::null, const QString &column5=QString::null) |
QueryColumnInfo::Vector | orderByColumnList () const |
virtual void | storeCurrentRow (RowData &data) const =0 |
bool | updateRow (RowData &data, RowEditBuffer &buf, bool useROWID=false) |
bool | insertRow (RowData &data, RowEditBuffer &buf, bool getROWID=false) |
bool | deleteRow (RowData &data, bool useROWID=false) |
bool | deleteAllRows () |
virtual int | serverResult () |
virtual QString | serverResultName () |
virtual QString | serverErrorMsg () |
QString | debugString () const |
void | debug () const |
Protected Types | |
enum | FetchResult { FetchError = 0, FetchOK = 1, FetchEnd = 2 } |
Protected Member Functions | |
Cursor (Connection *conn, const QString &statement, uint options=NoOptions) | |
Cursor (Connection *conn, QuerySchema &query, uint options=NoOptions) | |
void | init () |
bool | getNextRecord () |
virtual bool | drv_open ()=0 |
virtual bool | drv_close ()=0 |
virtual void | drv_getNextRecord ()=0 |
virtual void | drv_appendCurrentRecordToBuffer ()=0 |
virtual void | drv_bufferMovePointerNext ()=0 |
virtual void | drv_bufferMovePointerPrev ()=0 |
virtual void | drv_bufferMovePointerTo (Q_LLONG at)=0 |
virtual void | drv_clearBuffer () |
void | clearBuffer () |
virtual void | drv_clearServerResult ()=0 |
Protected Attributes | |
QGuardedPtr< Connection > | m_conn |
QuerySchema * | m_query |
QString | m_rawStatement |
bool | m_opened: 1 |
bool | m_atLast: 1 |
bool | m_afterLast: 1 |
bool | m_validRecord: 1 |
bool | m_containsROWIDInfo: 1 |
Q_LLONG | m_at |
uint | m_fieldCount |
uint | m_options |
char | m_result |
int | m_records_in_buf |
bool | m_buffering_completed: 1 |
QueryColumnInfo::Vector * | m_fieldsExpanded |
QueryColumnInfo::Vector * | m_orderByColumnList |
Member Enumeration Documentation
|
posible results of row fetching, used for m_result
|
|
Cursor options that describes its behaviour.
|
Constructor & Destructor Documentation
|
Cursor will operate on conn, raw statement will be used to execute query. Definition at line 36 of file cursor.cpp. |
|
Cursor will operate on conn, query schema will be used to execute query. Definition at line 46 of file cursor.cpp. |
Member Function Documentation
|
Definition at line 322 of file cursor.cpp. |
|
Definition at line 317 of file cursor.cpp. |
|
Closes previously opened cursor. If the cursor is closed, nothing happens. Definition at line 152 of file cursor.cpp. |
|
|
|
|
|
Outputs debug information.
Definition at line 497 of file cursor.cpp. |
|
Definition at line 470 of file cursor.cpp. |
|
Stores currently fetched record's values in appropriate place of the buffer. Note for driver developers: This place can be computed using m_at. Do not change value of m_at or any other Cursor members, only change your internal structures like pointer to current row, etc. If your database engine's API function (for record fetching) do not allocates such a space, you want to allocate a space for current record. Otherwise, reuse existing structure, what could be more efficient. All functions like drv_appendCurrentRecordToBuffer() operates on the buffer, i.e. array of stored rows. You are not forced to have any particular fixed structure for buffer item or buffer itself - the structure is internal and only methods like storeCurrentRecord() visible to public. Implemented in KexiDB::MySqlCursor, KexiDB::pqxxSqlCursor, and KexiDB::SQLiteCursor. |
|
Moves pointer (that points to the buffer) -- to next item in this buffer. Note for driver developers: probably just execute "your_pointer++" is enough. Implemented in KexiDB::MySqlCursor, KexiDB::pqxxSqlCursor, and KexiDB::SQLiteCursor. |
|
Like drv_bufferMovePointerNext() but execute "your_pointer--". Implemented in KexiDB::MySqlCursor, KexiDB::pqxxSqlCursor, and KexiDB::SQLiteCursor. |
|
Moves pointer (that points to the buffer) to a new place: at. Implemented in KexiDB::MySqlCursor, KexiDB::pqxxSqlCursor, and KexiDB::SQLiteCursor. |
|
Clears cursor's buffer if this was allocated (only for buffered cursor type). Otherwise do nothing. For reimplementing. Default implementation does nothing. Reimplemented in KexiDB::SQLiteCursor. |
|
Clears an internal member that is used to storing last result code, the same that is returend by serverResult(). Reimplemented from KexiDB::Object. Implemented in KexiDB::MySqlCursor, KexiDB::pqxxSqlCursor, and KexiDB::SQLiteCursor. |
|
Definition at line 312 of file cursor.cpp. |
|
|
|
Internal: cares about proper flag setting depending on result of drv_getNextRecord() and depending on wherher a cursor is buffered. Definition at line 354 of file cursor.cpp. |
|
Definition at line 329 of file cursor.cpp. |
|
|
|
Moves current position to the first record and retrieves it.
Definition at line 178 of file cursor.cpp. |
|
Moves current position to the last record and retrieves it.
Definition at line 227 of file cursor.cpp. |
|
Moves current position to the next record and retrieves it. Definition at line 265 of file cursor.cpp. |
|
Moves current position to the next record and retrieves it. Currently it's only supported for buffered cursors. Definition at line 276 of file cursor.cpp. |
|
Opens the cursor using data provided on creation. The data might be either QuerySchema or raw sql statement. Definition at line 109 of file cursor.cpp. |
|
|
|
Definition at line 526 of file cursor.cpp. |
|
|
|
|
|
Closes and then opens again the same cursor. If the cursor is not opened it is just opened and result of this open is returned. Otherwise, true is returned if cursor is successfully closed and then opened. Definition at line 171 of file cursor.cpp. |
|
[PROTOTYPE]
Implemented in KexiDB::MySqlCursor, KexiDB::pqxxSqlCursor, and KexiDB::SQLiteCursor. |
|
Reimplemented from KexiDB::Object. Reimplemented in KexiDB::MySqlCursor, and KexiDB::SQLiteCursor. |
|
Reimplemented from KexiDB::Object. Reimplemented in KexiDB::MySqlCursor, and KexiDB::SQLiteCursor. |
|
Reimplemented from KexiDB::Object. Reimplemented in KexiDB::MySqlCursor, and KexiDB::SQLiteCursor. |
|
Sets this cursor to buffered type or not. See description of buffered and nonbuffered cursors in class description. This method only works if cursor is not opened (isOpened()==false). You can close already opened cursor and then switch this option on/off. Definition at line 334 of file cursor.cpp. |
|
Convenience method, similar to setOrderByColumnList(const QStringList&). Definition at line 514 of file cursor.cpp. |
|
Sets a list of columns for ORDER BY section of the query. Only works when the cursor has been created using QuerySchema object (i.e. when query()!=0; does not work with raw statements). Each name on the list must be a field or alias present within the query and must not be covered by aliases. If one or more names cannot be found within the query, the method will have no effect. Any previous ORDER BY settings will be removed. The order list provided here has priority over a list defined in the QuerySchema object itseld (using QuerySchema::setOrderByColumnList()). The QuerySchema object itself is not modifed by this method: only order of records retrieved by this cursor is affected. Use this method before calling open(). You can also call reopen() after calling this method to see effects of applying records order. Definition at line 502 of file cursor.cpp. |
|
Puts current record's data into data (makes a deep copy). This have unspecified behaviour if the cursor is not at valid record. Note: For reimplementation in driver's code. Shortly, this method translates a row data from internal representation (probably also used in buffer) to simple public RecordData representation. Implemented in KexiDB::MySqlCursor, KexiDB::pqxxSqlCursor, and KexiDB::SQLiteCursor. |
|
Implemented in KexiDB::MySqlCursor, KexiDB::pqxxSqlCursor, and KexiDB::SQLiteCursor. |
Member Data Documentation
|
number of records currently stored in the buffer
|
|
true if valid record is currently retrieved @ current position
|
|
Usefull e.g. for value(int) method when we need access to schema def.
|
|
cached field count information
|
|
Used by setOrderByColumnList().
|
|
result of a row fetching
|
|
cursor options that describes its behaviour
|
The documentation for this class was generated from the following files: