Audacity 3.2.0
|
A class representing a connection to a SQLite database. More...
#include <Connection.h>
Public Member Functions | |
Connection ()=default | |
Connection (const Connection &)=delete | |
Connection (Connection &&) noexcept | |
Connection & | operator= (const Connection &)=delete |
Connection & | operator= (Connection &&) noexcept |
~Connection () | |
bool | IsOpen () const noexcept |
Returns true if the connection is open. More... | |
bool | CheckTableExists (std::string_view tableName) const |
Returns true if the table exists in the database. More... | |
Error | Execute (std::string_view sql) noexcept |
Executes the given SQL statement and returns the result. More... | |
Transaction | BeginTransaction (std::string name) |
Starts a new transaction. More... | |
Result< Statement > | CreateStatement (std::string_view sql) const |
Prepares the given SQL statement for execution. More... | |
template<typename ScalarFunctionType > | |
ScalarFunction | CreateScalarFunction (std::string name, ScalarFunctionType function) |
Registers a scalar function with the given name. More... | |
template<typename StepFunctionType , typename FinalFunctionType > | |
AggregateFunction | CreateAggregateFunction (std::string name, StepFunctionType stepFunction, FinalFunctionType finalFunction) |
Registers an aggregate function with the given name. More... | |
Result< Blob > | OpenBlob (const std::string &tableName, const std::string &columnName, int64_t rowId, bool readOnly, const std::string &databaseName="main") const |
Opens a BLOB for reading or writing. More... | |
operator sqlite3 * () const noexcept | |
Returns the underlying sqlite3* object. More... | |
operator bool () const noexcept | |
Returns true if the connection is open. More... | |
Error | Close (bool force) noexcept |
Closes the connection. More... | |
std::string_view | GetPath (const char *dbName={}) const noexcept |
Returns the path to the database. More... | |
Static Public Member Functions | |
static Result< Connection > | Open (std::string_view path, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized) |
Opens a connection to a database. More... | |
static Result< Connection > | Wrap (sqlite3 *connection) |
static Result< Connection > | Reopen (const Connection &connection, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized) |
static Result< Connection > | Reopen (sqlite3 *connection, OpenMode mode=OpenMode::ReadWriteCreate, ThreadMode threadMode=ThreadMode::Serialized) |
Private Member Functions | |
Connection (sqlite3 *connection, bool owned) noexcept | |
Static Private Member Functions | |
static Error | TransactionHandler (Connection &connection, Transaction::TransactionOperation operation, Transaction &name) |
Private Attributes | |
sqlite3 * | mConnection {} |
std::vector< Transaction * > | mPendingTransactions {} |
bool | mInDestructor {} |
bool | mIsOwned {} |
A class representing a connection to a SQLite database.
Definition at line 47 of file Connection.h.
|
default |
|
delete |
|
noexcept |
Definition at line 114 of file Connection.cpp.
audacity::sqlite::Connection::~Connection | ( | ) |
Definition at line 129 of file Connection.cpp.
References Close(), and mInDestructor.
|
privatenoexcept |
Definition at line 108 of file Connection.cpp.
Transaction audacity::sqlite::Connection::BeginTransaction | ( | std::string | name | ) |
Starts a new transaction.
Definition at line 200 of file Connection.cpp.
References name, and TransactionHandler().
bool audacity::sqlite::Connection::CheckTableExists | ( | std::string_view | tableName | ) | const |
Returns true if the table exists in the database.
Definition at line 141 of file Connection.cpp.
References CreateStatement().
|
noexcept |
Closes the connection.
Definition at line 298 of file Connection.cpp.
References audacity::sqlite::Error::IsError().
Referenced by ~Connection().
|
inline |
Registers an aggregate function with the given name.
Definition at line 107 of file Connection.h.
References name.
|
inline |
Registers a scalar function with the given name.
Definition at line 99 of file Connection.h.
References name.
Prepares the given SQL statement for execution.
Definition at line 253 of file Connection.cpp.
References mConnection, and mInDestructor.
Referenced by audacity::cloud::audiocom::sync::RemoteProjectSnapshot::AttachOriginalDB(), CheckTableExists(), audacity::cloud::audiocom::sync::CloudProjectsDatabase::DeleteProject(), audacity::cloud::audiocom::sync::anonymous_namespace{RemoteProjectSnapshot.cpp}::ListAttachedDatabases(), audacity::cloud::audiocom::sync::RemoteProjectSnapshot::RemoteProjectSnapshot(), audacity::cloud::audiocom::sync::RemoteProjectSnapshot::SetupBlocksCopy(), and audacity::cloud::audiocom::sync::RemoteProjectSnapshot::~RemoteProjectSnapshot().
|
noexcept |
Executes the given SQL statement and returns the result.
Definition at line 160 of file Connection.cpp.
|
noexcept |
Returns the path to the database.
Definition at line 317 of file Connection.cpp.
Referenced by Reopen().
|
noexcept |
Returns true if the connection is open.
Definition at line 136 of file Connection.cpp.
References mConnection.
Referenced by Reopen().
|
static |
Opens a connection to a database.
Definition at line 21 of file Connection.cpp.
References Connection(), audacity::sqlite::Initialize(), audacity::sqlite::Memory, audacity::sqlite::MultiThread, audacity::sqlite::ReadOnly, audacity::sqlite::ReadWrite, audacity::sqlite::ReadWriteCreate, and audacity::sqlite::Serialized.
Referenced by audacity::sqlite::SafeConnection::Open(), and Reopen().
Result< Blob > audacity::sqlite::Connection::OpenBlob | ( | const std::string & | tableName, |
const std::string & | columnName, | ||
int64_t | rowId, | ||
bool | readOnly, | ||
const std::string & | databaseName = "main" |
||
) | const |
Opens a BLOB for reading or writing.
Definition at line 269 of file Connection.cpp.
References mConnection, and mInDestructor.
|
explicitnoexcept |
Returns true if the connection is open.
Definition at line 293 of file Connection.cpp.
|
explicitnoexcept |
Returns the underlying sqlite3* object.
Definition at line 288 of file Connection.cpp.
|
noexcept |
Definition at line 119 of file Connection.cpp.
References anonymous_namespace{NoteTrack.cpp}::swap().
|
delete |
|
static |
Opens a new connection to the same database as the existing connection but with different parameters
Definition at line 82 of file Connection.cpp.
References GetPath(), IsOpen(), and Open().
Referenced by audacity::sqlite::SafeConnection::Reopen(), and Reopen().
|
static |
Opens a new connection to the same database as the existing connection but with different parameters
Definition at line 98 of file Connection.cpp.
References Reopen(), and Wrap().
|
staticprivate |
Definition at line 205 of file Connection.cpp.
References audacity::sqlite::Transaction::BeginOp, audacity::sqlite::Transaction::CommitOp, audacity::sqlite::Transaction::mCommitted, mConnection, audacity::sqlite::Transaction::mName, mPendingTransactions, name, and audacity::sqlite::Transaction::RollbackOp.
Referenced by BeginTransaction().
|
static |
Wraps an existing connection. The connection will not be closed when the object is destroyed.
Definition at line 74 of file Connection.cpp.
References Connection().
Referenced by Reopen().
|
private |
Definition at line 141 of file Connection.h.
Referenced by CreateStatement(), IsOpen(), OpenBlob(), audacity::sqlite::SafeConnection::Lock::operator*(), audacity::sqlite::SafeConnection::Lock::operator->(), and TransactionHandler().
|
private |
Definition at line 145 of file Connection.h.
Referenced by CreateStatement(), OpenBlob(), and ~Connection().
|
private |
Definition at line 146 of file Connection.h.
|
private |
Definition at line 143 of file Connection.h.
Referenced by TransactionHandler().