KDb

XbaseCursor.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2008 Sharan Rao <[email protected]>
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 
28 class KDbxBaseCursorData {
29  public:
30  explicit xBaseCursorData(KDbCursor* cursor = nullptr)
31  : internalCursor(cursor)
32  {
33  }
34 
35  KDbCursor* internalCursor;
36 
37 };
38 
39 xBaseCursor::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 
46 xBaseCursor::xBaseCursor(KDbConnection* conn, KDbCursor* internalCursor, KDbQuerySchema* query, int options)
47  : KDbCursor( conn, query, options )
48  , d( new xBaseCursorData(internalCursor) )
49 {
50  init();
51 }
52 
53 xBaseCursor::~xBaseCursor() {
54  close();
55 }
56 
57 void 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 
67 bool 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 
76 bool 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 
86 void xBaseCursor::drv_getNextRecord() {
87  if (!d->internalCursor) {
88  m_fetchResult = FetchResult::Error;
89  return;
90  }
91 
92  if ( !d->internalCursor->moveNext() ) {
93  if ( d->internalCursor->eof() )
94  m_fetchResult = FetchResult::End;
95  else
96  m_fetchResult = FetchResult::Error;
97  } else {
98  m_fetchResult = FetchResult::Ok;
99  m_fieldCount = d->internalCursor->fieldCount();
100  m_fieldsToStoreInRecord = m_fieldCount;
101  }
102 }
103 
104 QVariant 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 
113 bool 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 
127 void xBaseCursor::drv_appendCurrentRecordToBuffer() {
128 }
129 
130 
131 void xBaseCursor::drv_bufferMovePointerNext() {
132 }
133 
134 void xBaseCursor::drv_bufferMovePointerPrev() {
135 }
136 
137 
138 void xBaseCursor::drv_bufferMovePointerTo(qint64 to) {
139  Q_UNUSED(to);
140 }
141 
142 const char** xBaseCursor::recordData() const {
143  if (!d->internalCursor) {
144  return nullptr;
145  }
146  return d->internalCursor->recordData();
147 }
148 
149 int xBaseCursor::serverResult()
150 {
151  if (!d->internalCursor) {
152  // Any better value to return ?
153  return -1;
154  }
155  return d->internalCursor->serverResult();
156 }
157 
158 QString 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 
171 QString xBaseCursor::serverErrorMsg()
172 {
173  if (!d->internalCursor) {
174  return QString();
175  }
176  return d->internalCursor->serverErrorMsg();
177 }
bool deleteCursor(KDbCursor *cursor)
Provides database cursor functionality.
Definition: KDbCursor.h:68
QCA_EXPORT void init()
Specialized string for escaping.
const QList< QKeySequence > & close()
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
Structure for storing single record with type information.
Definition: KDbRecordData.h:36
KDbQuerySchema provides information about database query.
Provides database connection, allowing queries and data modification.
Definition: KDbConnection.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:40 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.