mirror of
https://github.com/cookiengineer/audacity
synced 2025-04-30 15:49:41 +02:00
Where CurConn() is used, don't assume it is non-null
This commit is contained in:
parent
900bf44219
commit
41eb66fccf
@ -345,7 +345,8 @@ bool ProjectFileIO::OpenConnection(FilePath fileName /* = {} */)
|
|||||||
bool ProjectFileIO::CloseConnection()
|
bool ProjectFileIO::CloseConnection()
|
||||||
{
|
{
|
||||||
auto &curConn = CurrConn();
|
auto &curConn = CurrConn();
|
||||||
wxASSERT(curConn);
|
if (!curConn)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!curConn->Close())
|
if (!curConn->Close())
|
||||||
{
|
{
|
||||||
@ -690,6 +691,10 @@ bool ProjectFileIO::CopyTo(const FilePath &destpath,
|
|||||||
bool prune /* = false */,
|
bool prune /* = false */,
|
||||||
const std::vector<const TrackList *> &tracks /* = {} */)
|
const std::vector<const TrackList *> &tracks /* = {} */)
|
||||||
{
|
{
|
||||||
|
auto pConn = CurrConn().get();
|
||||||
|
if (!pConn)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Get access to the active tracklist
|
// Get access to the active tracklist
|
||||||
auto pProject = &mProject;
|
auto pProject = &mProject;
|
||||||
|
|
||||||
@ -764,7 +769,7 @@ bool ProjectFileIO::CopyTo(const FilePath &destpath,
|
|||||||
//
|
//
|
||||||
// NOTE: Between the above attach and setting the mode here, a normal DELETE
|
// NOTE: Between the above attach and setting the mode here, a normal DELETE
|
||||||
// mode journal will be used and will briefly appear in the filesystem.
|
// mode journal will be used and will briefly appear in the filesystem.
|
||||||
CurrConn()->FastMode("outbound");
|
pConn->FastMode("outbound");
|
||||||
|
|
||||||
// Install our schema into the new database
|
// Install our schema into the new database
|
||||||
if (!InstallSchema(db, "outbound"))
|
if (!InstallSchema(db, "outbound"))
|
||||||
@ -2269,6 +2274,7 @@ void ProjectFileIO::SetError(
|
|||||||
const TranslatableString &msg, const TranslatableString &libraryError )
|
const TranslatableString &msg, const TranslatableString &libraryError )
|
||||||
{
|
{
|
||||||
auto &currConn = CurrConn();
|
auto &currConn = CurrConn();
|
||||||
|
if (currConn)
|
||||||
currConn->SetError(msg, libraryError);
|
currConn->SetError(msg, libraryError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2276,6 +2282,7 @@ void ProjectFileIO::SetDBError(
|
|||||||
const TranslatableString &msg, const TranslatableString &libraryError)
|
const TranslatableString &msg, const TranslatableString &libraryError)
|
||||||
{
|
{
|
||||||
auto &currConn = CurrConn();
|
auto &currConn = CurrConn();
|
||||||
|
if (currConn)
|
||||||
currConn->SetDBError(msg, libraryError);
|
currConn->SetDBError(msg, libraryError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2315,7 +2322,10 @@ void ProjectFileIO::SetBypass()
|
|||||||
|
|
||||||
int64_t ProjectFileIO::GetBlockUsage(SampleBlockID blockid)
|
int64_t ProjectFileIO::GetBlockUsage(SampleBlockID blockid)
|
||||||
{
|
{
|
||||||
return GetDiskUsage(CurrConn().get(), blockid);
|
auto pConn = CurrConn().get();
|
||||||
|
if (!pConn)
|
||||||
|
return 0;
|
||||||
|
return GetDiskUsage(*pConn, blockid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t ProjectFileIO::GetCurrentUsage(
|
int64_t ProjectFileIO::GetCurrentUsage(
|
||||||
@ -2336,7 +2346,10 @@ int64_t ProjectFileIO::GetCurrentUsage(
|
|||||||
|
|
||||||
int64_t ProjectFileIO::GetTotalUsage()
|
int64_t ProjectFileIO::GetTotalUsage()
|
||||||
{
|
{
|
||||||
return GetDiskUsage(CurrConn().get(), 0);
|
auto pConn = CurrConn().get();
|
||||||
|
if (!pConn)
|
||||||
|
return 0;
|
||||||
|
return GetDiskUsage(*pConn, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -2345,7 +2358,7 @@ int64_t ProjectFileIO::GetTotalUsage()
|
|||||||
// pages available from the "sqlite_dbpage" virtual table to traverse the SQLite
|
// pages available from the "sqlite_dbpage" virtual table to traverse the SQLite
|
||||||
// table b-tree described here: https://www.sqlite.org/fileformat.html
|
// table b-tree described here: https://www.sqlite.org/fileformat.html
|
||||||
//
|
//
|
||||||
int64_t ProjectFileIO::GetDiskUsage(DBConnection *conn, SampleBlockID blockid /* = 0 */)
|
int64_t ProjectFileIO::GetDiskUsage(DBConnection &conn, SampleBlockID blockid /* = 0 */)
|
||||||
{
|
{
|
||||||
// Information we need to track our travels through the b-tree
|
// Information we need to track our travels through the b-tree
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -2364,7 +2377,7 @@ int64_t ProjectFileIO::GetDiskUsage(DBConnection *conn, SampleBlockID blockid /*
|
|||||||
|
|
||||||
// Get the rootpage for the sampleblocks table.
|
// Get the rootpage for the sampleblocks table.
|
||||||
sqlite3_stmt *stmt =
|
sqlite3_stmt *stmt =
|
||||||
conn->Prepare(DBConnection::GetRootPage,
|
conn.Prepare(DBConnection::GetRootPage,
|
||||||
"SELECT rootpage FROM sqlite_master WHERE tbl_name = 'sampleblocks';");
|
"SELECT rootpage FROM sqlite_master WHERE tbl_name = 'sampleblocks';");
|
||||||
if (stmt == nullptr || sqlite3_step(stmt) != SQLITE_ROW)
|
if (stmt == nullptr || sqlite3_step(stmt) != SQLITE_ROW)
|
||||||
{
|
{
|
||||||
@ -2379,7 +2392,7 @@ int64_t ProjectFileIO::GetDiskUsage(DBConnection *conn, SampleBlockID blockid /*
|
|||||||
sqlite3_reset(stmt);
|
sqlite3_reset(stmt);
|
||||||
|
|
||||||
// Prepare/retrieve statement to read raw database page
|
// Prepare/retrieve statement to read raw database page
|
||||||
stmt = conn->Prepare(DBConnection::GetDBPage,
|
stmt = conn.Prepare(DBConnection::GetDBPage,
|
||||||
"SELECT data FROM sqlite_dbpage WHERE pgno = ?1;");
|
"SELECT data FROM sqlite_dbpage WHERE pgno = ?1;");
|
||||||
if (stmt == nullptr)
|
if (stmt == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@ public:
|
|||||||
|
|
||||||
// Return the bytes used for the given block using the connection to a
|
// Return the bytes used for the given block using the connection to a
|
||||||
// specific database. This is the workhorse for the above 3 methods.
|
// specific database. This is the workhorse for the above 3 methods.
|
||||||
static int64_t GetDiskUsage(DBConnection *conn, SampleBlockID blockid);
|
static int64_t GetDiskUsage(DBConnection &conn, SampleBlockID blockid);
|
||||||
|
|
||||||
const TranslatableString &GetLastError();
|
const TranslatableString &GetLastError();
|
||||||
const TranslatableString &GetLibraryError();
|
const TranslatableString &GetLibraryError();
|
||||||
|
@ -88,6 +88,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//! This must never be called for silent blocks
|
//! This must never be called for silent blocks
|
||||||
|
/*! @post return value is not null */
|
||||||
DBConnection *Conn() const;
|
DBConnection *Conn() const;
|
||||||
sqlite3 *DB() const
|
sqlite3 *DB() const
|
||||||
{
|
{
|
||||||
@ -527,7 +528,7 @@ size_t SqliteSampleBlock::GetSpaceUsage() const
|
|||||||
if (IsSilent())
|
if (IsSilent())
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return ProjectFileIO::GetDiskUsage(Conn(), mBlockID);
|
return ProjectFileIO::GetDiskUsage(*Conn(), mBlockID);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SqliteSampleBlock::GetBlob(void *dest,
|
size_t SqliteSampleBlock::GetBlob(void *dest,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user