// --------------------------------------------------------------------------------- bool operator == (dp::Project const& lhs, dp::Project const& rhs) { if(lhs.id().isNull()) { return (rhs.id().isNull()); } return lhs.id() == rhs.id(); }
// --------------------------------------------------------------------------------- success Project::update ( const dp::Project& _p ) const { if ( _p.id().isNull()) { return error(); } QSqlQuery query; query.prepare ( UPDATE_PROJECT ); query.addBindValue ( _p.name() ); query.addBindValue ( _p.creationDate() ); query.addBindValue( _p.comment() ); query.addBindValue ( _p.id().toString() ); return execute ( query ); }
// --------------------------------------------------------------------------------- // private stuff: // --------------------------------------------------------------------------------- bool Project::exists ( const dp::Project& _project ) const { if ( _project.id().isNull() ) { return false; } QSqlQuery query; query.prepare ( SELECT_DISTINCT_PROJECT ); query.addBindValue ( _project.id().toString() ); if ( execute ( query ).has_failed() ) { return false; } return query.first(); }
// --------------------------------------------------------------------------------- success Project::insert ( dp::Project const& _p ) const { if ( _p.id().isNull()) { return error(); } QSqlQuery query; query.prepare ( INSERT_PROJECT ); query.addBindValue ( _p.id().toString() ); query.addBindValue ( _p.name() ); query.addBindValue ( _p.creationDate() ); query.addBindValue( _p.comment() ); if ( execute ( query ).has_failed() ) { return error(); } return successful(); }
// --------------------------------------------------------------------------------- success Project::remove(dp::Project const& _project) const { if ( _project.id().isNull()) { return error(); } if(!exists(_project)) { return successful(); } QSqlQuery query; query.prepare(REMOVE_PROJECT); query.addBindValue(_project.id().toString()); if(execute(query).has_failed()) { return error(); } return successful(); }
// --------------------------------------------------------------------------------- success Project::load ( dp::Project &p ) const { if ( p.id().isNull()) { return error(); } QSqlQuery query; query.prepare ( SELECT_DISTINCT_PROJECT ); query.addBindValue ( p.id().toString() ); if ( execute ( query ).has_failed() ) { kWarning()<<"last error: "<<query.lastError(); return error(); } if ( !query.first() ) { kWarning()<<"last error: "<<query.lastError(); return error(); } return assign_query_values_to_entity ( query, p ); }