qsqlcursor.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 695 行 · 第 1/4 页
HTML
695 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/sql/qsqlcursor.cpp:78 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QSqlCursor 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>QSqlCursor Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1><p>The QSqlCursor class provides browsing and editing of SQLtables and views.<a href="#details">More...</a><p><tt>#include <<a href="qsqlcursor-h.html">qsqlcursor.h</a>></tt><p>Inherits <a href="qsqlrecord.html">QSqlRecord</a> and <a href="qsqlquery.html">QSqlQuery</a>.<p><a href="qsqlcursor-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QSqlCursor"><b>QSqlCursor</b></a> ( const QString & name = QString::null, bool autopopulate = TRUE, QSqlDatabase * db = 0 )</div></li><li><div class=fn><a href="#QSqlCursor-2"><b>QSqlCursor</b></a> ( const QSqlCursor & other )</div></li><li><div class=fn>QSqlCursor & <a href="#operator-eq"><b>operator=</b></a> ( const QSqlCursor & other )</div></li><li><div class=fn><a href="#~QSqlCursor"><b>~QSqlCursor</b></a> ()</div></li><li><div class=fn>enum <a href="#Mode-enum"><b>Mode</b></a> { ReadOnly = 0, Insert = 1, Update = 2, Delete = 4, Writable = 7 }</div></li><li><div class=fn>virtual QSqlIndex <a href="#primaryIndex"><b>primaryIndex</b></a> ( bool setFromCursor = TRUE ) const</div></li><li><div class=fn>virtual QSqlIndex <a href="#index"><b>index</b></a> ( const QStringList & fieldNames ) const</div></li><li><div class=fn>QSqlIndex <a href="#index-2"><b>index</b></a> ( const QString & fieldName ) const</div></li><li><div class=fn>QSqlIndex <a href="#index-3"><b>index</b></a> ( const char * fieldName ) const</div></li><li><div class=fn>virtual void <a href="#setPrimaryIndex"><b>setPrimaryIndex</b></a> ( const QSqlIndex & idx )</div></li><li><div class=fn>virtual void <a href="#append"><b>append</b></a> ( const QSqlFieldInfo & fieldInfo )</div></li><li><div class=fn>virtual void <a href="#insert"><b>insert</b></a> ( int pos, const QSqlFieldInfo & fieldInfo )</div></li><li><div class=fn>virtual void <a href="#remove"><b>remove</b></a> ( int pos )</div></li><li><div class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</div></li><li><div class=fn>virtual void <a href="#setGenerated"><b>setGenerated</b></a> ( const QString & name, bool generated )</div></li><li><div class=fn>virtual void <a href="#setGenerated-2"><b>setGenerated</b></a> ( int i, bool generated )</div></li><li><div class=fn>virtual QSqlRecord * <a href="#editBuffer"><b>editBuffer</b></a> ( bool copy = FALSE )</div></li><li><div class=fn>virtual QSqlRecord * <a href="#primeInsert"><b>primeInsert</b></a> ()</div></li><li><div class=fn>virtual QSqlRecord * <a href="#primeUpdate"><b>primeUpdate</b></a> ()</div></li><li><div class=fn>virtual QSqlRecord * <a href="#primeDelete"><b>primeDelete</b></a> ()</div></li><li><div class=fn>virtual int <a href="#insert-2"><b>insert</b></a> ( bool invalidate = TRUE )</div></li><li><div class=fn>virtual int <a href="#update"><b>update</b></a> ( bool invalidate = TRUE )</div></li><li><div class=fn>virtual int <a href="#del"><b>del</b></a> ( bool invalidate = TRUE )</div></li><li><div class=fn>virtual void <a href="#setMode"><b>setMode</b></a> ( int mode )</div></li><li><div class=fn>int <a href="#mode"><b>mode</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setCalculated"><b>setCalculated</b></a> ( const QString & name, bool calculated )</div></li><li><div class=fn>bool <a href="#isCalculated"><b>isCalculated</b></a> ( const QString & name ) const</div></li><li><div class=fn>virtual void <a href="#setTrimmed"><b>setTrimmed</b></a> ( const QString & name, bool trim )</div></li><li><div class=fn>bool <a href="#isTrimmed"><b>isTrimmed</b></a> ( const QString & name ) const</div></li><li><div class=fn>bool <a href="#isReadOnly"><b>isReadOnly</b></a> () const</div></li><li><div class=fn>bool <a href="#canInsert"><b>canInsert</b></a> () const</div></li><li><div class=fn>bool <a href="#canUpdate"><b>canUpdate</b></a> () const</div></li><li><div class=fn>bool <a href="#canDelete"><b>canDelete</b></a> () const</div></li><li><div class=fn>bool <a href="#select-2"><b>select</b></a> ()</div></li><li><div class=fn>bool <a href="#select-3"><b>select</b></a> ( const QSqlIndex & sort )</div></li><li><div class=fn>bool <a href="#select-4"><b>select</b></a> ( const QSqlIndex & filter, const QSqlIndex & sort )</div></li><li><div class=fn>virtual bool <a href="#select"><b>select</b></a> ( const QString & filter, const QSqlIndex & sort = QSqlIndex ( ) )</div></li><li><div class=fn>virtual void <a href="#setSort"><b>setSort</b></a> ( const QSqlIndex & sort )</div></li><li><div class=fn>QSqlIndex <a href="#sort"><b>sort</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setFilter"><b>setFilter</b></a> ( const QString & filter )</div></li><li><div class=fn>QString <a href="#filter"><b>filter</b></a> () const</div></li><li><div class=fn>virtual void <a href="#setName"><b>setName</b></a> ( const QString & name, bool autopopulate = TRUE )</div></li><li><div class=fn>QString <a href="#name"><b>name</b></a> () const</div></li></ul><h2>Protected Members</h2><ul><li><div class=fn>virtual QVariant <a href="#calculateField"><b>calculateField</b></a> ( const QString & name )</div></li><li><div class=fn>virtual int <a href="#update-2"><b>update</b></a> ( const QString & filter, bool invalidate = TRUE )</div></li><li><div class=fn>virtual int <a href="#del-2"><b>del</b></a> ( const QString & filter, bool invalidate = TRUE )</div></li><li><div class=fn>virtual QString <a href="#toString-3"><b>toString</b></a> ( const QString & prefix, QSqlField * field, const QString & fieldSep ) const</div></li><li><div class=fn>virtual QString <a href="#toString"><b>toString</b></a> ( QSqlRecord * rec, const QString & prefix, const QString & fieldSep, const QString & sep ) const</div></li><li><div class=fn>virtual QString <a href="#toString-4"><b>toString</b></a> ( const QSqlIndex & i, QSqlRecord * rec, const QString & prefix, const QString & fieldSep, const QString & sep ) const</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2> <p> The QSqlCursor class provides browsing and editing of SQLtables and views.<p> <p> A QSqlCursor is a database record (see <a href="qsqlrecord.html">QSqlRecord</a>) thatcorresponds to a table or view within an SQL database (see <a href="qsqldatabase.html">QSqlDatabase</a>). There are two buffers in a cursor, one used forbrowsing and one used for editing records. Each buffer contains alist of fields which correspond to the fields in the table orview.<p> When positioned on a valid record, the browse buffer contains thevalues of the current record's fields from the database. The editbuffer is separate, and is used for editing existing records andinserting new records.<p> For browsing data, a cursor must first <a href="#select">select</a>() data from thedatabase. After a successful select() the cursor is active(<a href="qsqlquery.html#isActive">isActive</a>() returns TRUE), but is initially not positioned on avalid record (<a href="qsqlquery.html#isValid">isValid</a>() returns FALSE). To position the cursor ona valid record, use one of the navigation functions, <a href="qsqlquery.html#next">next</a>(),<a href="qsqlquery.html#prev">prev</a>(), <a href="qsqlquery.html#first">first</a>(), <a href="qsqlquery.html#last">last</a>(), or <a href="qsqlquery.html#seek">seek</a>(). Once positioned on a validrecord, data can be retrieved from the browse buffer using<a href="qsqlquery.html#value">value</a>(). If a navigation function is not successful, it returnsFALSE, the cursor will no longer be positioned on a valid recordand the values returned by value() are undefined.<p> For example:<p> <pre> QSqlCursor cur( "staff" ); // Specify the table/view name <a name="x2177"></a> cur.<a href="#select">select</a>(); // We'll retrieve every record while ( cur.<a href="qsqlquery.html#next">next</a>() ) { <a name="x2178"></a> <a href="qapplication.html#qDebug">qDebug</a>( cur.<a href="qsqlquery.html#value">value</a>( "id" ).toString() + ": " + cur.<a href="qsqlquery.html#value">value</a>( "surname" ).toString() + " " + cur.<a href="qsqlquery.html#value">value</a>( "salary" ).toString() ); }</pre><p> In the above example, a cursor is created specifying a table orview name in the database. Then, <a href="#select">select</a>() is called, which can beoptionally parameterised to filter and order the recordsretrieved. Each record in the cursor is retrieved using <a href="qsqlquery.html#next">next</a>().When next() returns FALSE, there are no more records to process,and the loop terminates.<p> For editing records (rows of data), a cursor contains a separateedit buffer which is independent of the fields used when browsing.The functions <a href="#insert">insert</a>(), <a href="#update">update</a>() and <a href="#del">del</a>() operate on the editbuffer. This allows the cursor to be repositioned to otherrecords while simultaneously maintaining a separate buffer foredits. You can get a pointer to the edit buffer using<a href="#editBuffer">editBuffer</a>(). The <a href="#primeInsert">primeInsert</a>(), <a href="#primeUpdate">primeUpdate</a>() and <a href="#primeDelete">primeDelete</a>()functions also return a pointer to the edit buffer and prepare itfor insert, update and delete respectively. Edit operations onlyaffect a single row at a time. Note that update() and del()require that the table or view contain a <a href="#primaryIndex">primaryIndex</a>() to ensurethat edit operations affect a unique record within the database.<p> For example:<p> <pre> QSqlCursor cur( "prices" ); <a name="x2199"></a> cur.<a href="#select">select</a>( "id=202" ); if ( cur.<a href="qsqlquery.html#next">next</a>() ) { <a name="x2198"></a> <a href="qsqlrecord.html">QSqlRecord</a> *buffer = cur.<a href="#primeUpdate">primeUpdate</a>(); <a name="x2203"></a> double price = buffer-><a href="qsqlrecord.html#value">value</a>( "price" ).toDouble(); double newprice = price * 1.05; <a name="x2202"></a> buffer-><a href="qsqlrecord.html#setValue">setValue</a>( "price", newprice ); <a name="x2200"></a> cur.<a href="#update">update</a>(); }</pre><p> To edit an existing database record, first move to the record youwish to update. Call <a href="#primeUpdate">primeUpdate</a>() to get the pointer to thecursor's edit buffer. Then use this pointer to modify the valuesin the edit buffer. Finally, call <a href="#update">update</a>() to save the changes tothe database. The values in the edit buffer will be used tolocate the appropriate record when updating the database (see<a href="#primaryIndex">primaryIndex</a>()).<p> Similarly, when deleting an existing database record, first moveto the record you wish to delete. Then, call <a href="#primeDelete">primeDelete</a>() to getthe pointer to the edit buffer. Finally, call <a href="#del">del</a>() to delete therecord from the database. Again, the values in the edit bufferwill be used to locate and delete the appropriate record.<p> To insert a new record, call <a href="#primeInsert">primeInsert</a>() to get the pointer to
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?