| 700 | } |
| 701 | |
| 702 | void SqliteSampleBlock::Load(SampleBlockID sbid) |
| 703 | { |
| 704 | auto db = DB(); |
| 705 | int rc; |
| 706 | |
| 707 | wxASSERT(sbid > 0); |
| 708 | |
| 709 | mValid = false; |
| 710 | mSampleCount = 0; |
| 711 | mSampleBytes = 0; |
| 712 | mSumMin = FLT_MAX; |
| 713 | mSumMax = -FLT_MAX; |
| 714 | mSumMin = 0.0; |
| 715 | |
| 716 | // Prepare and cache statement...automatically finalized at DB close |
| 717 | sqlite3_stmt *stmt = Conn()->Prepare(DBConnection::LoadSampleBlock, |
| 718 | "SELECT sampleformat, summin, summax, sumrms," |
| 719 | " length(samples)" |
| 720 | " FROM sampleblocks WHERE blockid = ?1;"); |
| 721 | |
| 722 | // Bind statement parameters |
| 723 | // Might return SQLITE_MISUSE which means it's our mistake that we violated |
| 724 | // preconditions; should return SQL_OK which is 0 |
| 725 | if (sqlite3_bind_int64(stmt, 1, sbid)) |
| 726 | { |
| 727 | |
| 728 | ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(sqlite3_errcode(Conn()->DB()))); |
| 729 | ADD_EXCEPTION_CONTEXT("sqlite3.context", "SqliteSampleBlock::Load::bind"); |
| 730 | |
| 731 | wxASSERT_MSG(false, wxT("Binding failed...bug!!!")); |
| 732 | } |
| 733 | |
| 734 | // Execute the statement |
| 735 | rc = sqlite3_step(stmt); |
| 736 | if (rc != SQLITE_ROW) |
| 737 | { |
| 738 | |
| 739 | ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc)); |
| 740 | ADD_EXCEPTION_CONTEXT("sqlite3.context", "SqliteSampleBlock::Load::step"); |
| 741 | |
| 742 | |
| 743 | wxLogDebug(wxT("SqliteSampleBlock::Load - SQLITE error %s"), sqlite3_errmsg(db)); |
| 744 | |
| 745 | // Clear statement bindings and rewind statement |
| 746 | sqlite3_clear_bindings(stmt); |
| 747 | sqlite3_reset(stmt); |
| 748 | |
| 749 | // Just showing the user a simple message, not the library error too |
| 750 | // which isn't internationalized |
| 751 | Conn()->ThrowException( false ); |
| 752 | } |
| 753 | |
| 754 | // Retrieve returned data |
| 755 | mBlockID = sbid; |
| 756 | mSampleFormat = (sampleFormat) sqlite3_column_int(stmt, 0); |
| 757 | mSumMin = sqlite3_column_double(stmt, 1); |
| 758 | mSumMax = sqlite3_column_double(stmt, 2); |
| 759 | mSumRms = sqlite3_column_double(stmt, 3); |
no test coverage detected