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

Index & make unique files mrls & labels values

parent 0bde9d01
......@@ -119,9 +119,13 @@ bool File::createTable(sqlite3* connection)
"album_track_id UNSIGNED INTEGER,"
"play_count UNSIGNED INTEGER,"
"show_episode_id UNSIGNED INTEGER,"
"mrl TEXT"
"mrl TEXT UNIQUE ON CONFLICT FAIL"
")";
return SqliteTools::createTable( connection, req.c_str() );
if ( SqliteTools::createTable( connection, req.c_str() ) == false )
return false;
req = "CREATE INDEX file_index ON " + policy::FileTable::Name + " (mrl)";
auto stmt = SqliteTools::executeRequest( connection, req.c_str() );
return sqlite3_step( stmt.get() ) == SQLITE_DONE;
}
bool File::addLabel( LabelPtr label )
......
......@@ -73,10 +73,19 @@ bool Label::createTable(sqlite3* dbConnection)
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::LabelTable::Name + "("
"id_label INTEGER PRIMARY KEY AUTOINCREMENT, "
"name TEXT"
"name TEXT UNIQUE ON CONFLICT FAIL"
")";
if ( SqliteTools::createTable( dbConnection, req.c_str() ) == false )
return false;
//FIXME: Check for a better way when addressing transactions
req = "CREATE INDEX label_index ON " + policy::LabelTable::Name + " (name)";
{
auto stmt = SqliteTools::executeRequest( dbConnection, req.c_str() );
if ( stmt == nullptr )
return false;
if ( sqlite3_step( stmt.get() ) != SQLITE_DONE )
return false;
}
req = "CREATE TABLE IF NOT EXISTS LabelFileRelation("
"id_label INTEGER,"
"id_file INTEGER,"
......
......@@ -91,13 +91,13 @@ class SqliteTools
return sqlite3_changes( dbConnection ) > 0;
}
private:
template <typename... Args>
static StmtPtr executeRequest( sqlite3* dbConnection, const char* req, const Args&... args )
{
return _executeRequest<1>( dbConnection, req, args... );
}
private:
template <unsigned int>
static StmtPtr _executeRequest( sqlite3* dbConnection, const char* req )
{
......
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