upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/wallet_sqlite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet_sqlite.cpp')
-rw-r--r--src/wallet_sqlite.cpp43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/wallet_sqlite.cpp b/src/wallet_sqlite.cpp
index ca81573..f4b4b37 100644
--- a/src/wallet_sqlite.cpp
+++ b/src/wallet_sqlite.cpp
@@ -156,7 +156,8 @@ bool CWalletDBSQLite::InitSchema(string& strError)
156 156
157bool CWalletDBSQLite::WriteRecord(const vector<unsigned char>& vchKey, 157bool CWalletDBSQLite::WriteRecord(const vector<unsigned char>& vchKey,
158 const vector<unsigned char>& vchValue, 158 const vector<unsigned char>& vchValue,
159 string& strError) 159 string& strError,
160 bool fOverwrite)
160{ 161{
161 if (!pdb) 162 if (!pdb)
162 { 163 {
@@ -170,8 +171,9 @@ bool CWalletDBSQLite::WriteRecord(const vector<unsigned char>& vchKey,
170 } 171 }
171 172
172 sqlite3_stmt* stmt = NULL; 173 sqlite3_stmt* stmt = NULL;
173 const char* pszSql = 174 const char* pszSql = fOverwrite
174 "INSERT OR REPLACE INTO wallet_records(key, value) VALUES(?, ?);"; 175 ? "INSERT OR REPLACE INTO wallet_records(key, value) VALUES(?, ?);"
176 : "INSERT INTO wallet_records(key, value) VALUES(?, ?);";
175 int ret = sqlite3_prepare_v2(pdb, pszSql, -1, &stmt, NULL); 177 int ret = sqlite3_prepare_v2(pdb, pszSql, -1, &stmt, NULL);
176 if (ret != SQLITE_OK) 178 if (ret != SQLITE_OK)
177 { 179 {
@@ -250,6 +252,41 @@ bool CWalletDBSQLite::ReadRecord(const vector<unsigned char>& vchKey,
250 return false; 252 return false;
251} 253}
252 254
255bool CWalletDBSQLite::EraseRecord(const vector<unsigned char>& vchKey,
256 string& strError)
257{
258 if (!pdb)
259 {
260 strError = "SQLite wallet is not open";
261 return false;
262 }
263 if (vchKey.empty())
264 {
265 strError = "SQLite wallet record key is empty";
266 return false;
267 }
268
269 sqlite3_stmt* stmt = NULL;
270 const char* pszSql = "DELETE FROM wallet_records WHERE key = ?;";
271 int ret = sqlite3_prepare_v2(pdb, pszSql, -1, &stmt, NULL);
272 if (ret != SQLITE_OK)
273 {
274 SetSQLiteError(pdb, "cannot prepare SQLite wallet erase", strError);
275 return false;
276 }
277
278 ret = sqlite3_bind_blob(stmt, 1, &vchKey[0], (int)vchKey.size(),
279 SQLITE_TRANSIENT);
280 if (ret == SQLITE_OK)
281 ret = sqlite3_step(stmt);
282
283 bool fOk = (ret == SQLITE_DONE);
284 if (!fOk)
285 SetSQLiteError(pdb, "cannot erase SQLite wallet record", strError);
286 sqlite3_finalize(stmt);
287 return fOk;
288}
289
253bool CWalletDBSQLite::ScanRecords(CWalletRecordVisitor& visitor, 290bool CWalletDBSQLite::ScanRecords(CWalletRecordVisitor& visitor,
254 string& strError) 291 string& strError)
255{ 292{