示例#1
0
bool People::operator== (const People &other)
{
    if ( this->id() == other.id() &&
         this->name() == other.name() &&
         this->birthday() == other.birthday() &&
         this->biography() == other.biography() &&
         this->type() == other.type() )
    {
        return true;
    }

    return false;
}
/**
 * @brief Adds a person to the database.
 * Should not be called directly.
 *
 * @param People
 * @return bool
 */
bool DatabaseManager::insertNewPeople(People &people)
{
    QSqlQuery l_query(m_db);
    // If a people with the same name exist, we update it
    // else we insert
    if(existPeople(people.name())) {
        Macaw::DEBUG("[DatabaseManager.insertNewPeople] Name already known");
        People l_peopleToUpdate = getOnePeopleByName(people.name());
        people.setId(l_peopleToUpdate.id());
        if(!updatePeople(people)) {

            return false;
        }
    } else {
        l_query.prepare("INSERT INTO people ("
                                                "name, "
                                                "birthday, "
                                                "biography, "
                                                "imported, "
                                                "id_tmdb "
                                            ") VALUES ("
                                                ":name, "
                                                ":birthday, "
                                                ":biography, "
                                                ":imported, "
                                                ":id_tmdb "
                                            ")"
                        );
        l_query.bindValue(":name", people.name());
        l_query.bindValue(":birthday", people.birthday().toString(DATE_FORMAT));
        l_query.bindValue(":biography", people.biography());
        l_query.bindValue(":imported", people.isImported());
        l_query.bindValue(":id_tmdb", people.tmdbId());

        if (!l_query.exec()) {
            Macaw::DEBUG("In insertNewPeople():");
            Macaw::DEBUG(l_query.lastError().text());

            return false;
        }
        people.setId(l_query.lastInsertId().toInt());
    }

    return true;
}