File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -369,16 +369,42 @@ bool SQLiteBatch::HasKey(CDataStream&& key)
369
369
370
370
bool SQLiteBatch::StartCursor ()
371
371
{
372
- return false ;
372
+ assert (!m_cursor_init);
373
+ if (!m_database.m_db ) return false ;
374
+ m_cursor_init = true ;
375
+ return true ;
373
376
}
374
377
375
378
bool SQLiteBatch::ReadAtCursor (CDataStream& key, CDataStream& value, bool & complete)
376
379
{
377
- return false ;
380
+ complete = false ;
381
+
382
+ if (!m_cursor_init) return false ;
383
+
384
+ int res = sqlite3_step (m_cursor_stmt);
385
+ if (res == SQLITE_DONE) {
386
+ complete = true ;
387
+ return true ;
388
+ }
389
+ if (res != SQLITE_ROW) {
390
+ LogPrintf (" SQLiteBatch::ReadAtCursor: Unable to execute cursor step: %s\n " , sqlite3_errstr (res));
391
+ return false ;
392
+ }
393
+
394
+ // Leftmost column in result is index 0
395
+ const char * key_data = reinterpret_cast <const char *>(sqlite3_column_blob (m_cursor_stmt, 0 ));
396
+ int key_data_size = sqlite3_column_bytes (m_cursor_stmt, 0 );
397
+ key.write (key_data, key_data_size);
398
+ const char * value_data = reinterpret_cast <const char *>(sqlite3_column_blob (m_cursor_stmt, 1 ));
399
+ int value_data_size = sqlite3_column_bytes (m_cursor_stmt, 1 );
400
+ value.write (value_data, value_data_size);
401
+ return true ;
378
402
}
379
403
380
404
void SQLiteBatch::CloseCursor ()
381
405
{
406
+ sqlite3_reset (m_cursor_stmt);
407
+ m_cursor_init = false ;
382
408
}
383
409
384
410
bool SQLiteBatch::TxnBegin ()
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ class SQLiteBatch : public DatabaseBatch
18
18
private:
19
19
SQLiteDatabase& m_database;
20
20
21
+ bool m_cursor_init = false ;
22
+
21
23
sqlite3_stmt* m_read_stmt{nullptr };
22
24
sqlite3_stmt* m_insert_stmt{nullptr };
23
25
sqlite3_stmt* m_overwrite_stmt{nullptr };
You can’t perform that action at this time.
0 commit comments