diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2023-05-31 15:22:50 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-05-31 15:24:06 -0400 |
commit | 1d858b055daeea363e0450f327672658548be4c6 (patch) | |
tree | 549e34a4833228c50d39deb7abca9bb8e3243fec /src/wallet/sqlite.cpp | |
parent | 84b2f353bbefb9264284e7430863b2fa1d796d38 (diff) | |
download | bitcoin-1d858b055daeea363e0450f327672658548be4c6.tar.xz |
walletdb: Handle when database keys are empty
Diffstat (limited to 'src/wallet/sqlite.cpp')
-rw-r--r-- | src/wallet/sqlite.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp index 7621f2476b..55245707ed 100644 --- a/src/wallet/sqlite.cpp +++ b/src/wallet/sqlite.cpp @@ -39,7 +39,11 @@ static bool BindBlobToStatement(sqlite3_stmt* stmt, Span<const std::byte> blob, const std::string& description) { - int res = sqlite3_bind_blob(stmt, index, blob.data(), blob.size(), SQLITE_STATIC); + // Pass a pointer to the empty string "" below instead of passing the + // blob.data() pointer if the blob.data() pointer is null. Passing a null + // data pointer to bind_blob would cause sqlite to bind the SQL NULL value + // instead of the empty blob value X'', which would mess up SQL comparisons. + int res = sqlite3_bind_blob(stmt, index, blob.data() ? static_cast<const void*>(blob.data()) : "", blob.size(), SQLITE_STATIC); if (res != SQLITE_OK) { LogPrintf("Unable to bind %s to statement: %s\n", description, sqlite3_errstr(res)); sqlite3_clear_bindings(stmt); |