Returns the estimation of disk space used by the specified sample blockid or all of the sample blocks if the blockid is 0. This does not include small overhead of the internal SQLite structures, only the size used by the data
| 2583 | // of the internal SQLite structures, only the size used by the data |
| 2584 | // |
| 2585 | int64_t ProjectFileIO::GetDiskUsage(DBConnection &conn, SampleBlockID blockid /* = 0 */) |
| 2586 | { |
| 2587 | sqlite3_stmt* stmt = nullptr; |
| 2588 | |
| 2589 | if (blockid == 0) |
| 2590 | { |
| 2591 | static const char* statement = |
| 2592 | R"(SELECT |
| 2593 | sum(length(blockid) + length(sampleformat) + |
| 2594 | length(summin) + length(summax) + length(sumrms) + |
| 2595 | length(summary256) + length(summary64k) + |
| 2596 | length(samples)) |
| 2597 | FROM sampleblocks;)"; |
| 2598 | |
| 2599 | stmt = conn.Prepare(DBConnection::GetAllSampleBlocksSize, statement); |
| 2600 | } |
| 2601 | else |
| 2602 | { |
| 2603 | static const char* statement = |
| 2604 | R"(SELECT |
| 2605 | length(blockid) + length(sampleformat) + |
| 2606 | length(summin) + length(summax) + length(sumrms) + |
| 2607 | length(summary256) + length(summary64k) + |
| 2608 | length(samples) |
| 2609 | FROM sampleblocks WHERE blockid = ?1;)"; |
| 2610 | |
| 2611 | stmt = conn.Prepare(DBConnection::GetSampleBlockSize, statement); |
| 2612 | } |
| 2613 | |
| 2614 | auto cleanup = finally( |
| 2615 | [stmt]() { |
| 2616 | // Clear statement bindings and rewind statement |
| 2617 | if (stmt != nullptr) |
| 2618 | { |
| 2619 | sqlite3_clear_bindings(stmt); |
| 2620 | sqlite3_reset(stmt); |
| 2621 | } |
| 2622 | }); |
| 2623 | |
| 2624 | if (blockid != 0) |
| 2625 | { |
| 2626 | int rc = sqlite3_bind_int64(stmt, 1, blockid); |
| 2627 | |
| 2628 | if (rc != SQLITE_OK) |
| 2629 | { |
| 2630 | ADD_EXCEPTION_CONTEXT( |
| 2631 | "sqlite3.rc", std::to_string(rc)); |
| 2632 | |
| 2633 | ADD_EXCEPTION_CONTEXT( |
| 2634 | "sqlite3.context", "ProjectFileIO::GetDiskUsage::bind"); |
| 2635 | |
| 2636 | conn.ThrowException(false); |
| 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | int rc = sqlite3_step(stmt); |
| 2641 | |
| 2642 | if (rc != SQLITE_ROW) |
nothing calls this directly
no test coverage detected