?? qsqlquery.cpp
字號:
\c SELECT statement, e.g. in \code SELECT forename, surname FROM people; \endcode field 0 is \c forename and field 1 is \c surname. Using \c{SELECT *} is not recommended because the order 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();}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -