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

Folder: Add an FTS table

ref #42
parent 074cf8f6
......@@ -303,8 +303,12 @@ void Folder::setName( std::string name )
assert( m_name.empty() == true );
static const std::string req = "UPDATE " + Table::Name +
" SET name = ? WHERE id_folder = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, name, m_id ) == false )
auto dbConn = m_ml->getConn();
if ( sqlite::Tools::executeUpdate( dbConn, req, name, m_id ) == false )
return;
static const std::string reqFts = "INSERT INTO " + Table::Name + "Fts "
"(rowid, name) VALUES(?, ?)";
sqlite::Tools::executeInsert( dbConn, reqFts, m_id, name );
m_name = std::move( name );
}
......
......@@ -4,3 +4,16 @@
"CREATE INDEX IF NOT EXISTS parent_folder_id_idx ON " +
Folder::Table::Name + " (parent_id)",
"CREATE TRIGGER IF NOT EXISTS insert_folder_fts "
"AFTER INSERT ON " + Folder::Table::Name + " "
"BEGIN "
"INSERT INTO " + Folder::Table::Name + "Fts(rowid,name) "
"VALUES(new.id_folder,new.name);"
"END",
"CREATE TRIGGER IF NOT EXISTS delete_folder_fts "
"BEFORE DELETE ON " + Folder::Table::Name + " "
"BEGIN "
"DELETE FROM " + Folder::Table::Name + "Fts WHERE rowid = old.id_folder;"
"END",
......@@ -33,3 +33,8 @@
"UNIQUE(folder_id) ON CONFLICT FAIL"
")",
"CREATE VIRTUAL TABLE IF NOT EXISTS " + Folder::Table::Name + "Fts USING FTS3"
"("
"name"
")",
......@@ -174,7 +174,7 @@ TEST_F( DbModel, Upgrade12to13 )
// We can't check for the number of albums anymore since they are deleted
// as part of 13 -> 14 migration
CheckNbTriggers( 32 );
CheckNbTriggers( 34 );
}
TEST_F( DbModel, Upgrade13to14 )
......@@ -221,5 +221,5 @@ TEST_F( DbModel, Upgrade13to14 )
ASSERT_EQ( 2u, folder->nbMedia() );
ASSERT_EQ( "folder", folder->name() );
CheckNbTriggers( 32 );
CheckNbTriggers( 34 );
}
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