Commit 911c31d9 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Settinngs: Do not store a database connection

parent c57a20ec
......@@ -91,6 +91,7 @@ const size_t MediaLibrary::NbSupportedExtensions = sizeof(supportedExtensions) /
MediaLibrary::MediaLibrary()
: m_callback( nullptr )
, m_verbosity( LogLevel::Error )
, m_settings( this )
, m_initialized( false )
, m_discovererIdle( true )
, m_parserIdle( true )
......@@ -271,7 +272,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
LOG_ERROR( "Failed to create database structure" );
return false;
}
if ( m_settings.load( m_dbConnection.get() ) == false )
if ( m_settings.load() == false )
{
LOG_ERROR( "Failed to load settings" );
return false;
......
......@@ -34,22 +34,21 @@ namespace medialibrary
const uint32_t Settings::DbModelVersion = 4u;
Settings::Settings()
: m_dbConn( nullptr )
Settings::Settings( MediaLibrary* ml )
: m_ml( ml )
, m_dbModelVersion( 0 )
, m_changed( false )
{
}
bool Settings::load( DBConnection dbConn )
bool Settings::load()
{
m_dbConn = dbConn;
sqlite::Statement s( m_dbConn->getConn(), "SELECT * FROM Settings" );
sqlite::Statement s( m_ml->getConn()->getConn(), "SELECT * FROM Settings" );
auto row = s.row();
// First launch: no settings
if ( row == nullptr )
{
if ( sqlite::Tools::executeInsert( m_dbConn, "INSERT INTO Settings VALUES(?)", DbModelVersion ) == false )
if ( sqlite::Tools::executeInsert( m_ml->getConn(), "INSERT INTO Settings VALUES(?)", DbModelVersion ) == false )
return false;
m_dbModelVersion = DbModelVersion;
}
......@@ -72,7 +71,7 @@ bool Settings::save()
static const std::string req = "UPDATE Settings SET db_model_version = ?";
if ( m_changed == false )
return true;
if ( sqlite::Tools::executeUpdate( m_dbConn, req, m_dbModelVersion ) == true )
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, m_dbModelVersion ) == true )
{
m_changed = false;
return true;
......@@ -86,7 +85,7 @@ void Settings::setDbModelVersion(uint32_t dbModelVersion)
m_changed = true;
}
bool Settings::createTable( DBConnection dbConn )
bool Settings::createTable( sqlite::Connection* dbConn )
{
const std::string req = "CREATE TABLE IF NOT EXISTS Settings("
"db_model_version UNSIGNED INTEGER NOT NULL DEFAULT " +
......
......@@ -29,11 +29,17 @@
namespace medialibrary
{
namespace sqlite
{
class Connection;
}
class Settings
{
public:
Settings();
bool load( DBConnection dbConn );
Settings( MediaLibrary* ml );
bool load();
/**
* @brief dbModelVersion returns the current database model version.
*
......@@ -43,12 +49,12 @@ public:
bool save();
void setDbModelVersion( uint32_t dbModelVersion );
static bool createTable(DBConnection dbConn);
static bool createTable( sqlite::Connection* dbConn );
static const uint32_t DbModelVersion;
private:
DBConnection m_dbConn;
MediaLibrary* m_ml;
uint32_t m_dbModelVersion;
......
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