Commit 82c8fb24 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Metadata: Provide an unset method

parent 1ebc9b48
......@@ -63,6 +63,12 @@ const std::string& Metadata::Record::str() const
return m_value;
}
void Metadata::Record::unset()
{
m_isSet = false;
m_value.clear();
}
Metadata::Metadata(MediaLibraryPtr ml , IMetadata::EntityType entityType)
: m_ml( ml )
, m_entityType( entityType )
......@@ -151,6 +157,23 @@ bool Metadata::set( uint32_t type, int64_t value )
return set( type, str );
}
bool Metadata::unset( uint32_t type )
{
assert( isReady() == true );
auto it = std::find_if( begin( m_records ), end( m_records ), [type]( const Record& r ) {
return r.m_type == type;
});
if ( it != end( m_records ) )
{
static const std::string req = "DELETE FROM " + policy::MetadataTable::Name +
" WHERE id_media = ? AND entity_type = ? AND type = ?";
(*it).unset();
return sqlite::Tools::executeDelete( m_ml->getConn(), req, m_entityId,
m_entityType, type );
}
return true;
}
void Metadata::unset( sqlite::Connection* dbConn, IMetadata::EntityType entityType, uint32_t type )
{
static const std::string req = "DELETE FROM " + policy::MetadataTable::Name +
......
......@@ -56,6 +56,7 @@ public:
IMetadata& get( uint32_t type ) const;
bool set( uint32_t type, const std::string& value );
bool set( uint32_t type, int64_t value );
bool unset( uint32_t type );
static void unset( sqlite::Connection* dbConn, IMetadata::EntityType entityType, uint32_t type );
......@@ -71,6 +72,7 @@ private:
virtual bool isSet() const override;
virtual int64_t integer() const override;
virtual const std::string& str() const override;
void unset();
void set( const std::string& value );
private:
......
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