diff --git a/src/DBConnection.cpp b/src/DBConnection.cpp index 54cd5a652..967f1b471 100644 --- a/src/DBConnection.cpp +++ b/src/DBConnection.cpp @@ -17,6 +17,7 @@ Paul Licameli -- split from ProjectFileIO.cpp #include "Internat.h" #include "Project.h" +#include "FileException.h" // Configuration to provide "safe" connections static const char *SafeConfig = @@ -157,6 +158,20 @@ bool DBConnection::Close() return true; } +[[noreturn]] void DBConnection::ThrowException( bool write ) const +{ + // Sqlite3 documentation says returned character string + // does NOT require freeing by us. + wxString dbName{ sqlite3_db_filename(mDB, "main") }; + // Now we have an absolute path. Throw a message box exception that + // formats a helpful message just as used to be done before sqlite3 + // was used for projects. + throw FileException{ + write ? FileException::Cause::Write : FileException::Cause::Read, + dbName + }; +} + bool DBConnection::SafeMode(const char *schema /* = "main" */) { return ModeConfig(mDB, schema, SafeConfig); diff --git a/src/DBConnection.h b/src/DBConnection.h index d2dd7f5b6..28e679449 100644 --- a/src/DBConnection.h +++ b/src/DBConnection.h @@ -35,6 +35,11 @@ public: bool Open(const char *fileName); bool Close(); + //! throw and show appropriate message box + [[noreturn]] void ThrowException( + bool write //!< If true, a database update failed; if false, only a SELECT failed + ) const; + bool SafeMode(const char *schema = "main"); bool FastMode(const char *schema = "main"); diff --git a/src/SqliteSampleBlock.cpp b/src/SqliteSampleBlock.cpp index 39e51df55..407f88802 100644 --- a/src/SqliteSampleBlock.cpp +++ b/src/SqliteSampleBlock.cpp @@ -506,7 +506,7 @@ size_t SqliteSampleBlock::GetBlob(void *dest, // Just showing the user a simple message, not the library error too // which isn't internationalized - throw SimpleMessageBoxException{ XO("Failed to retrieve project data") }; + Conn()->ThrowException( false ); } // Retrieve returned data @@ -583,7 +583,7 @@ void SqliteSampleBlock::Load(SampleBlockID sbid) // Just showing the user a simple message, not the library error too // which isn't internationalized - throw SimpleMessageBoxException{ XO("Failed to retrieve sample block") }; + Conn()->ThrowException( false ); } // Retrieve returned data @@ -641,7 +641,7 @@ void SqliteSampleBlock::Commit() // Just showing the user a simple message, not the library error too // which isn't internationalized - throw SimpleMessageBoxException{ XO("Failed to add sample block") }; + Conn()->ThrowException( true ); } // Retrieve returned data @@ -690,7 +690,7 @@ void SqliteSampleBlock::Delete() // Just showing the user a simple message, not the library error too // which isn't internationalized - throw SimpleMessageBoxException{ XO("Failed to delete sample block") }; + Conn()->ThrowException( true ); } // Clear statement bindings and rewind statement