📄 qsqlquery.3qt
字号:
.br q.addBindValue( "Testname" );.br q.addBindValue( "Lastname" );.br q.exec();.br.fi.PPSee also QSqlDatabase, QSqlCursor, QVariant, and Database Classes..SH MEMBER FUNCTION DOCUMENTATION.SH "QSqlQuery::QSqlQuery ( QSqlResult * r )"Creates a QSqlQuery object which uses the QSqlResult \fIr\fR to communicate with a database..SH "QSqlQuery::QSqlQuery ( const QString & query = QString::null, QSqlDatabase * db = 0 )"Creates a QSqlQuery object using the SQL \fIquery\fR and the database \fIdb\fR. If \fIdb\fR is 0, (the default), the application's default database is used..PPSee also QSqlDatabase..SH "QSqlQuery::QSqlQuery ( const QSqlQuery & other )"Constructs a copy of \fIother\fR..SH "QSqlQuery::~QSqlQuery ()\fC [virtual]\fR"Destroys the object and frees any allocated resources..SH "void QSqlQuery::addBindValue ( const QVariant & val )"Adds the value \fIval\fR to the list of values when using positional value binding. The order of the addBindValue() calls determines which placeholder a value will be bound to in the prepared query. Placeholder values are cleared after the query has been executed..PPSee also bindValue(), prepare(), and exec()..SH "void QSqlQuery::afterSeek ()\fC [virtual protected]\fR"Protected virtual function called after the internal record pointer is moved to a new record. The default implementation does nothing..SH "int QSqlQuery::at () const"Returns the current internal position of the query. The first record is at position zero. If the position is invalid, a QSql::Location will be returned indicating the invalid position..PPSee also isValid()..PPExample: sql/overview/navigating/main.cpp..SH "void QSqlQuery::beforeSeek ()\fC [virtual protected]\fR"Protected virtual function called before the internal record pointer is moved to a new record. The default implementation does nothing..SH "void QSqlQuery::bindValue ( const QString & placeholder, const QVariant & val )"Set the placeholder \fIplaceholder\fR to be bound to value \fIval\fR in the prepared statement. Note that the placeholder mark (e.g \fC:\fR) should be included when specifying the placeholder name. Placeholder values are cleared after the query has been executed..PPSee also addBindValue(), prepare(), and exec()..SH "void QSqlQuery::bindValue ( int pos, const QVariant & val )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSet the placeholder in position \fIpos\fR to be bound to value \fIval\fR in the prepared statement. Field numbering starts at 0. Placeholder values are cleared after the query has been executed..PPSee also addBindValue(), prepare(), and exec()..SH "const QSqlDriver * QSqlQuery::driver () const"Returns the database driver associated with the query..SH "bool QSqlQuery::exec ( const QString & query )\fC [virtual]\fR"Executes the SQL in \fIquery\fR. Returns TRUE and sets the query state to active if the query was successful; otherwise returns FALSE and sets the query state to inactive. The \fIquery\fR string must use syntax appropriate for the SQL database being queried, for example, standard SQL..PPAfter the query is executed, the query is positioned on an \fIinvalid\fR record, and must be navigated to a valid record before data values can be retrieved, e.g. using next()..PPNote that the last error for this query is reset when exec() is called..PPSee also isActive(), isValid(), next(), prev(), first(), last(), and seek()..PPExamples:.)l sql/overview/basicbrowsing/main.cpp, sql/overview/basicbrowsing2/main.cpp, and sql/overview/basicdatamanip/main.cpp..SH "bool QSqlQuery::exec ()"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPExecutes a previously prepared SQL query. Returns TRUE if the query is executed successfully; otherwise returns FALSE..PPSee also prepare(), bindValue(), and addBindValue()..SH "bool QSqlQuery::first ()\fC [virtual]\fR"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..PPExample: sql/overview/navigating/main.cpp..SH "bool QSqlQuery::isActive () const"Returns TRUE if the query is currently active; otherwise returns FALSE..PPExamples:.)l sql/overview/basicbrowsing/main.cpp, sql/overview/basicbrowsing2/main.cpp, sql/overview/basicdatamanip/main.cpp, sql/overview/navigating/main.cpp, and sql/overview/retrieve1/main.cpp..SH "bool QSqlQuery::isForwardOnly () const"Returns TRUE when you can only scroll forward through a result set otherwise FALSE.SH "bool QSqlQuery::isNull ( int field ) const"Returns TRUE if the query is active and positioned on a valid record and the \fIfield\fR is NULL; otherwise returns FALSE. Note that, for some drivers, isNull() will not return accurate information until after an attempt is made to retrieve data..PPSee also isActive(), isValid(), and value()..SH "bool QSqlQuery::isSelect () const"Returns TRUE if the current query is a \fCSELECT\fR statement; otherwise returns FALSE..SH "bool QSqlQuery::isValid () const"Returns TRUE if the query is currently positioned on a valid record; otherwise returns FALSE..SH "bool QSqlQuery::last ()\fC [virtual]\fR"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..PPExample: sql/overview/navigating/main.cpp..SH "QSqlError QSqlQuery::lastError () const"Returns error information about the last error (if any) that occurred..PPSee also QSqlError..SH "QString QSqlQuery::lastQuery () const"Returns the text of the current query being used, or QString::null if there is no current query text..SH "bool QSqlQuery::next ()\fC [virtual]\fR"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..PPThe following rules apply:.TPIf 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..IP.TPIf the result is currently located after the last record, there is no change and FALSE is returned..IP.TPIf the result is located somewhere in the middle, an attempt is made to retrieve the next record..PPIf 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..PPSee also at() and isValid()..PPExamples:.)l sql/overview/basicbrowsing/main.cpp, sql/overview/basicbrowsing2/main.cpp, sql/overview/delete/main.cpp, sql/overview/order1/main.cpp, sql/overview/retrieve1/main.cpp, sql/overview/subclass4/main.cpp, and sql/overview/subclass5/main.cpp..SH "int QSqlQuery::numRowsAffected () const"Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined. Note that for SELECT statements, this value will be the same as size(). If the query is not active (isActive() returns FALSE), -1 is returned..PPSee also size() and QSqlDriver::hasFeature()..PPExamples:.)l sql/overview/basicbrowsing2/main.cpp and sql/overview/basicdatamanip/main.cpp..SH "QSqlQuery & QSqlQuery::operator= ( const QSqlQuery & other )"Assigns \fIother\fR to the query..SH "bool QSqlQuery::prepare ( const QString & query )"Prepares the SQL query \fIquery\fR for execution. The query may contain placeholders for binding values. Note that placeholder markers are usually database dependent..PPSee also exec(), bindValue(), and addBindValue()..SH "bool QSqlQuery::prev ()\fC [virtual]\fR"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..PPThe following rules apply:.TPIf the result is currently located before the first record, there is no change and FALSE is returned..IP.TPIf the result is currently located after the last record, an attempt is made to retrieve the last record..IP.TPIf the result is somewhere in the middle, an attempt is made to retrieve the previous record..PPIf 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..PPSee also at()..SH "const QSqlResult * QSqlQuery::result () const"Returns the result associated with the query..SH "bool QSqlQuery::seek ( int i, bool relative = FALSE )\fC [virtual]\fR"Retrieves the record at position (offset) \fIi\fR, 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..PPIf \fIrelative\fR is FALSE (the default), the following rules apply:.TPIf \fIi\fR is negative, the result is positioned before the first record and FALSE is returned..TPOtherwise, an attempt is made to move to the record at position \fIi\fR. If the record at position \fIi\fR 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..PPIf \fIrelative\fR is TRUE, the following rules apply:.TPIf the result is currently positioned before the first record or on the first record, and \fIi\fR is negative, there is no change, and FALSE is returned..TPIf the result is currently located after the last record, and \fIi\fR is positive, there is no change, and FALSE is returned..TPIf the result is currently located somewhere in the middle, and the relative offset \fIi\fR moves the result below zero, the result is positioned before the first record and FALSE is returned..TPOtherwise, an attempt is made to move to the record \fIi\fR records ahead of the current record (or \fIi\fR records behind the current record if \fIi\fR is negative). If the record at offset \fIi\fR could not be retrieved, the result is positioned after the last record if \fIi\fR >= 0, (or before the first record if \fIi\fR is negative), and FALSE is returned. If the record is successfully retrieved, TRUE is returned..PPExample: sql/overview/navigating/main.cpp..SH "void QSqlQuery::setForwardOnly ( bool forward )"Sets forward only mode to \fIforward\fR. If forward is TRUE only next() and seek() with positive values are allowed for navigating the results. Forward only mode needs far less memory since results do not have to be cached. Forward only mode is off by default. Note that it is not possible to use forward only mode with data aware widgets like QDataTable since they need to be able to scroll backward..PPSee also next() and seek()..SH "int QSqlQuery::size () const"Returns the size of the result, (number of rows returned), or -1 if the size cannot be determined or the database does not support reporting information about query sizes. Note that for non-SELECT statements (isSelect() returns FALSE), size() will return -1. If the query is not active (isActive() returns FALSE), -1 is returned..PPTo determine the number of rows affected by a non-SELECT statement, use numRowsAffected()..PPSee also isActive(), numRowsAffected(), and QSqlDriver::hasFeature()..PPExample: sql/overview/navigating/main.cpp..SH "QVariant QSqlQuery::value ( int i ) const\fC [virtual]\fR"Returns the value of the \fIi\fR-th field in the query (zero based)..PPThe fields are numbered from left to right using the text of the \fCSELECT\fR statement, e.g. in "SELECT forename, surname FROM people", field 0 is forename and field 1 is surname. Using \fCSELECT *\fR is not recommended because the order of the fields in the query is undefined..PPAn invalid QVariant is returned if field \fIi\fR does not exist, if the query is inactive, or if the query is positioned on an invalid record..PPSee also prev(), next(), first(), last(), seek(), isActive(), and isValid()..PPExamples:.)l sql/overview/basicbrowsing/main.cpp, sql/overview/basicbrowsing2/main.cpp, sql/overview/retrieve1/main.cpp, sql/overview/subclass3/main.cpp, sql/overview/subclass4/main.cpp, sql/overview/subclass5/main.cpp, and sql/overview/table4/main.cpp..SH "SEE ALSO".BR http://doc.trolltech.com/qsqlquery.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qsqlquery.3qt) and the Qtversion (3.1.1).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -