コード例 #1
0
bool Database::addPlaylist(const Playlist &playlist)
{
    try
    {
        _work.parameterized("INSERT INTO playlists (user_id, name, is_public) VALUES ($1, $2, $3);")
                (playlist.userId())(playlist.name())(playlist.isPublic()).exec();
    }
    catch (const pqxx::unique_violation &e)
    {
        return false;
    }

    return true;
}
コード例 #2
0
/**
 * @brief Adds a playlist to the database.
 *
 * @param Playlist
 * @return bool
 */
bool DatabaseManager::insertNewPlaylist(Playlist &playlist)
{
    QSqlQuery l_query(m_db);
    l_query.prepare("INSERT INTO playlists (name, creation_date, rate) "
                    "VALUES (:name, :creation_date, :rate)");
    l_query.bindValue(":name", playlist.name());
    l_query.bindValue(":creation_date", playlist.creationDate().toTime_t());
    l_query.bindValue(":rate", playlist.rate());

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

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

    return true;
}
コード例 #3
0
UpdateStatus Database::updatePlaylist(const Playlist &playlist)
{
    pqxx::result res;
    try
    {
        res = _work.parameterized("UPDATE playlists "
                                  "SET name=$1, "
                                  "is_public=$2 "
                                  "WHERE id=$3 "
                                  "  AND user_id=$4;")
                                  (playlist.name())(playlist.isPublic())
                                  (playlist.id())(playlist.userId()).exec();
    }
    catch (const pqxx::unique_violation &e)
    {
        return UpdateStatus::CONFLICT;
    }

    return res.affected_rows() == 1 ? UpdateStatus::UPDATED : UpdateStatus::NOT_FOUND;
}