Пример #1
0
bool ContentNode::createContentNode(QSqlDatabase& database,
                                    ContentNode & node)
{
    QSqlQuery query(database);
    query.prepare ("insert into content "
                   "(name, location, title, authors, description, "
                   "last_access, publisher, md5, "
                   "size, rating, read_time, read_count, progress, attributes ) "
                   " values "
                   "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

    query.addBindValue(node.name());
    query.addBindValue(node.location());
    query.addBindValue(node.title());
    query.addBindValue(node.authors());
    query.addBindValue(node.description());
    query.addBindValue(node.last_access());
    query.addBindValue(node.publisher());

    query.addBindValue(node.md5());
    query.addBindValue(node.size());
    query.addBindValue(node.rating());
    query.addBindValue(node.read_time());
    query.addBindValue(node.read_count());
    query.addBindValue(node.progress());
    query.addBindValue(node.attributes());

    if (query.exec())
    {
        node.id_ = query.lastInsertId().toInt();
        return true;
    }
    return false;
}
Пример #2
0
bool ContentNode::updateContentNode(QSqlDatabase& database,
                                    const ContentNode & node)
{
    QSqlQuery query(database);
    query.prepare ("update content set "
                   " name = ?, location = ?, title = ?, authors = ?, "
                   " description = ?, last_access = ?, publisher = ?, md5 = ?, "
                   " size = ?, rating = ?, read_time = ?, read_count = ?, "
                   " progress = ?, attributes = ? "
                   " where id = ?");

    query.addBindValue(node.name());
    query.addBindValue(node.location());
    query.addBindValue(node.title());
    query.addBindValue(node.authors());
    query.addBindValue(node.description());
    query.addBindValue(node.last_access());
    query.addBindValue(node.publisher());

    query.addBindValue(node.md5());
    query.addBindValue(node.size());
    query.addBindValue(node.rating());
    query.addBindValue(node.read_time());
    query.addBindValue(node.read_count());

    query.addBindValue(node.progress());
    query.addBindValue(node.attributes());

    query.addBindValue(node.id());

    return query.exec();
}
Пример #3
0
/// Update content by url.
bool ContentNode::updateContentNodeByUrl(QSqlDatabase& database,
        const ContentNode & node,
        const QString & url)
{
    // Check at first.
    ContentNode tmp;
    bool found = getContentNodeByUrl(database, url, tmp);

    if (!found)
    {
        QSqlQuery query(database);
        query.prepare ("INSERT into content  "
                       " (name, location, title, authors, "
                       " description, last_access, publisher, md5, "
                       " size, rating, read_time, read_count, "
                       " progress, attributes) values "
                       " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");

        query.addBindValue(node.name());
        query.addBindValue(node.location());
        query.addBindValue(node.title());
        query.addBindValue(node.authors());
        query.addBindValue(node.description());
        query.addBindValue(node.last_access());
        query.addBindValue(node.publisher());
        query.addBindValue(url);
        query.addBindValue(node.size());
        query.addBindValue(node.rating());
        query.addBindValue(node.read_time());
        query.addBindValue(node.read_count());
        query.addBindValue(node.progress());
        query.addBindValue(node.attributes());

        if (!query.exec())
        {
            qDebug() << query.lastError();
            return false;
        }
    }
    else
    {
        QSqlQuery query(database);
        query.prepare ("update content set "
                       " name = ?, location = ?, title = ?, authors = ?, "
                       " description = ?, last_access = ?, publisher = ?,  "
                       " size = ?, rating = ?, read_time = ?, read_count = ?, "
                       " progress = ?, attributes = ? "
                       " where md5 = ?");

        query.addBindValue(node.name());
        query.addBindValue(node.location());
        query.addBindValue(node.title());
        query.addBindValue(node.authors());
        query.addBindValue(node.description());
        query.addBindValue(node.last_access());
        query.addBindValue(node.publisher());

        query.addBindValue(node.size());
        query.addBindValue(node.rating());
        query.addBindValue(node.read_time());
        query.addBindValue(node.read_count());

        query.addBindValue(node.progress());
        query.addBindValue(node.attributes());

        query.addBindValue(url);

        if (!query.exec())
        {
            qDebug() << query.lastError();
            return false;
        }
    }
    return true;
}