⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsqlquery.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    of the fields in the query is undefined.    An invalid QVariant is returned if field \a index does not    exist, if the query is inactive, or if the query is positioned on    an invalid record.    \sa previous() next() first() last() seek() isActive() isValid()*/QVariant QSqlQuery::value(int index) const{    if (isActive() && isValid() && (index > QSql::BeforeFirstRow))        return d->sqlResult->data(index);    qWarning("QSqlQuery::value: not positioned on a valid record");    return QVariant();}/*!    Returns the current internal position of the query. The first    record is at position zero. If the position is invalid, the    function returns QSql::BeforeFirstRow or    QSql::AfterLastRow, which are special negative values.    \sa previous() next() first() last() seek() isActive() isValid()*/int QSqlQuery::at() const{    return d->sqlResult->at();}/*!    Returns the text of the current query being used, or an empty    string if there is no current query text.    \sa executedQuery()*/QString QSqlQuery::lastQuery() const{    return d->sqlResult->lastQuery();}/*!    Returns the database driver associated with the query.*/const QSqlDriver *QSqlQuery::driver() const{    return d->sqlResult->driver();}/*!    Returns the result associated with the query.*/const QSqlResult* QSqlQuery::result() const{    return d->sqlResult;}/*!    Retrieves the record at position \a index, if available, and    positions the query on the retrieved record. The first record is    at position 0. Note that the query must be in an active state and    isSelect() must return true before calling this function.    If \a relative is false (the default), the following rules apply:    \list    \o If \a index is negative, the result is positioned before the    first record and false is returned.    \o Otherwise, an attempt is made to move to the record at position    \a index. If the record at position \a index could not be retrieved, the    result is positioned after the last record and false is returned. If    the record is successfully retrieved, true is returned.    \endlist    If \a relative is true, the following rules apply:    \list    \o If the result is currently positioned before the first    record or on the first record, and \a index is negative, there is no    change, and false is returned.    \o If the result is currently located after the last record, and    \a index is positive, there is no change, and false is returned.    \o If the result is currently located somewhere in the middle,    and the relative offset \a index moves the result below zero, the    result is positioned before the first record and false is    returned.    \o Otherwise, an attempt is made to move to the record \a index    records ahead of the current record (or \a index records behind the    current record if \a index is negative). If the record at offset \a index    could not be retrieved, the result is positioned after the last    record if \a index >= 0, (or before the first record if \a index is    negative), and false is returned. If the record is successfully    retrieved, true is returned.    \endlist    \sa next() previous() first() last() at() isActive() isValid()*/bool QSqlQuery::seek(int index, bool relative){    if (!isSelect() || !isActive())        return false;    int actualIdx;    if (!relative) { // arbitrary seek        if (index < 0) {            d->sqlResult->setAt(QSql::BeforeFirstRow);            return false;        }        actualIdx = index;    } else {        switch (at()) { // relative seek        case QSql::BeforeFirstRow:            if (index > 0)                actualIdx = index;            else {                return false;            }            break;        case QSql::AfterLastRow:            if (index < 0) {                d->sqlResult->fetchLast();                actualIdx = at() + index;            } else {                return false;            }            break;        default:            if ((at() + index) < 0) {                d->sqlResult->setAt(QSql::BeforeFirstRow);                return false;            }            actualIdx = at() + index;            break;        }    }    // let drivers optimize    if (isForwardOnly() && actualIdx < at()) {        qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query");        return false;    }    if (actualIdx == (at() + 1) && at() != QSql::BeforeFirstRow) {        if (!d->sqlResult->fetchNext()) {            d->sqlResult->setAt(QSql::AfterLastRow);            return false;        }        return true;    }    if (actualIdx == (at() - 1)) {        if (!d->sqlResult->fetchPrevious()) {            d->sqlResult->setAt(QSql::BeforeFirstRow);            return false;        }        return true;    }    if (!d->sqlResult->fetch(actualIdx)) {        d->sqlResult->setAt(QSql::AfterLastRow);        return false;    }    return true;}/*!    Retrieves the next record in the result, if available, and    positions the query on the retrieved record. Note that the result    must be in an active state and isSelect() must return true before    calling this function or it will do nothing and return false.    The following rules apply:    \list    \o If the result is currently located before the first    record, e.g. immediately after a query is executed, an attempt is    made to retrieve the first record.    \o If the result is currently located after the last record,    there is no change and false is returned.    \o If the result is located somewhere in the middle, an attempt    is made to retrieve the next record.    \endlist    If the record could not be retrieved, the result is positioned after    the last record and false is returned. If the record is successfully    retrieved, true is returned.    \sa previous() first() last() seek() at() isActive() isValid()*/bool QSqlQuery::next(){    if (!isSelect() || !isActive())        return false;    bool b = false;    switch (at()) {    case QSql::BeforeFirstRow:        b = d->sqlResult->fetchFirst();        return b;    case QSql::AfterLastRow:        return false;    default:        if (!d->sqlResult->fetchNext()) {            d->sqlResult->setAt(QSql::AfterLastRow);            return false;        }        return true;    }}/*!    Retrieves the previous record in the result, if available, and    positions the query on the retrieved record. Note that the result    must be in an active state and isSelect() must return true before    calling this function or it will do nothing and return false.    The following rules apply:    \list    \o If the result is currently located before the first record,    there is no change and false is returned.    \o If the result is currently located after the last record, an    attempt is made to retrieve the last record.    \o If the result is somewhere in the middle, an attempt is made    to retrieve the previous record.    \endlist    If the record could not be retrieved, the result is positioned    before the first record and false is returned. If the record is    successfully retrieved, true is returned.    \sa next() first() last() seek() at() isActive() isValid()*/bool QSqlQuery::previous(){    if (!isSelect() || !isActive())        return false;    if (isForwardOnly()) {        qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query");        return false;    }    bool b = false;    switch (at()) {    case QSql::BeforeFirstRow:        return false;    case QSql::AfterLastRow:        b = d->sqlResult->fetchLast();        return b;    default:        if (!d->sqlResult->fetchPrevious()) {            d->sqlResult->setAt(QSql::BeforeFirstRow);            return false;        }        return true;    }}/*!    Retrieves the first record in the result, if available, and    positions the query on the retrieved record. Note that the result    must be in an active state and isSelect() must return true before    calling this function or it will do nothing and return false.    Returns true if successful. If unsuccessful the query position is    set to an invalid position and false is returned.    \sa next() previous() last() seek() at() isActive() isValid()*/bool QSqlQuery::first(){    if (!isSelect() || !isActive())        return false;    if (isForwardOnly() && at() > QSql::BeforeFirstRow) {        qWarning("QSqlQuery::seek: cannot seek backwards in a forward only query");        return false;    }    bool b = false;    b = d->sqlResult->fetchFirst();    return b;}/*!    Retrieves the last record in the result, if available, and    positions the query on the retrieved record. Note that the result    must be in an active state and isSelect() must return true before    calling this function or it will do nothing and return false.    Returns true if successful. If unsuccessful the query position is    set to an invalid position and false is returned.    \sa next() previous() first() seek() at() isActive() isValid()*/bool QSqlQuery::last(){    if (!isSelect() || !isActive())        return false;    bool b = false;    b = d->sqlResult->fetchLast();    return b;}/*!    Returns the size of the result (number of rows returned), or -1    if the size cannot be determined or if the database does not    support reporting information about query sizes. Note that for    non-\c SELECT statements (isSelect() returns false), size() will    return -1. If the query is not active (isActive() returns false),    -1 is returned.    To determine the number of rows affected by a non-\c SELECT    statement, use numRowsAffected().    \sa isActive() numRowsAffected() QSqlDriver::hasFeature()*/int QSqlQuery::size() const{    if (isActive() && d->sqlResult->driver()->hasFeature(QSqlDriver::QuerySize))        return d->sqlResult->size();    return -1;}/*!    Returns the number of rows affected by the result's SQL statement,    or -1 if it cannot be determined. Note that for \c SELECT    statements, the value is undefined; use size() instead. If the    query is not active (isActive() returns false), -1 is returned.    \sa size() QSqlDriver::hasFeature()*/int QSqlQuery::numRowsAffected() const{    if (isActive())        return d->sqlResult->numRowsAffected();    return -1;}/*!    Returns error information about the last error (if any) that    occurred with this query.    \sa QSqlError, QSqlDatabase::lastError()*/QSqlError QSqlQuery::lastError() const{    return d->sqlResult->lastError();}/*!    Returns true if the query is currently positioned on a valid    record; otherwise returns false.*/bool QSqlQuery::isValid() const{    return d->sqlResult->isValid();}/*!    Returns true if the query is currently active; otherwise returns    false.*/bool QSqlQuery::isActive() const{    return d->sqlResult->isActive();}/*!    Returns true if the current query is a \c SELECT statement;    otherwise returns false.*/bool QSqlQuery::isSelect() const{    return d->sqlResult->isSelect();}/*!    Returns true if you can only scroll forward through a result set;    otherwise returns false.    \sa setForwardOnly(), next()*/bool QSqlQuery::isForwardOnly() const{    return d->sqlResult->isForwardOnly();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -