void PostgreSqlStorage::setUserSetting(UserId userId, const QString &settingName, const QVariant &data)
{
    QByteArray rawData;
    QDataStream out(&rawData, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_2);
    out << data;

    QSqlDatabase db = logDb();
    QSqlQuery selectQuery(db);
    selectQuery.prepare(queryString("select_user_setting"));
    selectQuery.bindValue(":userid", userId.toInt());
    selectQuery.bindValue(":settingname", settingName);
    safeExec(selectQuery);

    QString setQueryString;
    if (!selectQuery.first()) {
        setQueryString = queryString("insert_user_setting");
    }
    else {
        setQueryString = queryString("update_user_setting");
    }

    QSqlQuery setQuery(db);
    setQuery.prepare(setQueryString);
    setQuery.bindValue(":userid", userId.toInt());
    setQuery.bindValue(":settingname", settingName);
    setQuery.bindValue(":settingvalue", rawData);
    safeExec(setQuery);
}
void PostgreSqlStorage::setUserSetting(UserId userId, const QString &settingName, const QVariant &data)
{
    QByteArray rawData;
    QDataStream out(&rawData, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_2);
    out << data;

    QSqlDatabase db = logDb();
    QSqlQuery selectQuery(db);
    selectQuery.prepare(queryString("select_user_setting"));
    selectQuery.bindValue(":userid", userId.toInt());
    selectQuery.bindValue(":settingname", settingName);
    safeExec(selectQuery);

    QString setQueryString;
    if (!selectQuery.first()) {
        setQueryString = queryString("insert_user_setting");
    }
    else {
        setQueryString = queryString("update_user_setting");
    }

    QSqlQuery setQuery(db);
    setQuery.prepare(setQueryString);
    setQuery.bindValue(":userid", userId.toInt());
    setQuery.bindValue(":settingname", settingName);
    setQuery.bindValue(":settingvalue", rawData);
    safeExec(setQuery);
}