KDb

XbaseCursor.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2008 Sharan Rao <sharanrao@gmail.com>
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#include "XbaseCursor.h"
21#include "XbaseConnection.h"
22
23#include "KDbError.h"
24#include "KDb.h"
25
26#include <limits.h>
27
28class KDbxBaseCursorData {
29 public:
30 explicit xBaseCursorData(KDbCursor* cursor = nullptr)
31 : internalCursor(cursor)
32 {
33 }
34
35 KDbCursor* internalCursor;
36
37};
38
39xBaseCursor::xBaseCursor(KDbConnection* conn, KDbCursor* internalCursor, const KDbEscapedString& sql, int cursor_options)
40 : KDbCursor(conn,sql,cursor_options)
41 , d( new xBaseCursorData(internalCursor) )
42{
43 init();
44}
45
46xBaseCursor::xBaseCursor(KDbConnection* conn, KDbCursor* internalCursor, KDbQuerySchema* query, int options)
47 : KDbCursor( conn, query, options )
48 , d( new xBaseCursorData(internalCursor) )
49{
50 init();
51}
52
53xBaseCursor::~xBaseCursor() {
54 close();
55}
56
57void xBaseCursor::init() {
58
59 if (d->internalCursor) {
60 m_options |= d->internalCursor->options();
61 }
62 // SQLite does buffering. So all calls to moving the cursor to SQLite will read from the buffer
63 // ( if the rows are already buffered ) inside. Any point in double buffering ?
64 setBuffered(false);
65}
66
67bool xBaseCursor::drv_open(const KDbEscapedString& sql)
68{
69// xbaseDebug() << m_sql;
70 if (!d->internalCursor) {
71 return false;
72 }
73 return d->internalCursor->open();
74}
75
76bool xBaseCursor::drv_close() {
77 if (!d->internalCursor) {
78 return false;
79 }
80 m_opened = false;
81 KDbConnection* internalConn = d->internalCursor->connection();
82 internalConn->deleteCursor( d->internalCursor );
83 return true;
84}
85
86void xBaseCursor::drv_getNextRecord() {
87 if (!d->internalCursor) {
89 return;
90 }
91
92 if ( !d->internalCursor->moveNext() ) {
93 if ( d->internalCursor->eof() )
95 else
97 } else {
99 m_fieldCount = d->internalCursor->fieldCount();
101 }
102}
103
104QVariant xBaseCursor::value(int pos) {
105 if (!d->internalCursor) {
106 // Construct an invalid QVariant
107 return QVariant();
108 }
109 return d->internalCursor->value(pos);
110}
111
112
113bool xBaseCursor::drv_storeCurrentRecord(KDbRecordData* data) const
114{
115 if (!d->internalCursor) {
116 return false;
117 }
118
119 KDbRecordData* rData = d->internalCursor->storeCurrentRecord();
120 if (!rData) {
121 return false;
122 }
123 *data = *rData;
124 return true;
125}
126
127void xBaseCursor::drv_appendCurrentRecordToBuffer() {
128}
129
130
131void xBaseCursor::drv_bufferMovePointerNext() {
132}
133
134void xBaseCursor::drv_bufferMovePointerPrev() {
135}
136
137
138void xBaseCursor::drv_bufferMovePointerTo(qint64 to) {
139 Q_UNUSED(to);
140}
141
142const char** xBaseCursor::recordData() const {
143 if (!d->internalCursor) {
144 return nullptr;
145 }
146 return d->internalCursor->recordData();
147}
148
149int xBaseCursor::serverResult()
150{
151 if (!d->internalCursor) {
152 // Any better value to return ?
153 return -1;
154 }
155 return d->internalCursor->serverResult();
156}
157
158QString xBaseCursor::serverResultName() const
159{
160 if (!d->internalCursor) {
161 return QString();
162 }
163 return d->internalCursor->serverResultName();
164}
165
166//! @todo xBaseCursor::drv_clearServerResult()
167/*void xBaseCursor::drv_clearServerResult()
168{
169}*/
170
171QString xBaseCursor::serverErrorMsg()
172{
173 if (!d->internalCursor) {
174 return QString();
175 }
176 return d->internalCursor->serverErrorMsg();
177}
Provides database connection, allowing queries and data modification.
bool deleteCursor(KDbCursor *cursor)
Provides database cursor functionality.
Definition KDbCursor.h:69
@ End
at the end of data
@ Error
error of fetching
@ Ok
the data is fetched
int m_fieldsToStoreInRecord
Used by storeCurrentRecord(), reimplement if needed (e.g.
Definition KDbCursor.h:302
int m_fieldCount
cached field count information
Definition KDbCursor.h:301
KDbCursor::Options m_options
cursor options that describes its behavior
Definition KDbCursor.h:306
FetchResult m_fetchResult
result of a record fetching
Definition KDbCursor.h:316
void setBuffered(bool buffered)
virtual bool close()
Specialized string for escaping.
KDbQuerySchema provides information about database query.
Structure for storing single record with type information.
std::optional< QSqlQuery > query(const QString &queryStatement)
QCA_EXPORT void init()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.