<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- /home/reggie/tmp/qt-3.1-reggie-23625/qt-x11-free-3.1.1/src/sql/qsqlquery.cpp:79 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>QSqlQuery Class</title> <style type="text/css"><!-- h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } body { background: #ffffff; color: black; } --></style> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr bgcolor="#E5E5E5"> <td valign=center> <a href="index.html"> <font color="#004faf">Home</font></a> | <a href="classes.html"> <font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"> <font color="#004faf">Main Classes</font></a> | <a href="annotated.html"> <font color="#004faf">Annotated</font></a> | <a href="groups.html"> <font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"> <font color="#004faf">Functions</font></a> </td> <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QSqlQuery Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1> <p>The QSqlQuery class provides a means of executing and manipulating SQL statements. <a href="#details">More...</a> <p><tt>#include <<a href="qsqlquery-h.html">qsqlquery.h</a>></tt> <p>Inherited by <a href="qsqlcursor.html">QSqlCursor</a>. <p><a href="qsqlquery-members.html">List of all member functions.</a> <h2>Public Members</h2> <ul> <li><div class=fn><a href="#QSqlQuery"><b>QSqlQuery</b></a> ( QSqlResult * r )</div></li> <li><div class=fn><a href="#QSqlQuery-2"><b>QSqlQuery</b></a> ( const QString & query = QString::null, QSqlDatabase * db = 0 )</div></li> <li><div class=fn><a href="#QSqlQuery-3"><b>QSqlQuery</b></a> ( const QSqlQuery & other )</div></li> <li><div class=fn>QSqlQuery & <a href="#operator-eq"><b>operator=</b></a> ( const QSqlQuery & other )</div></li> <li><div class=fn>virtual <a href="#~QSqlQuery"><b>~QSqlQuery</b></a> ()</div></li> <li><div class=fn>bool <a href="#isValid"><b>isValid</b></a> () const</div></li> <li><div class=fn>bool <a href="#isActive"><b>isActive</b></a> () const</div></li> <li><div class=fn>bool <a href="#isNull"><b>isNull</b></a> ( int field ) const</div></li> <li><div class=fn>int <a href="#at"><b>at</b></a> () const</div></li> <li><div class=fn>QString <a href="#lastQuery"><b>lastQuery</b></a> () const</div></li> <li><div class=fn>int <a href="#numRowsAffected"><b>numRowsAffected</b></a> () const</div></li> <li><div class=fn>QSqlError <a href="#lastError"><b>lastError</b></a> () const</div></li> <li><div class=fn>bool <a href="#isSelect"><b>isSelect</b></a> () const</div></li> <li><div class=fn>int <a href="#size"><b>size</b></a> () const</div></li> <li><div class=fn>const QSqlDriver * <a href="#driver"><b>driver</b></a> () const</div></li> <li><div class=fn>const QSqlResult * <a href="#result"><b>result</b></a> () const</div></li> <li><div class=fn>bool <a href="#isForwardOnly"><b>isForwardOnly</b></a> () const</div></li> <li><div class=fn>void <a href="#setForwardOnly"><b>setForwardOnly</b></a> ( bool forward )</div></li> <li><div class=fn>virtual bool <a href="#exec"><b>exec</b></a> ( const QString & query )</div></li> <li><div class=fn>virtual QVariant <a href="#value"><b>value</b></a> ( int i ) const</div></li> <li><div class=fn>virtual bool <a href="#seek"><b>seek</b></a> ( int i, bool relative = FALSE )</div></li> <li><div class=fn>virtual bool <a href="#next"><b>next</b></a> ()</div></li> <li><div class=fn>virtual bool <a href="#prev"><b>prev</b></a> ()</div></li> <li><div class=fn>virtual bool <a href="#first"><b>first</b></a> ()</div></li> <li><div class=fn>virtual bool <a href="#last"><b>last</b></a> ()</div></li> <li><div class=fn>bool <a href="#exec-2"><b>exec</b></a> ()</div></li> <li><div class=fn>bool <a href="#prepare"><b>prepare</b></a> ( const QString & query )</div></li> <li><div class=fn>void <a href="#bindValue"><b>bindValue</b></a> ( const QString & placeholder, const QVariant & val )</div></li> <li><div class=fn>void <a href="#bindValue-2"><b>bindValue</b></a> ( int pos, const QVariant & val )</div></li> <li><div class=fn>void <a href="#addBindValue"><b>addBindValue</b></a> ( const QVariant & val )</div></li> </ul> <h2>Protected Members</h2> <ul> <li><div class=fn>virtual void <a href="#beforeSeek"><b>beforeSeek</b></a> ()</div></li> <li><div class=fn>virtual void <a href="#afterSeek"><b>afterSeek</b></a> ()</div></li> </ul> <hr><a name="details"></a><h2>Detailed Description</h2> The QSqlQuery class provides a means of executing and manipulating SQL statements. <p> <p> QSqlQuery encapsulates the functionality involved in creating, navigating and retrieving data from SQL queries which are executed on a <a href="qsqldatabase.html">QSqlDatabase</a>. It can be used to execute DML (data manipulation language) statements, e.g. <tt>SELECT</tt>, <tt>INSERT</tt>, <tt>UPDATE</tt> and <tt>DELETE</tt>, and also DDL (data definition language) statements, e.g. <tt>CREATE TABLE</tt>. It can also be used to execute database-specific commands which are not standard SQL (e.g. <tt>SET DATESTYLE=ISO</tt> for PostgreSQL). <p> Successfully executed SQL statements set the query's state to active (<a href="#isActive">isActive</a>() returns TRUE); otherwise the query's state is set to inactive. In either case, when executing a new SQL statement, the query is positioned on an invalid record; an active query must be navigated to a valid record (so that <a href="#isValid">isValid</a>() returns TRUE) before values can be retrieved. <p> Navigating records is performed with the following functions: <p> <ul> <li> <a href="#next">next</a>() <li> <a href="#prev">prev</a>() <li> <a href="#first">first</a>() <li> <a href="#last">last</a>() <li> <tt></tt><a href="#seek">seek</a>(int) </ul> <p> These functions allow the programmer to move forward, backward or arbitrarily through the records returned by the query. Once an active query is positioned on a valid record, data can be retrieved using <a href="#value">value</a>(). All data is transferred from the SQL backend using QVariants. <p> For example: <p> <pre> QSqlQuery query( "SELECT name FROM customer" ); while ( query.<a href="#next">next</a>() ) { <a href="qstring.html">QString</a> name = query.<a href="#value">value</a>(0).toString(); doSomething( name ); } </pre> <p> To access the data returned by a query, use the value() method. Each field in the data returned by a SELECT statement is accessed by passing the field's position in the statement, starting from 0. For the sake of efficiency there are no methods to access a field by name. (The <a href="qsqlcursor.html">QSqlCursor</a> class provides a higher level interface for that generates SQL automatically and through which fields are accessed by name.) <p> QSqlQuery supports prepared query execution and binding of parameter values to placeholders. Note that only input values may be bound. Be aware that not all databases support these features. Currently only the Oracle and ODBC drivers have proper prepared query support, but the rest of the drivers support this by emulating the missing features (the placeholders are simply replaced with the actual value when the query is executed). It is also important to know that different databases use different placeholder marks for value binding. Oracle uses a <tt>:</tt> character followed by a placeholder name, while ODBC only uses a <tt>?</tt> character to identify a placeholder. In an attempt to make this database independant we substitute the markers if you try to use ODBC markers in a query to an Oracle database and vice versa. Note that you can't mix the different bind styles by binding some values using named placeholders and some using positional placeholders. <p> Example: <p> <pre> // Named binding using named placeholders QSqlQuery q; q.<a href="#prepare">prepare</a>( "insert into mytable (id, name, lastname) values (:id, :name, :lname)" ); q.<a href="#bindValue">bindValue</a>( ":id", 0 ); q.<a href="#bindValue">bindValue</a>( ":name", "Testname" ); q.<a href="#bindValue">bindValue</a>( ":lname", "Lastname" ); q.<a href="#exec">exec</a>(); // Positional binding using named placeholders QSqlQuery q; q.<a href="#prepare">prepare</a>( "insert into mytable (id, name, lastname) values (:id, :name, :lname)" ); q.<a href="#bindValue">bindValue</a>( 0, 0 ); q.<a href="#bindValue">bindValue</a>( 1, "Testname" ); q.<a href="#bindValue">bindValue</a>( 2, "Lastname" ); q.<a href="#exec">exec</a>(); // Binding values using positional placeholders QSqlQuery q; q.<a href="#prepare">prepare</a>( "insert into mytable (id, name, lastname) values (?, ?, ?)" ); q.<a href="#bindValue">bindValue</a>( 0, 0 ); q.<a href="#bindValue">bindValue</a>( 1, "Testname" ); q.<a href="#bindValue">bindValue</a>( 2, "Lastname" ); q.<a href="#exec">exec</a>(); // or alternatively q.<a href="#prepare">prepare</a>( "insert into mytable (id, name, lastname) values (?, ?, ?)" ); q.<a href="#addBindValue">addBindValue</a>( 0 ); q.<a href="#addBindValue">addBindValue</a>( "Testname" ); q.<a href="#addBindValue">addBindValue</a>( "Lastname" ); q.<a href="#exec">exec</a>(); </pre> <p> <p>See also <a href="qsqldatabase.html">QSqlDatabase</a>, <a href="qsqlcursor.html">QSqlCursor</a>, <a href="qvariant.html">QVariant</a>, and <a href="database.html">Database Classes</a>. <hr><h2>Member Function Documentation</h2> <h3 class=fn><a name="QSqlQuery"></a>QSqlQuery::QSqlQuery ( <a href="qsqlresult.html">QSqlResult</a> * r ) </h3> Creates a QSqlQuery object which uses the <a href="qsqlresult.html">QSqlResult</a> <em>r</em> to communicate with a database. <h3 class=fn><a name="QSqlQuery-2"></a>QSqlQuery::QSqlQuery ( const <a href="qstring.html">QString</a> & query = QString::null, <a href="qsqldatabase.html">QSqlDatabase</a> * db = 0 ) </h3> Creates a QSqlQuery object using the SQL <em>query</em> and the database <em>db</em>. If <em>db</em> is 0, (the default), the application's default database is used. <p> <p>See also <a href="qsqldatabase.html">QSqlDatabase</a>. <h3 class=fn><a name="QSqlQuery-3"></a>QSqlQuery::QSqlQuery ( const <a href="qsqlquery.html">QSqlQuery</a> & other ) </h3> Constructs a copy of <em>other</em>. <h3 class=fn><a name="~QSqlQuery"></a>QSqlQuery::~QSqlQuery ()<tt> [virtual]</tt> </h3> Destroys the object and frees any allocated resources. <h3 class=fn>void <a name="addBindValue"></a>QSqlQuery::addBindValue ( const <a href="qvariant.html">QVariant</a> & val ) </h3> Adds the value <em>val</em> to the list of values when using positional value binding. The order of the <a href="#addBindValue">addBindValue</a>() calls determines which placeholder a value will be bound to in the prepared query. Placeholder values are cleared after the query has been executed. <p> <p>See also <a href="#bindValue">bindValue</a>(), <a href="#prepare">prepare</a>(), and <a href="#exec">exec</a>(). <h3 class=fn>void <a name="afterSeek"></a>QSqlQuery::afterSeek ()<tt> [virtual protected]</tt> </h3> Protected virtual function called after the internal record pointer is moved to a new record. The default implementation does nothing. <h3 class=fn>int <a name="at"></a>QSqlQuery::at () const </h3> 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. <p> <p>See also <a href="#isValid">isValid</a>(). <p>Example: <a href="sql.html#x2099">sql/overview/navigating/main.cpp</a>. <h3 class=fn>void <a name="beforeSeek"></a>QSqlQuery::beforeSeek ()<tt> [virtual protected]</tt> </h3> Protected virtual function called before the internal record pointer is moved to a new record. The default implementation does nothing. <h3 class=fn>void <a name="bindValue"></a>QSqlQuery::bindValue ( const <a href="qstring.html">QString</a> & placeholder, const <a href="qvariant.html">QVariant</a> & val ) </h3> Set the placeholder <em>placeholder</em> to be bound to value <em>val</em> in the prepared statement. Note that the placeholder mark (e.g <tt>:</tt>) should be included when specifying the placeholder name. Placeholder values are cleared after the query has been executed. <p> <p>See also <a href="#addBindValue">addBindValue</a>(), <a href="#prepare">prepare</a>(), and <a href="#exec">exec</a>(). <h3 class=fn>void <a name="bindValue-2"></a>QSqlQuery::bindValue ( int pos, const <a href="qvariant.html">QVariant</a> & val ) </h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function. <p> Set the placeholder in position <em>pos</em> to be bound to value <em>val</em> in the prepared statement. Field numbering starts at 0. Placeholder values are cleared after the query has been executed. <p> <p>See also <a href="#addBindValue">addBindValue</a>(), <a href="#prepare">prepare</a>(), and <a href="#exec">exec</a>(). <h3 class=fn>const <a href="qsqldriver.html">QSqlDriver</a> * <a name="driver"></a>QSqlQuery::driver () const </h3> Returns the database driver associated with the query. <h3 class=fn>bool <a name="exec"></a>QSqlQuery::exec ( const <a href="qstring.html">QString</a> & query )<tt> [virtual]</tt> </h3> Executes the SQL in <em>query</em>. 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 <em>query</em> string must use syntax appropriate for the SQL database being queried, for example, standard SQL. <p> After the query is executed, the query is positioned on an <em>invalid</em> record, and must be navigated to a valid record before data values can be retrieved, e.g. using <a href="#next">next</a>(). <p> Note that the last error for this query is reset when <a href="#exec">exec</a>() is called. <p> <p>See also <a href="#isActive">isActive</a>(), <a href="#isValid">isValid</a>(), <a href="#next">next</a>(), <a href="#prev">prev</a>(), <a href="#first">first</a>(), <a href="#last">last</a>(), and <a href="#seek">seek</a>(). <p>Examples: <a href="sql.html#x2087">sql/overview/basicbrowsing/main.cpp</a>, <a href="sql.html#x2091">sql/overview/basicbrowsing2/main.cpp</a>, and <a href="sql.html#x2096">sql/overview/basicdatamanip/main.cpp</a>. <h3 class=fn>bool <a name="exec-2"></a>QSqlQuery::exec () </h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function. <p> Executes a previously prepared SQL query. Returns TRUE if the query is executed successfully; otherwise returns FALSE. <p> <p>See also <a href="#prepare">prepare</a>(), <a href="#bindValue">bindValue</a>(), and <a href="#addBindValue">addBindValue</a>(). <h3 class=fn>bool <a name="first"></a>QSqlQuery::first ()<tt> [virtual]</tt> </h3> 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 <a href="#isSelect">isSelect</a>() 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. <p>Example: <a href="sql.html#x2100">sql/overview/navigating/main.cpp</a>. <h3 class=fn>bool <a name="isActive"></a>QSqlQuery::isActive () const </h3> Returns TRUE if the query is currently active; otherwise returns FALSE. <p>Examples: <a href="sql.html#x2088">sql/overview/basicbrowsing/main.cpp</a>, <a href="sql.html#x2092">sql/overview/basicbrowsing2/main.cpp</a>, <a href="sql.html#x2097">sql/overview/basicdatamanip/main.cpp</a>, <a href="sql.html#x2101">sql/overview/navigating/main.cpp</a>, and <a href="sql.html#x2105">sql/overview/retrieve1/main.cpp</a>. <h3 class=fn>bool <a name="isForwardOnly"></a>QSqlQuery::isForwardOnly () const </h3> Returns TRUE when you can only scroll forward through a result set otherwise FALSE <h3 class=fn>bool <a name="isNull"></a>QSqlQuery::isNull ( int field ) const </h3> Returns TRUE if the query is active and positioned on a valid record and the <em>field</em> is NULL; otherwise returns FALSE. Note that, for some drivers, <a href="#isNull">isNull</a>() will not return accurate information until after an attempt is made to retrieve data. <p> <p>See also <a href="#isActive">isActive</a>(), <a href="#isValid">isValid</a>(), and <a href="#value">value</a>(). <h3 class=fn>bool <a name="isSelect"></a>QSqlQuery::isSelect () const </h3> Returns TRUE if the current query is a <tt>SELECT</tt> statement; otherwise returns FALSE. <h3 class=fn>bool <a name="isValid"></a>QSqlQuery::isValid () const </h3> Returns TRUE if the query is currently positioned on a valid record; otherwise returns FALSE. <h3 class=fn>bool <a name="last"></a>QSqlQuery::last ()<tt> [virtual]</tt> </h3> 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 <a href="#isSelect">isSelect</a>() 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. <p>Example: <a href="sql.html#x2102">sql/overview/navigating/main.cpp</a>. <h3 class=fn><a href="qsqlerror.html">QSqlError</a> <a name="lastError"></a>QSqlQuery::lastError () const </h3> Returns error information about the last error (if any) that occurred. <p> <p>See also <a href="qsqlerror.html">QSqlError</a>. <h3 class=fn><a href="qstring.html">QString</a> <a name="lastQuery"></a>QSqlQuery::lastQuery () const </h3> Returns the text of the current query being used, or <a href="qstring.html#QString-null">QString::null</a> if there is no current query text. <h3 class=fn>bool <a name="next"></a>QSqlQuery::next ()<tt> [virtual]</tt> </h3> 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 <a href="#isSelect">isSelect</a>() must return TRUE before calling this function or it will do nothing and return FALSE. <p> The following rules apply: <p> <ul> <li> 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. <p> <li> If the result is currently located after the last record, there is no change and FALSE is returned. <p> <li> If the result is located somewhere in the middle, an attempt is made to retrieve the next record. </ul> <p> 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. <p> <p>See also <a href="#at">at</a>() and <a href="#isValid">isValid</a>(). <p>Examples: <a href="sql.html#x2089">sql/overview/basicbrowsing/main.cpp</a>, <a href="sql.html#x2093">sql/overview/basicbrowsing2/main.cpp</a>, <a href="sql.html#x2138">sql/overview/delete/main.cpp</a>, <a href="sql.html#x2113">sql/overview/order1/main.cpp</a>, <a href="sql.html#x2106">sql/overview/retrieve1/main.cpp</a>, <a href="sql.html#x2195">sql/overview/subclass4/main.cpp</a>, and <a href="sql.html#x2198">sql/overview/subclass5/main.cpp</a>. <h3 class=fn>int <a name="numRowsAffected"></a>QSqlQuery::numRowsAffected () const </h3> 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 <a href="#size">size</a>(). If the query is not active (<a href="#isActive">isActive</a>() returns FALSE), -1 is returned. <p> <p>See also <a href="#size">size</a>() and <a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>(). <p>Examples: <a href="sql.html#x2094">sql/overview/basicbrowsing2/main.cpp</a> and <a href="sql.html#x2098">sql/overview/basicdatamanip/main.cpp</a>. <h3 class=fn><a href="qsqlquery.html">QSqlQuery</a> & <a name="operator-eq"></a>QSqlQuery::operator= ( const <a href="qsqlquery.html">QSqlQuery</a> & other ) </h3> Assigns <em>other</em> to the query. <h3 class=fn>bool <a name="prepare"></a>QSqlQuery::prepare ( const <a href="qstring.html">QString</a> & query ) </h3> Prepares the SQL query <em>query</em> for execution. The query may contain placeholders for binding values. Note that placeholder markers are usually database dependent. <p> <p>See also <a href="#exec">exec</a>(), <a href="#bindValue">bindValue</a>(), and <a href="#addBindValue">addBindValue</a>(). <h3 class=fn>bool <a name="prev"></a>QSqlQuery::prev ()<tt> [virtual]</tt> </h3> 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 <a href="#isSelect">isSelect</a>() must return TRUE before calling this function or it will do nothing and return FALSE. <p> The following rules apply: <p> <ul> <li> If the result is currently located before the first record, there is no change and FALSE is returned. <p> <li> If the result is currently located after the last record, an attempt is made to retrieve the last record. <p> <li> If the result is somewhere in the middle, an attempt is made to retrieve the previous record. </ul> <p> 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. <p> <p>See also <a href="#at">at</a>(). <h3 class=fn>const <a href="qsqlresult.html">QSqlResult</a> * <a name="result"></a>QSqlQuery::result () const </h3> Returns the result associated with the query. <h3 class=fn>bool <a name="seek"></a>QSqlQuery::seek ( int i, bool relative = FALSE )<tt> [virtual]</tt> </h3> Retrieves the record at position (offset) <em>i</em>, 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 <a href="#isSelect">isSelect</a>() must return TRUE before calling this function. <p> If <em>relative</em> is FALSE (the default), the following rules apply: <p> <ul> <li> If <em>i</em> is negative, the result is positioned before the first record and FALSE is returned. <li> Otherwise, an attempt is made to move to the record at position <em>i</em>. If the record at position <em>i</em> 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. </ul> <p> If <em>relative</em> is TRUE, the following rules apply: <p> <ul> <li> If the result is currently positioned before the first record or on the first record, and <em>i</em> is negative, there is no change, and FALSE is returned. <li> If the result is currently located after the last record, and <em>i</em> is positive, there is no change, and FALSE is returned. <li> If the result is currently located somewhere in the middle, and the relative offset <em>i</em> moves the result below zero, the result is positioned before the first record and FALSE is returned. <li> Otherwise, an attempt is made to move to the record <em>i</em> records ahead of the current record (or <em>i</em> records behind the current record if <em>i</em> is negative). If the record at offset <em>i</em> could not be retrieved, the result is positioned after the last record if <em>i</em> >= 0, (or before the first record if <em>i</em> is negative), and FALSE is returned. If the record is successfully retrieved, TRUE is returned. </ul> <p>Example: <a href="sql.html#x2103">sql/overview/navigating/main.cpp</a>. <h3 class=fn>void <a name="setForwardOnly"></a>QSqlQuery::setForwardOnly ( bool forward ) </h3> Sets forward only mode to <em>forward</em>. If forward is TRUE only <a href="#next">next</a>() and <a href="#seek">seek</a>() 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 <a href="qdatatable.html">QDataTable</a> since they need to be able to scroll backward. <p>See also <a href="#next">next</a>() and <a href="#seek">seek</a>(). <h3 class=fn>int <a name="size"></a>QSqlQuery::size () const </h3> 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 (<a href="#isSelect">isSelect</a>() returns FALSE), <a href="#size">size</a>() will return -1. If the query is not active (<a href="#isActive">isActive</a>() returns FALSE), -1 is returned. <p> To determine the number of rows affected by a non-SELECT statement, use <a href="#numRowsAffected">numRowsAffected</a>(). <p> <p>See also <a href="#isActive">isActive</a>(), <a href="#numRowsAffected">numRowsAffected</a>(), and <a href="qsqldriver.html#hasFeature">QSqlDriver::hasFeature</a>(). <p>Example: <a href="sql.html#x2104">sql/overview/navigating/main.cpp</a>. <h3 class=fn><a href="qvariant.html">QVariant</a> <a name="value"></a>QSqlQuery::value ( int i ) const<tt> [virtual]</tt> </h3> Returns the value of the <em>i</em>-th field in the query (zero based). <p> The fields are numbered from left to right using the text of the <tt>SELECT</tt> statement, e.g. in "SELECT forename, surname FROM people", field 0 is forename and field 1 is surname. Using <tt>SELECT *</tt> is not recommended because the order of the fields in the query is undefined. <p> An invalid <a href="qvariant.html">QVariant</a> is returned if field <em>i</em> does not exist, if the query is inactive, or if the query is positioned on an invalid record. <p> <p>See also <a href="#prev">prev</a>(), <a href="#next">next</a>(), <a href="#first">first</a>(), <a href="#last">last</a>(), <a href="#seek">seek</a>(), <a href="#isActive">isActive</a>(), and <a href="#isValid">isValid</a>(). <p>Examples: <a href="sql.html#x2090">sql/overview/basicbrowsing/main.cpp</a>, <a href="sql.html#x2095">sql/overview/basicbrowsing2/main.cpp</a>, <a href="sql.html#x2107">sql/overview/retrieve1/main.cpp</a>, <a href="sql.html#x2192">sql/overview/subclass3/main.cpp</a>, <a href="sql.html#x2196">sql/overview/subclass4/main.cpp</a>, <a href="sql.html#x2199">sql/overview/subclass5/main.cpp</a>, and <a href="sql.html#x2182">sql/overview/table4/main.cpp</a>. <!-- eof --> <hr><p> This file is part of the <a href="index.html">Qt toolkit</a>. Copyright © 1995-2002 <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center> <table width=100% cellspacing=0 border=0><tr> <td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a> <td align=right><div align=right>Qt version 3.1.1</div> </table></div></address></body> </html>