mirror of
https://github.com/cookiengineer/audacity
synced 2025-04-30 15:49:41 +02:00
Demote error message storage from ProjectFileIO into DBConnection
This commit is contained in:
parent
c9dec8f5a9
commit
eb7e67623e
@ -55,6 +55,28 @@ bool DBConnection::ShouldBypass()
|
||||
return mBypass;
|
||||
}
|
||||
|
||||
void DBConnection::SetError(
|
||||
const TranslatableString &msg, const TranslatableString &libraryError)
|
||||
{
|
||||
mLastError = msg;
|
||||
mLibraryError = libraryError;
|
||||
}
|
||||
|
||||
void DBConnection::SetDBError(
|
||||
const TranslatableString &msg, const TranslatableString &libraryError)
|
||||
{
|
||||
mLastError = msg;
|
||||
wxLogDebug(wxT("SQLite error: %s"), mLastError.Debug());
|
||||
printf(" Lib error: %s", mLastError.Debug().mb_str().data());
|
||||
|
||||
mLibraryError = libraryError.empty()
|
||||
? Verbatim(sqlite3_errmsg(DB())) : libraryError;
|
||||
wxLogDebug(wxT(" Lib error: %s"), mLibraryError.Debug());
|
||||
printf(" Lib error: %s", mLibraryError.Debug().mb_str().data());
|
||||
|
||||
wxASSERT(false);
|
||||
}
|
||||
|
||||
bool DBConnection::Open(const char *fileName)
|
||||
{
|
||||
wxASSERT(mDB == nullptr);
|
||||
|
@ -69,6 +69,21 @@ public:
|
||||
void SetBypass( bool bypass );
|
||||
bool ShouldBypass();
|
||||
|
||||
//! Just set stored errors
|
||||
void SetError(
|
||||
const TranslatableString &msg,
|
||||
const TranslatableString &libraryError = {} );
|
||||
|
||||
//! Set stored errors and write to log; and default libraryError to what database library reports
|
||||
void SetDBError(
|
||||
const TranslatableString &msg,
|
||||
const TranslatableString &libraryError = {} );
|
||||
|
||||
const TranslatableString &GetLastError() const
|
||||
{ return mLastError; }
|
||||
const TranslatableString &GetLibraryError() const
|
||||
{ return mLibraryError; }
|
||||
|
||||
private:
|
||||
bool ModeConfig(sqlite3 *db, const char *schema, const char *config);
|
||||
|
||||
@ -88,6 +103,9 @@ private:
|
||||
|
||||
std::map<enum StatementID, sqlite3_stmt *> mStatements;
|
||||
|
||||
TranslatableString mLastError;
|
||||
TranslatableString mLibraryError;
|
||||
|
||||
// Bypass transactions if database will be deleted after close
|
||||
bool mBypass;
|
||||
};
|
||||
|
@ -507,9 +507,9 @@ int ProjectFileIO::Exec(const char *query, const ExecCB &callback)
|
||||
if (rc != SQLITE_ABORT && errmsg)
|
||||
{
|
||||
SetDBError(
|
||||
XO("Failed to execute a project file command:\n\n%s").Format(query)
|
||||
XO("Failed to execute a project file command:\n\n%s").Format(query),
|
||||
Verbatim(errmsg)
|
||||
);
|
||||
mLibraryError = Verbatim(errmsg);
|
||||
}
|
||||
if (errmsg)
|
||||
{
|
||||
@ -1769,9 +1769,8 @@ bool ProjectFileIO::ImportProject(const FilePath &fileName)
|
||||
if (!xmlFile.ParseString(this, output.GetString()))
|
||||
{
|
||||
SetError(
|
||||
XO("Unable to parse project information.")
|
||||
XO("Unable to parse project information."), xmlFile.GetErrorStr()
|
||||
);
|
||||
mLibraryError = xmlFile.GetErrorStr();
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1846,9 +1845,9 @@ bool ProjectFileIO::LoadProject(const FilePath &fileName)
|
||||
if (!success)
|
||||
{
|
||||
SetError(
|
||||
XO("Unable to parse project information.")
|
||||
XO("Unable to parse project information."),
|
||||
xmlFile.GetErrorStr()
|
||||
);
|
||||
mLibraryError = xmlFile.GetErrorStr();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2122,37 +2121,30 @@ wxLongLong ProjectFileIO::GetFreeDiskSpace() const
|
||||
return -1;
|
||||
}
|
||||
|
||||
const TranslatableString &ProjectFileIO::GetLastError() const
|
||||
{
|
||||
return mLastError;
|
||||
}
|
||||
|
||||
const TranslatableString &ProjectFileIO::GetLibraryError() const
|
||||
{
|
||||
return mLibraryError;
|
||||
}
|
||||
|
||||
void ProjectFileIO::SetError(const TranslatableString &msg)
|
||||
{
|
||||
mLastError = msg;
|
||||
mLibraryError = {};
|
||||
}
|
||||
|
||||
void ProjectFileIO::SetDBError(const TranslatableString &msg)
|
||||
const TranslatableString &ProjectFileIO::GetLastError()
|
||||
{
|
||||
auto &currConn = CurrConn();
|
||||
mLastError = msg;
|
||||
wxLogDebug(wxT("SQLite error: %s"), mLastError.Debug());
|
||||
printf(" Lib error: %s", mLastError.Debug().mb_str().data());
|
||||
return currConn->GetLastError();
|
||||
}
|
||||
|
||||
if (currConn)
|
||||
{
|
||||
mLibraryError = Verbatim(sqlite3_errmsg(currConn->DB()));
|
||||
wxLogDebug(wxT(" Lib error: %s"), mLibraryError.Debug());
|
||||
printf(" Lib error: %s", mLibraryError.Debug().mb_str().data());
|
||||
}
|
||||
const TranslatableString &ProjectFileIO::GetLibraryError()
|
||||
{
|
||||
auto &currConn = CurrConn();
|
||||
return currConn->GetLibraryError();
|
||||
}
|
||||
|
||||
wxASSERT(false);
|
||||
void ProjectFileIO::SetError(
|
||||
const TranslatableString &msg, const TranslatableString &libraryError )
|
||||
{
|
||||
auto &currConn = CurrConn();
|
||||
currConn->SetError(msg, libraryError);
|
||||
}
|
||||
|
||||
void ProjectFileIO::SetDBError(
|
||||
const TranslatableString &msg, const TranslatableString &libraryError)
|
||||
{
|
||||
auto &currConn = CurrConn();
|
||||
currConn->SetDBError(msg, libraryError);
|
||||
}
|
||||
|
||||
void ProjectFileIO::SetBypass()
|
||||
|
@ -104,8 +104,8 @@ public:
|
||||
// specific database. This is the workhorse for the above 3 methods.
|
||||
static int64_t GetDiskUsage(DBConnection *conn, SampleBlockID blockid);
|
||||
|
||||
const TranslatableString &GetLastError() const;
|
||||
const TranslatableString &GetLibraryError() const;
|
||||
const TranslatableString &GetLastError();
|
||||
const TranslatableString &GetLibraryError();
|
||||
|
||||
// Provides a means to bypass "DELETE"s at shutdown if the database
|
||||
// is just going to be deleted anyway. This prevents a noticable
|
||||
@ -199,8 +199,13 @@ private:
|
||||
bool prune = false,
|
||||
const std::shared_ptr<TrackList> &tracks = nullptr);
|
||||
|
||||
void SetError(const TranslatableString & msg);
|
||||
void SetDBError(const TranslatableString & msg);
|
||||
//! Just set stored errors
|
||||
void SetError(const TranslatableString & msg,
|
||||
const TranslatableString &libraryError = {});
|
||||
|
||||
//! Set stored errors and write to log; and default libraryError to what database library reports
|
||||
void SetDBError(const TranslatableString & msg,
|
||||
const TranslatableString &libraryError = {});
|
||||
|
||||
bool ShouldCompact(const std::shared_ptr<TrackList> &tracks);
|
||||
|
||||
@ -236,9 +241,6 @@ private:
|
||||
Connection mPrevConn;
|
||||
FilePath mPrevFileName;
|
||||
bool mPrevTemporary;
|
||||
|
||||
TranslatableString mLastError;
|
||||
TranslatableString mLibraryError;
|
||||
};
|
||||
|
||||
// Make a savepoint (a transaction, possibly nested) with the given name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user