| 575 | } |
| 576 | |
| 577 | void Read(Order order, int entries_per_batch) { |
| 578 | int status; |
| 579 | sqlite3_stmt *read_stmt, *begin_trans_stmt, *end_trans_stmt; |
| 580 | |
| 581 | std::string read_str = "SELECT * FROM test WHERE key = ?"; |
| 582 | std::string begin_trans_str = "BEGIN TRANSACTION;"; |
| 583 | std::string end_trans_str = "END TRANSACTION;"; |
| 584 | |
| 585 | // Preparing sqlite3 statements |
| 586 | status = sqlite3_prepare_v2(db_, begin_trans_str.c_str(), -1, |
| 587 | &begin_trans_stmt, nullptr); |
| 588 | ErrorCheck(status); |
| 589 | status = sqlite3_prepare_v2(db_, end_trans_str.c_str(), -1, &end_trans_stmt, |
| 590 | nullptr); |
| 591 | ErrorCheck(status); |
| 592 | status = sqlite3_prepare_v2(db_, read_str.c_str(), -1, &read_stmt, nullptr); |
| 593 | ErrorCheck(status); |
| 594 | |
| 595 | bool transaction = (entries_per_batch > 1); |
| 596 | for (int i = 0; i < reads_; i += entries_per_batch) { |
| 597 | // Begin read transaction |
| 598 | if (FLAGS_transaction && transaction) { |
| 599 | status = sqlite3_step(begin_trans_stmt); |
| 600 | StepErrorCheck(status); |
| 601 | status = sqlite3_reset(begin_trans_stmt); |
| 602 | ErrorCheck(status); |
| 603 | } |
| 604 | |
| 605 | // Create and execute SQL statements |
| 606 | for (int j = 0; j < entries_per_batch; j++) { |
| 607 | // Create key value |
| 608 | char key[100]; |
| 609 | int k = (order == SEQUENTIAL) ? i + j : (rand_.Next() % reads_); |
| 610 | snprintf(key, sizeof(key), "%016d", k); |
| 611 | |
| 612 | // Bind key value into read_stmt |
| 613 | status = sqlite3_bind_blob(read_stmt, 1, key, 16, SQLITE_STATIC); |
| 614 | ErrorCheck(status); |
| 615 | |
| 616 | // Execute read statement |
| 617 | while ((status = sqlite3_step(read_stmt)) == SQLITE_ROW) { |
| 618 | } |
| 619 | StepErrorCheck(status); |
| 620 | |
| 621 | // Reset SQLite statement for another use |
| 622 | status = sqlite3_clear_bindings(read_stmt); |
| 623 | ErrorCheck(status); |
| 624 | status = sqlite3_reset(read_stmt); |
| 625 | ErrorCheck(status); |
| 626 | FinishedSingleOp(); |
| 627 | } |
| 628 | |
| 629 | // End read transaction |
| 630 | if (FLAGS_transaction && transaction) { |
| 631 | status = sqlite3_step(end_trans_stmt); |
| 632 | StepErrorCheck(status); |
| 633 | status = sqlite3_reset(end_trans_stmt); |
| 634 | ErrorCheck(status); |
nothing calls this directly
no test coverage detected