MCPcopy Create free account
hub / github.com/ElementsProject/elements / Write

Method Write

src/leveldb/benchmarks/db_bench_sqlite3.cc:474–575  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472 }
473
474 void Write(bool write_sync, Order order, DBState state, int num_entries,
475 int value_size, int entries_per_batch) {
476 // Create new database if state == FRESH
477 if (state == FRESH) {
478 if (FLAGS_use_existing_db) {
479 message_ = "skipping (--use_existing_db is true)";
480 return;
481 }
482 sqlite3_close(db_);
483 db_ = nullptr;
484 Open();
485 Start();
486 }
487
488 if (num_entries != num_) {
489 char msg[100];
490 snprintf(msg, sizeof(msg), "(%d ops)", num_entries);
491 message_ = msg;
492 }
493
494 char* err_msg = nullptr;
495 int status;
496
497 sqlite3_stmt *replace_stmt, *begin_trans_stmt, *end_trans_stmt;
498 std::string replace_str = "REPLACE INTO test (key, value) VALUES (?, ?)";
499 std::string begin_trans_str = "BEGIN TRANSACTION;";
500 std::string end_trans_str = "END TRANSACTION;";
501
502 // Check for synchronous flag in options
503 std::string sync_stmt =
504 (write_sync) ? "PRAGMA synchronous = FULL" : "PRAGMA synchronous = OFF";
505 status = sqlite3_exec(db_, sync_stmt.c_str(), nullptr, nullptr, &err_msg);
506 ExecErrorCheck(status, err_msg);
507
508 // Preparing sqlite3 statements
509 status = sqlite3_prepare_v2(db_, replace_str.c_str(), -1, &replace_stmt,
510 nullptr);
511 ErrorCheck(status);
512 status = sqlite3_prepare_v2(db_, begin_trans_str.c_str(), -1,
513 &begin_trans_stmt, nullptr);
514 ErrorCheck(status);
515 status = sqlite3_prepare_v2(db_, end_trans_str.c_str(), -1, &end_trans_stmt,
516 nullptr);
517 ErrorCheck(status);
518
519 bool transaction = (entries_per_batch > 1);
520 for (int i = 0; i < num_entries; i += entries_per_batch) {
521 // Begin write transaction
522 if (FLAGS_transaction && transaction) {
523 status = sqlite3_step(begin_trans_stmt);
524 StepErrorCheck(status);
525 status = sqlite3_reset(begin_trans_stmt);
526 ErrorCheck(status);
527 }
528
529 // Create and execute SQL statements
530 for (int j = 0; j < entries_per_batch; j++) {
531 const char* value = gen_.Generate(value_size).data();

Callers

nothing calls this directly

Calls 6

ExecErrorCheckFunction · 0.85
ErrorCheckFunction · 0.85
StepErrorCheckFunction · 0.85
dataMethod · 0.45
GenerateMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected