当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlQuery::isForwardOnly方法代码示例

本文整理汇总了C++中QSqlQuery::isForwardOnly方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQuery::isForwardOnly方法的具体用法?C++ QSqlQuery::isForwardOnly怎么用?C++ QSqlQuery::isForwardOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSqlQuery的用法示例。


在下文中一共展示了QSqlQuery::isForwardOnly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setQuery

/*!
    Resets the model and sets the data provider to be the given \a
    query. Note that the query must be active and must not be
    isForwardOnly().

    lastError() can be used to retrieve verbose information if there
    was an error setting the query.

    \sa query(), QSqlQuery::isActive(), QSqlQuery::setForwardOnly(), lastError()
*/
void QSqlQueryModel::setQuery(const QSqlQuery &query)
{
    Q_D(QSqlQueryModel);
    QSqlRecord newRec = query.record();
    bool columnsChanged = (newRec != d->rec);
    bool hasQuerySize = query.driver()->hasFeature(QSqlDriver::QuerySize);
    bool hasNewData = (newRec != QSqlRecord()) || !query.lastError().isValid();

    if (d->colOffsets.size() != newRec.count() || columnsChanged)
        d->initColOffsets(newRec.count());

    bool mustClearModel = d->bottom.isValid();
    if (mustClearModel) {
        d->atEnd = true;
        beginRemoveRows(QModelIndex(), 0, qMax(d->bottom.row(), 0));
        d->bottom = QModelIndex();
    }

    d->error = QSqlError();
    d->query = query;
    d->rec = newRec;

    if (mustClearModel)
        endRemoveRows();

    d->atEnd = false;

    if (columnsChanged && hasNewData)
        reset();

    if (!query.isActive() || query.isForwardOnly()) {
        d->atEnd = true;
        d->bottom = QModelIndex();
        if (query.isForwardOnly())
            d->error = QSqlError(QLatin1String("Forward-only queries "
                                               "cannot be used in a data model"),
                                 QString(), QSqlError::ConnectionError);
        else
            d->error = query.lastError();
        return;
    }
    QModelIndex newBottom;
    if (hasQuerySize && d->query.size() > 0) {
        newBottom = createIndex(d->query.size() - 1, d->rec.count() - 1);
        beginInsertRows(QModelIndex(), 0, qMax(0, newBottom.row()));
        d->bottom = createIndex(d->query.size() - 1, columnsChanged ? 0 : d->rec.count() - 1);
        d->atEnd = true;
        endInsertRows();
    } else {
        newBottom = createIndex(-1, d->rec.count() - 1);
    }
    d->bottom = newBottom;

    queryChange();

    // fetchMore does the rowsInserted stuff for incremental models
    fetchMore();
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:68,代码来源:qsqlquerymodel.cpp

示例2: execQuery

bool DbFunc::execQuery(QSqlQuery& query, const QString& sql,
                       const ArgList& args)
{
    // Executes an existing query (in place) with the supplied SQL/args.
    // THIS IS THE MAIN POINT THROUGH WHICH ALL QUERIES SHOULD BE EXECUTED.
    query.prepare(sql);
    addArgs(query, args);

#ifdef DEBUG_SQL_QUERY
    {
        qDebug() << "Executing:" << qUtf8Printable(sql);
        QDebug debug = qDebug().nospace();
        debug << "... args: ";
        DebugFunc::debugConcisely(debug, args);
    }  // endl on destruction
#endif

    bool success = query.exec();
#ifdef DEBUG_QUERY_END
    qDebug() << "... query finished";
#endif
    if (!success) {
        qCritical() << "Query failed; error was:" << query.lastError();
    }
#ifdef DEBUG_SQL_RESULT
    if (success && query.isSelect() && !query.isForwardOnly()) {
        qDebug() << "Resultset preview:";
        int row = 0;
        while (query.next()) {
            QDebug debug = qDebug().nospace();
            QSqlRecord rec = query.record();
            int ncols = rec.count();
            debug << "... row " << row << ": ";
            for (int col = 0; col < ncols; ++col) {
                if (col > 0) {
                    debug << "; ";
                }
                debug << rec.fieldName(col) << "=";
                DebugFunc::debugConcisely(debug, query.value(col));
            }
            ++row;
        }  // endl on destruction
        if (row == 0) {
            qDebug() << "<no rows>";
        }
        query.seek(QSql::BeforeFirstRow);  // the original starting position
    }
#endif
    return success;
    // The return value is boolean (success?).
    // Use query.next() to iterate through a result set; see
    // http://doc.qt.io/qt-4.8/sql-sqlstatements.html
}
开发者ID:RudolfCardinal,项目名称:camcops,代码行数:53,代码来源:dbfunc.cpp

示例3: property

 QScriptValue property(const QScriptValue &object,
                       const QScriptString &name, uint)
 {
     QSqlQuery query = qscriptvalue_cast<QSqlQuery>(object.data());
     if (name == str_length) {
         int s = query.size();
         if (s<0) {
             // Inefficient.
             if (query.last()) {
                 return query.at()+1;
             } else {
                 return 0;
             }
         } else {
             return s;
         }
     } else if (name == str_forwardOnly) {
         return query.isForwardOnly();
     }
     return engine()->undefinedValue();
 }
开发者ID:NikhilNJ,项目名称:screenplay-dx,代码行数:21,代码来源:qdeclarativesqldatabase.cpp


注:本文中的QSqlQuery::isForwardOnly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。