Changeset View
Changeset View
Standalone View
Standalone View
src/KDbCursor.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 37 | public: | |||
---|---|---|---|---|---|
61 | KDbQueryColumnInfo::Vector orderByColumnList; | 61 | KDbQueryColumnInfo::Vector orderByColumnList; | ||
62 | QList<QVariant> queryParameters; | 62 | QList<QVariant> queryParameters; | ||
63 | 63 | | |||
64 | //<members related to buffering> | 64 | //<members related to buffering> | ||
65 | bool atBuffer; //!< true if we already point to the buffer with curr_coldata | 65 | bool atBuffer; //!< true if we already point to the buffer with curr_coldata | ||
66 | //</members related to buffering> | 66 | //</members related to buffering> | ||
67 | }; | 67 | }; | ||
68 | 68 | | |||
69 | KDbCursor::KDbCursor(KDbConnection* conn, const KDbEscapedString& sql, int options) | 69 | KDbCursor::KDbCursor(KDbConnection* conn, const KDbEscapedString& sql, Options options) | ||
70 | : m_query(0) | 70 | : m_query(0) | ||
71 | , m_options(options) | 71 | , m_options(options) | ||
72 | , d(new Private) | 72 | , d(new Private) | ||
73 | { | 73 | { | ||
74 | #ifdef KDB_DEBUG_GUI | 74 | #ifdef KDB_DEBUG_GUI | ||
75 | KDb::debugGUI(QLatin1String("Create cursor for raw SQL: ") + sql.toString()); | 75 | KDb::debugGUI(QLatin1String("Create cursor for raw SQL: ") + sql.toString()); | ||
76 | #endif | 76 | #endif | ||
77 | init(conn); | 77 | init(conn); | ||
78 | d->rawSql = sql; | 78 | d->rawSql = sql; | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | KDbCursor::KDbCursor(KDbConnection* conn, KDbQuerySchema* query, int options) | 81 | KDbCursor::KDbCursor(KDbConnection* conn, KDbQuerySchema* query, Options options) | ||
82 | : m_query(query) | 82 | : m_query(query) | ||
83 | , m_options(options) | 83 | , m_options(options) | ||
84 | , d(new Private) | 84 | , d(new Private) | ||
85 | { | 85 | { | ||
86 | #ifdef KDB_DEBUG_GUI | 86 | #ifdef KDB_DEBUG_GUI | ||
87 | KDb::debugGUI(QString::fromLatin1("Create cursor for query \"%1\":\n") | 87 | KDb::debugGUI(QString::fromLatin1("Create cursor for query \"%1\":\n") | ||
88 | .arg(KDb::iifNotEmpty(query->name(), QString::fromLatin1("<unnamed>"))) | 88 | .arg(KDb::iifNotEmpty(query->name(), QString::fromLatin1("<unnamed>"))) | ||
89 | + KDbUtils::debugString(query)); | 89 | + KDbUtils::debugString(query)); | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 157 | { | |||
158 | return m_query; | 158 | return m_query; | ||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | KDbEscapedString KDbCursor::rawSql() const | 161 | KDbEscapedString KDbCursor::rawSql() const | ||
162 | { | 162 | { | ||
163 | return d->rawSql; | 163 | return d->rawSql; | ||
164 | } | 164 | } | ||
165 | 165 | | |||
166 | int KDbCursor::options() const | 166 | KDbCursor::Options KDbCursor::options() const | ||
167 | { | 167 | { | ||
168 | return m_options; | 168 | return m_options; | ||
169 | } | 169 | } | ||
170 | 170 | | |||
171 | bool KDbCursor::isOpened() const | 171 | bool KDbCursor::isOpened() const | ||
172 | { | 172 | { | ||
173 | return d->opened; | 173 | return d->opened; | ||
174 | } | 174 | } | ||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Line(s) | |||||
279 | } | 279 | } | ||
280 | 280 | | |||
281 | bool KDbCursor::moveFirst() | 281 | bool KDbCursor::moveFirst() | ||
282 | { | 282 | { | ||
283 | if (!d->opened) { | 283 | if (!d->opened) { | ||
284 | return false; | 284 | return false; | ||
285 | } | 285 | } | ||
286 | if (!d->readAhead) { | 286 | if (!d->readAhead) { | ||
287 | if (m_options & Buffered) { | 287 | if (m_options & KDbCursor::Option::Buffered) { | ||
288 | if (m_records_in_buf == 0 && m_buffering_completed) { | 288 | if (m_records_in_buf == 0 && m_buffering_completed) { | ||
289 | //eof and bof should now return true: | 289 | //eof and bof should now return true: | ||
290 | m_afterLast = true; | 290 | m_afterLast = true; | ||
291 | m_at = 0; | 291 | m_at = 0; | ||
292 | return false; //buffering completed and there is no records! | 292 | return false; //buffering completed and there is no records! | ||
293 | } | 293 | } | ||
294 | if (m_records_in_buf > 0) { | 294 | if (m_records_in_buf > 0) { | ||
295 | //set state as we would be before first rec: | 295 | //set state as we would be before first rec: | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 348 | { | |||
352 | if (getNextRecord()) { | 352 | if (getNextRecord()) { | ||
353 | return true; | 353 | return true; | ||
354 | } | 354 | } | ||
355 | return false; | 355 | return false; | ||
356 | } | 356 | } | ||
357 | 357 | | |||
358 | bool KDbCursor::movePrev() | 358 | bool KDbCursor::movePrev() | ||
359 | { | 359 | { | ||
360 | if (!d->opened /*|| m_beforeFirst*/ || !(m_options & Buffered)) { | 360 | if (!d->opened /*|| m_beforeFirst*/ || !(m_options & KDbCursor::Option::Buffered)) { | ||
361 | return false; | 361 | return false; | ||
362 | } | 362 | } | ||
363 | //we're after last record and there are records in the buffer | 363 | //we're after last record and there are records in the buffer | ||
364 | //--let's move to last record | 364 | //--let's move to last record | ||
365 | if (m_afterLast && (m_records_in_buf > 0)) { | 365 | if (m_afterLast && (m_records_in_buf > 0)) { | ||
366 | drv_bufferMovePointerTo(m_records_in_buf - 1); | 366 | drv_bufferMovePointerTo(m_records_in_buf - 1); | ||
367 | m_at = m_records_in_buf; | 367 | m_at = m_records_in_buf; | ||
368 | d->atBuffer = true; //now current record is stored in the buffer | 368 | d->atBuffer = true; //now current record is stored in the buffer | ||
Show All 19 Lines | |||||
388 | } | 388 | } | ||
389 | d->validRecord = true; | 389 | d->validRecord = true; | ||
390 | m_afterLast = false; | 390 | m_afterLast = false; | ||
391 | return true; | 391 | return true; | ||
392 | } | 392 | } | ||
393 | 393 | | |||
394 | bool KDbCursor::isBuffered() const | 394 | bool KDbCursor::isBuffered() const | ||
395 | { | 395 | { | ||
396 | return m_options & Buffered; | 396 | return m_options & KDbCursor::Option::Buffered; | ||
397 | } | 397 | } | ||
398 | 398 | | |||
399 | void KDbCursor::setBuffered(bool buffered) | 399 | void KDbCursor::setBuffered(bool buffered) | ||
400 | { | 400 | { | ||
401 | if (!d->opened) { | 401 | if (!d->opened) { | ||
402 | return; | 402 | return; | ||
403 | } | 403 | } | ||
404 | if (isBuffered() == buffered) | 404 | if (isBuffered() == buffered) | ||
405 | return; | 405 | return; | ||
406 | m_options ^= Buffered; | 406 | m_options ^= KDbCursor::Option::Buffered; | ||
407 | } | 407 | } | ||
408 | 408 | | |||
409 | void KDbCursor::clearBuffer() | 409 | void KDbCursor::clearBuffer() | ||
410 | { | 410 | { | ||
411 | if (!isBuffered() || m_fieldCount == 0) | 411 | if (!isBuffered() || m_fieldCount == 0) | ||
412 | return; | 412 | return; | ||
413 | 413 | | |||
414 | drv_clearBuffer(); | 414 | drv_clearBuffer(); | ||
415 | 415 | | |||
416 | m_records_in_buf = 0; | 416 | m_records_in_buf = 0; | ||
417 | d->atBuffer = false; | 417 | d->atBuffer = false; | ||
418 | } | 418 | } | ||
419 | 419 | | |||
420 | bool KDbCursor::getNextRecord() | 420 | bool KDbCursor::getNextRecord() | ||
421 | { | 421 | { | ||
422 | m_fetchResult = FetchInvalid; //by default: invalid result of record fetching | 422 | m_fetchResult = FetchInvalid; //by default: invalid result of record fetching | ||
423 | 423 | | |||
424 | if (m_options & Buffered) {//this cursor is buffered: | 424 | if (m_options & KDbCursor::Option::Buffered) {//this cursor is buffered: | ||
425 | // kdbDebug() << "m_at < m_records_in_buf :: " << (long)m_at << " < " << m_records_in_buf; | 425 | // kdbDebug() << "m_at < m_records_in_buf :: " << (long)m_at << " < " << m_records_in_buf; | ||
426 | if (m_at < m_records_in_buf) {//we have next record already buffered: | 426 | if (m_at < m_records_in_buf) {//we have next record already buffered: | ||
427 | if (d->atBuffer) {//we already have got a pointer to buffer | 427 | if (d->atBuffer) {//we already have got a pointer to buffer | ||
428 | drv_bufferMovePointerNext(); //just move to next record in the buffer | 428 | drv_bufferMovePointerNext(); //just move to next record in the buffer | ||
429 | } else {//we have no pointer | 429 | } else {//we have no pointer | ||
430 | //compute a place in the buffer that contain next record's data | 430 | //compute a place in the buffer that contain next record's data | ||
431 | drv_bufferMovePointerTo(m_at - 1 + 1); | 431 | drv_bufferMovePointerTo(m_at - 1 + 1); | ||
432 | d->atBuffer = true; //now current record is stored in the buffer | 432 | d->atBuffer = true; //now current record is stored in the buffer | ||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |