Commit 2133ef17 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

sqlite::Connection: Rename getConn to handle()

To reduce the confusion of having to call getConn() on a class named
Connection
parent 724599b0
......@@ -287,7 +287,7 @@ const IMediaMetadata& Media::metadata( IMedia::MetadataType type ) const
" WHERE id_media = ?";
auto conn = m_ml->getConn();
auto ctx = conn->acquireReadContext();
sqlite::Statement stmt( conn->getConn(), req );
sqlite::Statement stmt( conn->handle(), req );
stmt.execute( m_id );
for ( sqlite::Row row = stmt.row(); row != nullptr; row = stmt.row() )
{
......
......@@ -43,7 +43,7 @@ Settings::Settings( MediaLibrary* ml )
bool Settings::load()
{
sqlite::Statement s( m_ml->getConn()->getConn(), "SELECT * FROM Settings" );
sqlite::Statement s( m_ml->getConn()->handle(), "SELECT * FROM Settings" );
auto row = s.row();
// First launch: no settings
if ( row == nullptr )
......
......@@ -49,7 +49,7 @@ Connection::~Connection()
sqlite::Statement::FlushStatementCache();
}
Connection::Handle Connection::getConn()
Connection::Handle Connection::handle()
{
/**
* We need to have a single sqlite connection per thread, but we also need
......@@ -140,7 +140,7 @@ void Connection::setForeignKeyEnabled( bool value )
// Changing this pragma during a transaction is a no-op (silently ignored by
// sqlite), so ensure we're doing something usefull here:
assert( sqlite::Transaction::transactionInProgress() == false );
setPragmaEnabled( getConn(), "foreign_keys", value );
setPragmaEnabled( handle(), "foreign_keys", value );
}
void Connection::setRecursiveTriggers( bool value )
......@@ -156,7 +156,7 @@ void Connection::setRecursiveTriggers( bool value )
// https://sqlite.org/pragma.html#pragma_recursive_triggers
sqlite::Statement::FlushStatementCache();
setPragmaEnabled( getConn(), "recursive_triggers", value );
setPragmaEnabled( handle(), "recursive_triggers", value );
}
void Connection::registerUpdateHook( const std::string& table, Connection::UpdateHookCb cb )
......
......@@ -69,7 +69,7 @@ public:
// Returns the current thread's connection
// This will initiate a connection if required
Handle getConn();
Handle handle();
std::unique_ptr<sqlite::Transaction> newTransaction();
ReadContext acquireReadContext();
WriteContext acquireWriteContext();
......
......@@ -240,7 +240,7 @@ class Tools
auto chrono = std::chrono::steady_clock::now();
std::vector<std::shared_ptr<INTF>> results;
Statement stmt( dbConnection->getConn(), req );
Statement stmt( dbConnection->handle(), req );
stmt.execute( std::forward<Args>( args )... );
Row sqliteRow;
while ( ( sqliteRow = stmt.row() ) != nullptr )
......@@ -263,7 +263,7 @@ class Tools
ctx = dbConnection->acquireReadContext();
auto chrono = std::chrono::steady_clock::now();
Statement stmt( dbConnection->getConn(), req );
Statement stmt( dbConnection->handle(), req );
stmt.execute( std::forward<Args>( args )... );
auto row = stmt.row();
std::shared_ptr<T> res;
......@@ -292,7 +292,7 @@ class Tools
ctx = dbConnection->acquireWriteContext();
if ( executeRequestLocked( dbConnection, req, std::forward<Args>( args )... ) == false )
return false;
return sqlite3_changes( dbConnection->getConn() ) > 0;
return sqlite3_changes( dbConnection->handle() ) > 0;
}
template <typename... Args>
......@@ -314,7 +314,7 @@ class Tools
ctx = dbConnection->acquireWriteContext();
if ( executeRequestLocked( dbConnection, req, std::forward<Args>( args )... ) == false )
return 0;
return sqlite3_last_insert_rowid( dbConnection->getConn() );
return sqlite3_last_insert_rowid( dbConnection->handle() );
}
/**
......@@ -348,7 +348,7 @@ class Tools
static bool executeRequestLocked( sqlite::Connection* dbConnection, const std::string& req, Args&&... args )
{
auto chrono = std::chrono::steady_clock::now();
Statement stmt( dbConnection->getConn(), req );
Statement stmt( dbConnection->handle(), req );
stmt.execute( std::forward<Args>( args )... );
while ( stmt.row() != nullptr )
;
......
......@@ -42,7 +42,7 @@ Transaction::Transaction( sqlite::Connection* dbConn)
{
assert( CurrentTransaction == nullptr );
LOG_DEBUG( "Starting SQLite transaction" );
Statement s( dbConn->getConn(), "BEGIN" );
Statement s( dbConn->handle(), "BEGIN" );
s.execute();
while ( s.row() != nullptr )
;
......@@ -53,7 +53,7 @@ void Transaction::commit()
{
assert( CurrentTransaction != nullptr );
auto chrono = std::chrono::steady_clock::now();
Statement s( m_dbConn->getConn(), "COMMIT" );
Statement s( m_dbConn->handle(), "COMMIT" );
s.execute();
while ( s.row() != nullptr )
;
......@@ -82,7 +82,7 @@ Transaction::~Transaction()
{
if ( CurrentTransaction != nullptr )
{
Statement s( m_dbConn->getConn(), "ROLLBACK" );
Statement s( m_dbConn->handle(), "ROLLBACK" );
s.execute();
while ( s.row() != nullptr )
;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment