Bitcoin ABC 0.30.5
P2P Digital Currency
sqlite.cpp
Go to the documentation of this file.
1// Copyright (c) 2020 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <wallet/sqlite.h>
6
7#include <logging.h>
8#include <sync.h>
9#include <util/fs_helpers.h>
10#include <util/strencodings.h>
11#include <util/translation.h>
12#include <wallet/db.h>
13
14#include <cstdint>
15#include <sqlite3.h>
16
17static const char *const DATABASE_FILENAME = "wallet.dat";
18
20static int g_sqlite_count GUARDED_BY(g_sqlite_mutex) = 0;
21
22static void ErrorLogCallback(void *arg, int code, const char *msg) {
23 // From sqlite3_config() documentation for the SQLITE_CONFIG_LOG option:
24 // "The void pointer that is the second argument to SQLITE_CONFIG_LOG is
25 // passed through as the first parameter to the application-defined logger
26 // function whenever that function is invoked."
27 // Assert that this is the case:
28 assert(arg == nullptr);
29 LogPrintf("SQLite Error. Code: %d. Message: %s\n", code, msg);
30}
31
33 const fs::path &file_path, bool mock)
34 : WalletDatabase(), m_mock(mock), m_dir_path(fs::PathToString(dir_path)),
35 m_file_path(fs::PathToString(file_path)) {
36 {
38 LogPrintf("Using SQLite Version %s\n", SQLiteDatabaseVersion());
39 LogPrintf("Using wallet %s\n", m_dir_path);
40
41 if (++g_sqlite_count == 1) {
42 // Setup logging
43 int ret =
44 sqlite3_config(SQLITE_CONFIG_LOG, ErrorLogCallback, nullptr);
45 if (ret != SQLITE_OK) {
46 throw std::runtime_error(
47 strprintf("SQLiteDatabase: Failed to setup error log: %s\n",
48 sqlite3_errstr(ret)));
49 }
50 }
51 // This is a no-op if sqlite3 is already initialized
52 int ret = sqlite3_initialize();
53 if (ret != SQLITE_OK) {
54 throw std::runtime_error(
55 strprintf("SQLiteDatabase: Failed to initialize SQLite: %s\n",
56 sqlite3_errstr(ret)));
57 }
58 }
59
60 try {
61 Open();
62 } catch (const std::runtime_error &) {
63 // If open fails, cleanup this object and rethrow the exception
64 Cleanup();
65 throw;
66 }
67}
68
70 int res;
71 if (!m_read_stmt) {
72 if ((res = sqlite3_prepare_v2(
73 m_database.m_db, "SELECT value FROM main WHERE key = ?", -1,
74 &m_read_stmt, nullptr)) != SQLITE_OK) {
75 throw std::runtime_error(strprintf(
76 "SQLiteDatabase: Failed to setup SQL statements: %s\n",
77 sqlite3_errstr(res)));
78 }
79 }
80 if (!m_insert_stmt) {
81 if ((res = sqlite3_prepare_v2(m_database.m_db,
82 "INSERT INTO main VALUES(?, ?)", -1,
83 &m_insert_stmt, nullptr)) != SQLITE_OK) {
84 throw std::runtime_error(strprintf(
85 "SQLiteDatabase: Failed to setup SQL statements: %s\n",
86 sqlite3_errstr(res)));
87 }
88 }
89 if (!m_overwrite_stmt) {
90 if ((res = sqlite3_prepare_v2(
91 m_database.m_db, "INSERT or REPLACE into main values(?, ?)",
92 -1, &m_overwrite_stmt, nullptr)) != SQLITE_OK) {
93 throw std::runtime_error(strprintf(
94 "SQLiteDatabase: Failed to setup SQL statements: %s\n",
95 sqlite3_errstr(res)));
96 }
97 }
98 if (!m_delete_stmt) {
99 if ((res = sqlite3_prepare_v2(m_database.m_db,
100 "DELETE FROM main WHERE key = ?", -1,
101 &m_delete_stmt, nullptr)) != SQLITE_OK) {
102 throw std::runtime_error(strprintf(
103 "SQLiteDatabase: Failed to setup SQL statements: %s\n",
104 sqlite3_errstr(res)));
105 }
106 }
107 if (!m_cursor_stmt) {
108 if ((res = sqlite3_prepare_v2(m_database.m_db,
109 "SELECT key, value FROM main", -1,
110 &m_cursor_stmt, nullptr)) != SQLITE_OK) {
111 throw std::runtime_error(strprintf(
112 "SQLiteDatabase: Failed to setup SQL statements : %s\n",
113 sqlite3_errstr(res)));
114 }
115 }
116}
117
119 Cleanup();
120}
121
122void SQLiteDatabase::Cleanup() noexcept {
123 Close();
124
126 if (--g_sqlite_count == 0) {
127 int ret = sqlite3_shutdown();
128 if (ret != SQLITE_OK) {
129 LogPrintf("SQLiteDatabase: Failed to shutdown SQLite: %s\n",
130 sqlite3_errstr(ret));
131 }
132 }
133}
134
136 assert(m_db);
137
138 sqlite3_stmt *stmt{nullptr};
139 int ret =
140 sqlite3_prepare_v2(m_db, "PRAGMA integrity_check", -1, &stmt, nullptr);
141 if (ret != SQLITE_OK) {
142 sqlite3_finalize(stmt);
143 error = strprintf(_("SQLiteDatabase: Failed to prepare statement to "
144 "verify database: %s"),
145 sqlite3_errstr(ret));
146 return false;
147 }
148 while (true) {
149 ret = sqlite3_step(stmt);
150 if (ret == SQLITE_DONE) {
151 break;
152 }
153 if (ret != SQLITE_ROW) {
154 error = strprintf(_("SQLiteDatabase: Failed to execute statement "
155 "to verify database: %s"),
156 sqlite3_errstr(ret));
157 break;
158 }
159 const char *msg = (const char *)sqlite3_column_text(stmt, 0);
160 if (!msg) {
161 error = strprintf(_("SQLiteDatabase: Failed to read database "
162 "verification error: %s"),
163 sqlite3_errstr(ret));
164 break;
165 }
166 std::string str_msg(msg);
167 if (str_msg == "ok") {
168 continue;
169 }
170 if (error.empty()) {
171 error = _("Failed to verify database") + Untranslated("\n");
172 }
173 error += Untranslated(strprintf("%s\n", str_msg));
174 }
175 sqlite3_finalize(stmt);
176 return error.empty();
177}
178
180 int flags =
181 SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
182 if (m_mock) {
183 // In memory database for mock db
184 flags |= SQLITE_OPEN_MEMORY;
185 }
186
187 if (m_db == nullptr) {
189 int ret = sqlite3_open_v2(m_file_path.c_str(), &m_db, flags, nullptr);
190 if (ret != SQLITE_OK) {
191 throw std::runtime_error(
192 strprintf("SQLiteDatabase: Failed to open database: %s\n",
193 sqlite3_errstr(ret)));
194 }
195 }
196
197 if (sqlite3_db_readonly(m_db, "main") != 0) {
198 throw std::runtime_error("SQLiteDatabase: Database opened in readonly "
199 "mode but read-write permissions are needed");
200 }
201
202 // Acquire an exclusive lock on the database
203 // First change the locking mode to exclusive
204 int ret = sqlite3_exec(m_db, "PRAGMA locking_mode = exclusive", nullptr,
205 nullptr, nullptr);
206 if (ret != SQLITE_OK) {
207 throw std::runtime_error(
208 strprintf("SQLiteDatabase: Unable to change database locking mode "
209 "to exclusive: %s\n",
210 sqlite3_errstr(ret)));
211 }
212 // Now begin a transaction to acquire the exclusive lock. This lock won't be
213 // released until we close because of the exclusive locking mode.
214 ret = sqlite3_exec(m_db, "BEGIN EXCLUSIVE TRANSACTION", nullptr, nullptr,
215 nullptr);
216 if (ret != SQLITE_OK) {
217 throw std::runtime_error(
218 "SQLiteDatabase: Unable to obtain an exclusive lock on the "
219 "database, is it being used by another bitcoind?\n");
220 }
221 ret = sqlite3_exec(m_db, "COMMIT", nullptr, nullptr, nullptr);
222 if (ret != SQLITE_OK) {
223 throw std::runtime_error(strprintf(
224 "SQLiteDatabase: Unable to end exclusive lock transaction: %s\n",
225 sqlite3_errstr(ret)));
226 }
227
228 // Enable fullfsync for the platforms that use it
229 ret = sqlite3_exec(m_db, "PRAGMA fullfsync = true", nullptr, nullptr,
230 nullptr);
231 if (ret != SQLITE_OK) {
232 throw std::runtime_error(
233 strprintf("SQLiteDatabase: Failed to enable fullfsync: %s\n",
234 sqlite3_errstr(ret)));
235 }
236
237 // Make the table for our key-value pairs
238 // First check that the main table exists
239 sqlite3_stmt *check_main_stmt{nullptr};
240 ret = sqlite3_prepare_v2(
241 m_db,
242 "SELECT name FROM sqlite_master WHERE type='table' AND name='main'", -1,
243 &check_main_stmt, nullptr);
244 if (ret != SQLITE_OK) {
245 throw std::runtime_error(
246 strprintf("SQLiteDatabase: Failed to prepare statement to check "
247 "table existence: %s\n",
248 sqlite3_errstr(ret)));
249 }
250 ret = sqlite3_step(check_main_stmt);
251 if (sqlite3_finalize(check_main_stmt) != SQLITE_OK) {
252 throw std::runtime_error(
253 strprintf("SQLiteDatabase: Failed to finalize statement checking "
254 "table existence: %s\n",
255 sqlite3_errstr(ret)));
256 }
257 bool table_exists;
258 if (ret == SQLITE_DONE) {
259 table_exists = false;
260 } else if (ret == SQLITE_ROW) {
261 table_exists = true;
262 } else {
263 throw std::runtime_error(
264 strprintf("SQLiteDatabase: Failed to execute statement to check "
265 "table existence: %s\n",
266 sqlite3_errstr(ret)));
267 }
268
269 // Do the db setup things because the table doesn't exist only when we are
270 // creating a new wallet
271 if (!table_exists) {
272 ret = sqlite3_exec(m_db,
273 "CREATE TABLE main(key BLOB PRIMARY KEY NOT NULL, "
274 "value BLOB NOT NULL)",
275 nullptr, nullptr, nullptr);
276 if (ret != SQLITE_OK) {
277 throw std::runtime_error(
278 strprintf("SQLiteDatabase: Failed to create new database: %s\n",
279 sqlite3_errstr(ret)));
280 }
281 }
282}
283
284bool SQLiteDatabase::Rewrite(const char *skip) {
285 // Rewrite the database using the VACUUM command:
286 // https://sqlite.org/lang_vacuum.html
287 int ret = sqlite3_exec(m_db, "VACUUM", nullptr, nullptr, nullptr);
288 return ret == SQLITE_OK;
289}
290
291bool SQLiteDatabase::Backup(const std::string &dest) const {
292 sqlite3 *db_copy;
293 int res = sqlite3_open(dest.c_str(), &db_copy);
294 if (res != SQLITE_OK) {
295 sqlite3_close(db_copy);
296 return false;
297 }
298 sqlite3_backup *backup = sqlite3_backup_init(db_copy, "main", m_db, "main");
299 if (!backup) {
300 LogPrintf("%s: Unable to begin backup: %s\n", __func__,
301 sqlite3_errmsg(m_db));
302 sqlite3_close(db_copy);
303 return false;
304 }
305 // Specifying -1 will copy all of the pages
306 res = sqlite3_backup_step(backup, -1);
307 if (res != SQLITE_DONE) {
308 LogPrintf("%s: Unable to backup: %s\n", __func__, sqlite3_errstr(res));
309 sqlite3_backup_finish(backup);
310 sqlite3_close(db_copy);
311 return false;
312 }
313 res = sqlite3_backup_finish(backup);
314 sqlite3_close(db_copy);
315 return res == SQLITE_OK;
316}
317
319 int res = sqlite3_close(m_db);
320 if (res != SQLITE_OK) {
321 throw std::runtime_error(
322 strprintf("SQLiteDatabase: Failed to close database: %s\n",
323 sqlite3_errstr(res)));
324 }
325 m_db = nullptr;
326}
327
328std::unique_ptr<DatabaseBatch> SQLiteDatabase::MakeBatch(bool flush_on_close) {
329 // We ignore flush_on_close because we don't do manual flushing for SQLite
330 return std::make_unique<SQLiteBatch>(*this);
331}
332
333SQLiteBatch::SQLiteBatch(SQLiteDatabase &database) : m_database(database) {
334 // Make sure we have a db handle
336
338}
339
341 // If m_db is in a transaction (i.e. not in autocommit mode), then abort the
342 // transaction in progress
343 if (m_database.m_db && sqlite3_get_autocommit(m_database.m_db) == 0) {
344 if (TxnAbort()) {
345 LogPrintf("SQLiteBatch: Batch closed unexpectedly without the "
346 "transaction being explicitly committed or aborted\n");
347 } else {
348 LogPrintf(
349 "SQLiteBatch: Batch closed and failed to abort transaction\n");
350 }
351 }
352
353 // Free all of the prepared statements
354 int ret = sqlite3_finalize(m_read_stmt);
355 if (ret != SQLITE_OK) {
356 LogPrintf("SQLiteBatch: Batch closed but could not finalize read "
357 "statement: %s\n",
358 sqlite3_errstr(ret));
359 }
360 ret = sqlite3_finalize(m_insert_stmt);
361 if (ret != SQLITE_OK) {
362 LogPrintf("SQLiteBatch: Batch closed but could not finalize insert "
363 "statement: %s\n",
364 sqlite3_errstr(ret));
365 }
366 ret = sqlite3_finalize(m_overwrite_stmt);
367 if (ret != SQLITE_OK) {
368 LogPrintf("SQLiteBatch: Batch closed but could not finalize overwrite "
369 "statement: %s\n",
370 sqlite3_errstr(ret));
371 }
372 ret = sqlite3_finalize(m_delete_stmt);
373 if (ret != SQLITE_OK) {
374 LogPrintf("SQLiteBatch: Batch closed but could not finalize delete "
375 "statement: %s\n",
376 sqlite3_errstr(ret));
377 }
378 ret = sqlite3_finalize(m_cursor_stmt);
379 if (ret != SQLITE_OK) {
380 LogPrintf("SQLiteBatch: Batch closed but could not finalize cursor "
381 "statement: %s\n",
382 sqlite3_errstr(ret));
383 }
384 m_read_stmt = nullptr;
385 m_insert_stmt = nullptr;
386 m_overwrite_stmt = nullptr;
387 m_delete_stmt = nullptr;
388 m_cursor_stmt = nullptr;
389}
390
392 if (!m_database.m_db) {
393 return false;
394 }
396
397 // Bind: leftmost parameter in statement is index 1
398 int res = sqlite3_bind_blob(m_read_stmt, 1, key.data(), key.size(),
399 SQLITE_STATIC);
400 if (res != SQLITE_OK) {
401 LogPrintf("%s: Unable to bind statement: %s\n", __func__,
402 sqlite3_errstr(res));
403 sqlite3_clear_bindings(m_read_stmt);
404 sqlite3_reset(m_read_stmt);
405 return false;
406 }
407 res = sqlite3_step(m_read_stmt);
408 if (res != SQLITE_ROW) {
409 if (res != SQLITE_DONE) {
410 // SQLITE_DONE means "not found", don't log an error in that case.
411 LogPrintf("%s: Unable to execute statement: %s\n", __func__,
412 sqlite3_errstr(res));
413 }
414 sqlite3_clear_bindings(m_read_stmt);
415 sqlite3_reset(m_read_stmt);
416 return false;
417 }
418 // Leftmost column in result is index 0
419 const std::byte *data{BytePtr(sqlite3_column_blob(m_read_stmt, 0))};
420 size_t data_size(sqlite3_column_bytes(m_read_stmt, 0));
421 value.write({data, data_size});
422
423 sqlite3_clear_bindings(m_read_stmt);
424 sqlite3_reset(m_read_stmt);
425 return true;
426}
427
429 bool overwrite) {
430 if (!m_database.m_db) {
431 return false;
432 }
434
435 sqlite3_stmt *stmt;
436 if (overwrite) {
437 stmt = m_overwrite_stmt;
438 } else {
439 stmt = m_insert_stmt;
440 }
441
442 // Bind: leftmost parameter in statement is index 1
443 // Insert index 1 is key, 2 is value
444 int res = sqlite3_bind_blob(stmt, 1, key.data(), key.size(), SQLITE_STATIC);
445 if (res != SQLITE_OK) {
446 LogPrintf("%s: Unable to bind key to statement: %s\n", __func__,
447 sqlite3_errstr(res));
448 sqlite3_clear_bindings(stmt);
449 sqlite3_reset(stmt);
450 return false;
451 }
452 res = sqlite3_bind_blob(stmt, 2, value.data(), value.size(), SQLITE_STATIC);
453 if (res != SQLITE_OK) {
454 LogPrintf("%s: Unable to bind value to statement: %s\n", __func__,
455 sqlite3_errstr(res));
456 sqlite3_clear_bindings(stmt);
457 sqlite3_reset(stmt);
458 return false;
459 }
460
461 // Execute
462 res = sqlite3_step(stmt);
463 sqlite3_clear_bindings(stmt);
464 sqlite3_reset(stmt);
465 if (res != SQLITE_DONE) {
466 LogPrintf("%s: Unable to execute statement: %s\n", __func__,
467 sqlite3_errstr(res));
468 }
469 return res == SQLITE_DONE;
470}
471
473 if (!m_database.m_db) {
474 return false;
475 }
477
478 // Bind: leftmost parameter in statement is index 1
479 int res = sqlite3_bind_blob(m_delete_stmt, 1, key.data(), key.size(),
480 SQLITE_STATIC);
481 if (res != SQLITE_OK) {
482 LogPrintf("%s: Unable to bind statement: %s\n", __func__,
483 sqlite3_errstr(res));
484 sqlite3_clear_bindings(m_delete_stmt);
485 sqlite3_reset(m_delete_stmt);
486 return false;
487 }
488
489 // Execute
490 res = sqlite3_step(m_delete_stmt);
491 sqlite3_clear_bindings(m_delete_stmt);
492 sqlite3_reset(m_delete_stmt);
493 if (res != SQLITE_DONE) {
494 LogPrintf("%s: Unable to execute statement: %s\n", __func__,
495 sqlite3_errstr(res));
496 }
497 return res == SQLITE_DONE;
498}
499
501 if (!m_database.m_db) {
502 return false;
503 }
505
506 // Bind: leftmost parameter in statement is index 1
507 bool ret = false;
508 int res = sqlite3_bind_blob(m_read_stmt, 1, key.data(), key.size(),
509 SQLITE_STATIC);
510 if (res == SQLITE_OK) {
511 res = sqlite3_step(m_read_stmt);
512 if (res == SQLITE_ROW) {
513 ret = true;
514 }
515 }
516
517 sqlite3_clear_bindings(m_read_stmt);
518 sqlite3_reset(m_read_stmt);
519 return ret;
520}
521
524 if (!m_database.m_db) {
525 return false;
526 }
527 m_cursor_init = true;
528 return true;
529}
530
532 bool &complete) {
533 complete = false;
534
535 if (!m_cursor_init) {
536 return false;
537 }
538
539 int res = sqlite3_step(m_cursor_stmt);
540 if (res == SQLITE_DONE) {
541 complete = true;
542 return true;
543 }
544 if (res != SQLITE_ROW) {
545 LogPrintf(
546 "SQLiteBatch::ReadAtCursor: Unable to execute cursor step: %s\n",
547 sqlite3_errstr(res));
548 return false;
549 }
550
551 // Leftmost column in result is index 0
552 const std::byte *key_data{BytePtr(sqlite3_column_blob(m_cursor_stmt, 0))};
553 size_t key_data_size(sqlite3_column_bytes(m_cursor_stmt, 0));
554 key.write({key_data, key_data_size});
555 const std::byte *value_data{BytePtr(sqlite3_column_blob(m_cursor_stmt, 1))};
556 size_t value_data_size(sqlite3_column_bytes(m_cursor_stmt, 1));
557 value.write({value_data, value_data_size});
558 return true;
559}
560
562 sqlite3_reset(m_cursor_stmt);
563 m_cursor_init = false;
564}
565
567 if (!m_database.m_db || sqlite3_get_autocommit(m_database.m_db) == 0) {
568 return false;
569 }
570 int res = sqlite3_exec(m_database.m_db, "BEGIN TRANSACTION", nullptr,
571 nullptr, nullptr);
572 if (res != SQLITE_OK) {
573 LogPrintf("SQLiteBatch: Failed to begin the transaction\n");
574 }
575 return res == SQLITE_OK;
576}
577
579 if (!m_database.m_db || sqlite3_get_autocommit(m_database.m_db) != 0) {
580 return false;
581 }
582 int res = sqlite3_exec(m_database.m_db, "COMMIT TRANSACTION", nullptr,
583 nullptr, nullptr);
584 if (res != SQLITE_OK) {
585 LogPrintf("SQLiteBatch: Failed to commit the transaction\n");
586 }
587 return res == SQLITE_OK;
588}
589
591 if (!m_database.m_db || sqlite3_get_autocommit(m_database.m_db) != 0) {
592 return false;
593 }
594 int res = sqlite3_exec(m_database.m_db, "ROLLBACK TRANSACTION", nullptr,
595 nullptr, nullptr);
596 if (res != SQLITE_OK) {
597 LogPrintf("SQLiteBatch: Failed to abort the transaction\n");
598 }
599 return res == SQLITE_OK;
600}
601
603 return false;
604}
605
606std::unique_ptr<SQLiteDatabase>
607MakeSQLiteDatabase(const fs::path &path, const DatabaseOptions &options,
609 const fs::path file = path / DATABASE_FILENAME;
610 try {
611 auto db = std::make_unique<SQLiteDatabase>(path, file);
612 if (options.verify && !db->Verify(error)) {
614 return nullptr;
615 }
616 return db;
617 } catch (const std::runtime_error &e) {
619 error.original = e.what();
620 return nullptr;
621 }
622}
623
625 return std::string(sqlite3_libversion());
626}
int flags
Definition: bitcoin-tx.cpp:541
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:177
void write(Span< const value_type > src)
Definition: streams.h:379
Different type to mark Mutex at global scope.
Definition: sync.h:144
bool WriteKey(CDataStream &&key, CDataStream &&value, bool overwrite=true) override
Definition: sqlite.cpp:428
sqlite3_stmt * m_read_stmt
Definition: sqlite.h:22
bool TxnAbort() override
Definition: sqlite.cpp:590
bool m_cursor_init
Definition: sqlite.h:20
sqlite3_stmt * m_cursor_stmt
Definition: sqlite.h:26
void SetupSQLStatements()
Definition: sqlite.cpp:69
bool HasKey(CDataStream &&key) override
Definition: sqlite.cpp:500
sqlite3_stmt * m_insert_stmt
Definition: sqlite.h:23
sqlite3_stmt * m_overwrite_stmt
Definition: sqlite.h:24
bool StartCursor() override
Definition: sqlite.cpp:522
bool EraseKey(CDataStream &&key) override
Definition: sqlite.cpp:472
bool ReadAtCursor(CDataStream &key, CDataStream &value, bool &complete) override
Definition: sqlite.cpp:531
bool TxnBegin() override
Definition: sqlite.cpp:566
void Close() override
Definition: sqlite.cpp:340
sqlite3_stmt * m_delete_stmt
Definition: sqlite.h:25
bool ReadKey(CDataStream &&key, CDataStream &value) override
Definition: sqlite.cpp:391
bool TxnCommit() override
Definition: sqlite.cpp:578
SQLiteDatabase & m_database
Definition: sqlite.h:18
void CloseCursor() override
Definition: sqlite.cpp:561
SQLiteBatch(SQLiteDatabase &database)
Definition: sqlite.cpp:333
An instance of this class represents one SQLite3 database.
Definition: sqlite.h:55
void Close() override
Close the database.
Definition: sqlite.cpp:318
void Open() override
Open the database if it is not already opened.
Definition: sqlite.cpp:179
sqlite3 * m_db
Definition: sqlite.h:114
std::unique_ptr< DatabaseBatch > MakeBatch(bool flush_on_close=true) override
Make a SQLiteBatch connected to this database.
Definition: sqlite.cpp:328
const std::string m_dir_path
Definition: sqlite.h:59
void Cleanup() noexcept
Definition: sqlite.cpp:122
bool Verify(bilingual_str &error)
Definition: sqlite.cpp:135
SQLiteDatabase()=delete
const bool m_mock
Definition: sqlite.h:57
const std::string m_file_path
Definition: sqlite.h:61
bool Backup(const std::string &dest) const override
Back up the entire database to a file.
Definition: sqlite.cpp:291
bool Rewrite(const char *skip=nullptr) override
Rewrite the entire database on disk.
Definition: sqlite.cpp:284
An instance of this class represents one database.
Definition: db.h:100
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
Definition: fs_helpers.cpp:287
bool error(const char *fmt, const Args &...args)
Definition: logging.h:226
#define LogPrintf(...)
Definition: logging.h:207
Filesystem operations and types.
Definition: fs.h:20
static std::string PathToString(const path &path)
Convert path object to byte string.
Definition: fs.h:142
static path PathFromString(const std::string &string)
Convert byte string to path object.
Definition: fs.h:165
CAddrDb db
Definition: main.cpp:35
const std::byte * BytePtr(const void *data)
Convert a data pointer to a std::byte data pointer.
Definition: span.h:286
static void ErrorLogCallback(void *arg, int code, const char *msg)
Definition: sqlite.cpp:22
std::string SQLiteDatabaseVersion()
Definition: sqlite.cpp:624
static GlobalMutex g_sqlite_mutex
Definition: sqlite.cpp:19
std::unique_ptr< SQLiteDatabase > MakeSQLiteDatabase(const fs::path &path, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error)
Definition: sqlite.cpp:607
static const char *const DATABASE_FILENAME
Definition: sqlite.cpp:17
bool ExistsSQLiteDatabase(const fs::path &path)
Definition: sqlite.cpp:602
static int g_sqlite_count GUARDED_BY(g_sqlite_mutex)=0
bool verify
Definition: db.h:226
Bilingual messages:
Definition: translation.h:17
#define LOCK(cs)
Definition: sync.h:306
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:68
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:36
assert(!tx.IsCoinBase())
DatabaseStatus
Definition: db.h:229