aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2020-05-26 20:53:46 -0400
committerAndrew Chow <achow101-github@achow101.com>2020-10-14 11:28:18 -0400
commitf6f9cd6a64842ef23777312f2465e826ca04b886 (patch)
tree296c59f7a55da61207e96812ee45d4d3580b0655 /src/wallet
parentbf90e033f4fe86cfb90492c7e0962278ea3a146d (diff)
downloadbitcoin-f6f9cd6a64842ef23777312f2465e826ca04b886.tar.xz
Implement SQLiteBatch::StartCursor, ReadAtCursor, and CloseCursor
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/sqlite.cpp30
-rw-r--r--src/wallet/sqlite.h2
2 files changed, 30 insertions, 2 deletions
diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp
index aae32e404e..d684eef87e 100644
--- a/src/wallet/sqlite.cpp
+++ b/src/wallet/sqlite.cpp
@@ -369,16 +369,42 @@ bool SQLiteBatch::HasKey(CDataStream&& key)
bool SQLiteBatch::StartCursor()
{
- return false;
+ assert(!m_cursor_init);
+ if (!m_database.m_db) return false;
+ m_cursor_init = true;
+ return true;
}
bool SQLiteBatch::ReadAtCursor(CDataStream& key, CDataStream& value, bool& complete)
{
- return false;
+ complete = false;
+
+ if (!m_cursor_init) return false;
+
+ int res = sqlite3_step(m_cursor_stmt);
+ if (res == SQLITE_DONE) {
+ complete = true;
+ return true;
+ }
+ if (res != SQLITE_ROW) {
+ LogPrintf("SQLiteBatch::ReadAtCursor: Unable to execute cursor step: %s\n", sqlite3_errstr(res));
+ return false;
+ }
+
+ // Leftmost column in result is index 0
+ const char* key_data = reinterpret_cast<const char*>(sqlite3_column_blob(m_cursor_stmt, 0));
+ int key_data_size = sqlite3_column_bytes(m_cursor_stmt, 0);
+ key.write(key_data, key_data_size);
+ const char* value_data = reinterpret_cast<const char*>(sqlite3_column_blob(m_cursor_stmt, 1));
+ int value_data_size = sqlite3_column_bytes(m_cursor_stmt, 1);
+ value.write(value_data, value_data_size);
+ return true;
}
void SQLiteBatch::CloseCursor()
{
+ sqlite3_reset(m_cursor_stmt);
+ m_cursor_init = false;
}
bool SQLiteBatch::TxnBegin()
diff --git a/src/wallet/sqlite.h b/src/wallet/sqlite.h
index 4d4dca1d20..dca6560abb 100644
--- a/src/wallet/sqlite.h
+++ b/src/wallet/sqlite.h
@@ -18,6 +18,8 @@ class SQLiteBatch : public DatabaseBatch
private:
SQLiteDatabase& m_database;
+ bool m_cursor_init = false;
+
sqlite3_stmt* m_read_stmt{nullptr};
sqlite3_stmt* m_insert_stmt{nullptr};
sqlite3_stmt* m_overwrite_stmt{nullptr};