You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
762 lines
50 KiB
762 lines
50 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/sql/qsqlcursor.cpp:122 -->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>TQSqlCursor Class</title>
|
|
<style type="text/css"><!--
|
|
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>TQSqlCursor Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1>
|
|
|
|
<p>The TQSqlCursor class provides browsing and editing of SQL
|
|
tables and views.
|
|
<a href="#details">More...</a>
|
|
<p><tt>#include <<a href="qsqlcursor-h.html">ntqsqlcursor.h</a>></tt>
|
|
<p>Inherits <a href="ntqsqlrecord.html">TQSqlRecord</a> and <a href="ntqsqlquery.html">TQSqlQuery</a>.
|
|
<p>Inherited by <a href="ntqsqlselectcursor.html">TQSqlSelectCursor</a>.
|
|
<p><a href="qsqlcursor-members.html">List of all member functions.</a>
|
|
<h2>Public Members</h2>
|
|
<ul>
|
|
<li class=fn><a href="#TQSqlCursor"><b>TQSqlCursor</b></a> ( const TQString & name = TQString::null, bool autopopulate = TRUE, TQSqlDatabase * db = 0 )</li>
|
|
<li class=fn><a href="#TQSqlCursor-2"><b>TQSqlCursor</b></a> ( const TQSqlCursor & other )</li>
|
|
<li class=fn>TQSqlCursor & <a href="#operator-eq"><b>operator=</b></a> ( const TQSqlCursor & other )</li>
|
|
<li class=fn><a href="#~TQSqlCursor"><b>~TQSqlCursor</b></a> ()</li>
|
|
<li class=fn>enum <a href="#Mode-enum"><b>Mode</b></a> { ReadOnly = 0, Insert = 1, Update = 2, Delete = 4, Writable = 7 }</li>
|
|
<li class=fn>virtual TQSqlIndex <a href="#primaryIndex"><b>primaryIndex</b></a> ( bool setFromCursor = TRUE ) const</li>
|
|
<li class=fn>virtual TQSqlIndex <a href="#index"><b>index</b></a> ( const TQStringList & fieldNames ) const</li>
|
|
<li class=fn>TQSqlIndex <a href="#index-2"><b>index</b></a> ( const TQString & fieldName ) const</li>
|
|
<li class=fn>TQSqlIndex <a href="#index-3"><b>index</b></a> ( const char * fieldName ) const</li>
|
|
<li class=fn>virtual void <a href="#setPrimaryIndex"><b>setPrimaryIndex</b></a> ( const TQSqlIndex & idx )</li>
|
|
<li class=fn>virtual void <a href="#append"><b>append</b></a> ( const TQSqlFieldInfo & fieldInfo )</li>
|
|
<li class=fn>virtual void <a href="#insert"><b>insert</b></a> ( int pos, const TQSqlFieldInfo & fieldInfo )</li>
|
|
<li class=fn>virtual void <a href="#remove"><b>remove</b></a> ( int pos )</li>
|
|
<li class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</li>
|
|
<li class=fn>virtual void <a href="#setGenerated"><b>setGenerated</b></a> ( const TQString & name, bool generated )</li>
|
|
<li class=fn>virtual void <a href="#setGenerated-2"><b>setGenerated</b></a> ( int i, bool generated )</li>
|
|
<li class=fn>virtual TQSqlRecord * <a href="#editBuffer"><b>editBuffer</b></a> ( bool copy = FALSE )</li>
|
|
<li class=fn>virtual TQSqlRecord * <a href="#primeInsert"><b>primeInsert</b></a> ()</li>
|
|
<li class=fn>virtual TQSqlRecord * <a href="#primeUpdate"><b>primeUpdate</b></a> ()</li>
|
|
<li class=fn>virtual TQSqlRecord * <a href="#primeDelete"><b>primeDelete</b></a> ()</li>
|
|
<li class=fn>virtual int <a href="#insert-2"><b>insert</b></a> ( bool invalidate = TRUE )</li>
|
|
<li class=fn>virtual int <a href="#update"><b>update</b></a> ( bool invalidate = TRUE )</li>
|
|
<li class=fn>virtual int <a href="#del"><b>del</b></a> ( bool invalidate = TRUE )</li>
|
|
<li class=fn>virtual void <a href="#setMode"><b>setMode</b></a> ( int mode )</li>
|
|
<li class=fn>int <a href="#mode"><b>mode</b></a> () const</li>
|
|
<li class=fn>virtual void <a href="#setCalculated"><b>setCalculated</b></a> ( const TQString & name, bool calculated )</li>
|
|
<li class=fn>bool <a href="#isCalculated"><b>isCalculated</b></a> ( const TQString & name ) const</li>
|
|
<li class=fn>virtual void <a href="#setTrimmed"><b>setTrimmed</b></a> ( const TQString & name, bool trim )</li>
|
|
<li class=fn>bool <a href="#isTrimmed"><b>isTrimmed</b></a> ( const TQString & name ) const</li>
|
|
<li class=fn>bool <a href="#isReadOnly"><b>isReadOnly</b></a> () const</li>
|
|
<li class=fn>bool <a href="#canInsert"><b>canInsert</b></a> () const</li>
|
|
<li class=fn>bool <a href="#canUpdate"><b>canUpdate</b></a> () const</li>
|
|
<li class=fn>bool <a href="#canDelete"><b>canDelete</b></a> () const</li>
|
|
<li class=fn>bool <a href="#select-2"><b>select</b></a> ()</li>
|
|
<li class=fn>bool <a href="#select-3"><b>select</b></a> ( const TQSqlIndex & sort )</li>
|
|
<li class=fn>bool <a href="#select-4"><b>select</b></a> ( const TQSqlIndex & filter, const TQSqlIndex & sort )</li>
|
|
<li class=fn>virtual bool <a href="#select"><b>select</b></a> ( const TQString & filter, const TQSqlIndex & sort = TQSqlIndex ( ) )</li>
|
|
<li class=fn>virtual void <a href="#setSort"><b>setSort</b></a> ( const TQSqlIndex & sort )</li>
|
|
<li class=fn>TQSqlIndex <a href="#sort"><b>sort</b></a> () const</li>
|
|
<li class=fn>virtual void <a href="#setFilter"><b>setFilter</b></a> ( const TQString & filter )</li>
|
|
<li class=fn>TQString <a href="#filter"><b>filter</b></a> () const</li>
|
|
<li class=fn>virtual void <a href="#setName"><b>setName</b></a> ( const TQString & name, bool autopopulate = TRUE )</li>
|
|
<li class=fn>TQString <a href="#name"><b>name</b></a> () const</li>
|
|
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> ( int i ) const</li>
|
|
<li class=fn>bool <a href="#isNull-2"><b>isNull</b></a> ( const TQString & name ) const</li>
|
|
</ul>
|
|
<h2>Protected Members</h2>
|
|
<ul>
|
|
<li class=fn>virtual TQVariant <a href="#calculateField"><b>calculateField</b></a> ( const TQString & name )</li>
|
|
<li class=fn>virtual int <a href="#update-2"><b>update</b></a> ( const TQString & filter, bool invalidate = TRUE )</li>
|
|
<li class=fn>virtual int <a href="#del-2"><b>del</b></a> ( const TQString & filter, bool invalidate = TRUE )</li>
|
|
<li class=fn>virtual TQString <a href="#toString-3"><b>toString</b></a> ( const TQString & prefix, TQSqlField * field, const TQString & fieldSep ) const</li>
|
|
<li class=fn>virtual TQString <a href="#toString"><b>toString</b></a> ( TQSqlRecord * rec, const TQString & prefix, const TQString & fieldSep, const TQString & sep ) const</li>
|
|
<li class=fn>virtual TQString <a href="#toString-4"><b>toString</b></a> ( const TQSqlIndex & i, TQSqlRecord * rec, const TQString & prefix, const TQString & fieldSep, const TQString & sep ) const</li>
|
|
</ul>
|
|
<hr><a name="details"></a><h2>Detailed Description</h2>
|
|
|
|
|
|
The TQSqlCursor class provides browsing and editing of SQL
|
|
tables and views.
|
|
<p>
|
|
|
|
<p> A TQSqlCursor is a database record (see <a href="ntqsqlrecord.html">TQSqlRecord</a>) that
|
|
corresponds to a table or view within an SQL database (see <a href="ntqsqldatabase.html">TQSqlDatabase</a>). There are two buffers in a cursor, one used for
|
|
browsing and one used for editing records. Each buffer contains a
|
|
list of fields which correspond to the fields in the table or
|
|
view.
|
|
<p> When positioned on a valid record, the browse buffer contains the
|
|
values of the current record's fields from the database. The edit
|
|
buffer is separate, and is used for editing existing records and
|
|
inserting new records.
|
|
<p> For browsing data, a cursor must first <a href="#select">select</a>() data from the
|
|
database. After a successful select() the cursor is active
|
|
(<a href="ntqsqlquery.html#isActive">isActive</a>() returns TRUE), but is initially not positioned on a
|
|
valid record (<a href="ntqsqlquery.html#isValid">isValid</a>() returns FALSE). To position the cursor on
|
|
a valid record, use one of the navigation functions, <a href="ntqsqlquery.html#next">next</a>(),
|
|
<a href="ntqsqlquery.html#prev">prev</a>(), <a href="ntqsqlquery.html#first">first</a>(), <a href="ntqsqlquery.html#last">last</a>(), or <a href="ntqsqlquery.html#seek">seek</a>(). Once positioned on a valid
|
|
record, data can be retrieved from the browse buffer using
|
|
<a href="ntqsqlquery.html#value">value</a>(). If a navigation function is not successful, it returns
|
|
FALSE, the cursor will no longer be positioned on a valid record
|
|
and the values returned by value() are undefined.
|
|
<p> For example:
|
|
<p>
|
|
|
|
<pre> TQSqlCursor cur( "staff" ); // Specify the table/view name
|
|
<a name="x2178"></a> cur.<a href="#select">select</a>(); // We'll retrieve every record
|
|
while ( cur.<a href="ntqsqlquery.html#next">next</a>() ) {
|
|
<a name="x2179"></a> <a href="ntqapplication.html#qDebug">tqDebug</a>( cur.<a href="ntqsqlquery.html#value">value</a>( "id" ).toString() + ": " +
|
|
cur.<a href="ntqsqlquery.html#value">value</a>( "surname" ).toString() + " " +
|
|
cur.<a href="ntqsqlquery.html#value">value</a>( "salary" ).toString() );
|
|
}
|
|
</pre>
|
|
<p> In the above example, a cursor is created specifying a table or
|
|
view name in the database. Then, <a href="#select">select</a>() is called, which can be
|
|
optionally parameterised to filter and order the records
|
|
retrieved. Each record in the cursor is retrieved using <a href="ntqsqlquery.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 separate
|
|
edit 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 edit
|
|
buffer. This allows the cursor to be repositioned to other
|
|
records while simultaneously maintaining a separate buffer for
|
|
edits. 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 it
|
|
for insert, update and delete respectively. Edit operations only
|
|
affect 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 ensure
|
|
that edit operations affect a unique record within the database.
|
|
<p> For example:
|
|
<p>
|
|
|
|
<pre> TQSqlCursor cur( "prices" );
|
|
<a name="x2200"></a> cur.<a href="#select">select</a>( "id=202" );
|
|
if ( cur.<a href="ntqsqlquery.html#next">next</a>() ) {
|
|
<a name="x2199"></a> <a href="ntqsqlrecord.html">TQSqlRecord</a> *buffer = cur.<a href="#primeUpdate">primeUpdate</a>();
|
|
<a name="x2204"></a> double price = buffer-><a href="ntqsqlrecord.html#value">value</a>( "price" ).toDouble();
|
|
double newprice = price * 1.05;
|
|
<a name="x2203"></a> buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "price", newprice );
|
|
<a name="x2201"></a> cur.<a href="#update">update</a>();
|
|
}
|
|
</pre>
|
|
<p> To edit an existing database record, first move to the record you
|
|
wish to update. Call <a href="#primeUpdate">primeUpdate</a>() to get the pointer to the
|
|
cursor's edit buffer. Then use this pointer to modify the values
|
|
in the edit buffer. Finally, call <a href="#update">update</a>() to save the changes to
|
|
the database. The values in the edit buffer will be used to
|
|
locate the appropriate record when updating the database (see
|
|
<a href="#primaryIndex">primaryIndex</a>()).
|
|
<p> Similarly, when deleting an existing database record, first move
|
|
to the record you wish to delete. Then, call <a href="#primeDelete">primeDelete</a>() to get
|
|
the pointer to the edit buffer. Finally, call <a href="#del">del</a>() to delete the
|
|
record from the database. Again, the values in the edit buffer
|
|
will 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
|
|
the edit buffer. Use this pointer to populate the edit buffer
|
|
with new values and then <a href="#insert">insert</a>() the record into the database.
|
|
<p> After calling insert(), update() or del(), the cursor is no longer
|
|
positioned on a valid record and can no longer be navigated
|
|
(<a href="ntqsqlquery.html#isValid">isValid</a>() return FALSE). The reason for this is that any changes
|
|
made to the database will not be visible until <a href="#select">select</a>() is called
|
|
to refresh the cursor. You can change this behavior by passing
|
|
FALSE to insert(), <a href="#update">update</a>() or del() which will prevent the cursor
|
|
from becoming invalid. The edits will still not be visible when
|
|
navigating the cursor until select() is called.
|
|
<p> TQSqlCursor contains virtual methods which allow editing behavior
|
|
to be customized by subclasses. This allows custom cursors to be
|
|
created that encapsulate the editing behavior of a database table
|
|
for an entire application. For example, a cursor can be customized
|
|
to always auto-number primary index fields, or provide fields with
|
|
suitable default values, when inserting new records. TQSqlCursor
|
|
generates SQL statements which are sent to the database engine;
|
|
you can control which fields are included in these statements
|
|
using <a href="#setGenerated">setGenerated</a>().
|
|
<p> Note that TQSqlCursor does not inherit from <a href="ntqobject.html">TQObject</a>. This means
|
|
that you are responsible for destroying instances of this class
|
|
yourself. However if you create a TQSqlCursor and use it in a
|
|
<a href="ntqdatatable.html">TQDataTable</a>, <a href="ntqdatabrowser.html">TQDataBrowser</a> or a <a href="ntqdataview.html">TQDataView</a> these classes will
|
|
usually take ownership of the cursor and destroy it when they
|
|
don't need it anymore. The documentation for <a href="ntqdatatable.html">TQDataTable</a>,
|
|
<a href="ntqdatabrowser.html">TQDataBrowser</a> and <a href="ntqdataview.html">TQDataView</a> explicitly states which calls take
|
|
ownership of the cursor.
|
|
<p>See also <a href="database.html">Database Classes</a>.
|
|
|
|
<hr><h2>Member Type Documentation</h2>
|
|
<h3 class=fn><a name="Mode-enum"></a>TQSqlCursor::Mode</h3>
|
|
|
|
<p> This enum type describes how TQSqlCursor operates on records in the
|
|
database.
|
|
<ul>
|
|
<li><tt>TQSqlCursor::ReadOnly</tt> - the cursor can only SELECT records from the
|
|
database.
|
|
<li><tt>TQSqlCursor::Insert</tt> - the cursor can INSERT records into the database.
|
|
<li><tt>TQSqlCursor::Update</tt> - the cursor can UPDATE records in the database.
|
|
<li><tt>TQSqlCursor::Delete</tt> - the cursor can DELETE records from the database.
|
|
<li><tt>TQSqlCursor::Writable</tt> - the cursor can INSERT, UPDATE and DELETE records
|
|
in the database.
|
|
</ul>
|
|
<hr><h2>Member Function Documentation</h2>
|
|
<h3 class=fn><a name="TQSqlCursor"></a>TQSqlCursor::TQSqlCursor ( const <a href="ntqstring.html">TQString</a> & name = TQString::null, bool autopopulate = TRUE, <a href="ntqsqldatabase.html">TQSqlDatabase</a> * db = 0 )
|
|
</h3>
|
|
Constructs a cursor on database <em>db</em> using table or view <em>name</em>.
|
|
<p> If <em>autopopulate</em> is TRUE (the default), the <em>name</em> of the
|
|
cursor must correspond to an existing table or view name in the
|
|
database so that field information can be automatically created.
|
|
If the table or view does not exist, the cursor will not be
|
|
functional.
|
|
<p> The cursor is created with an initial mode of TQSqlCursor::Writable
|
|
(meaning that records can be inserted, updated or deleted using
|
|
the cursor). If the cursor does not have a unique primary index,
|
|
update and deletes cannot be performed.
|
|
<p> Note that <em>autopopulate</em> refers to populating the cursor with
|
|
meta-data, e.g. the names of the table's fields, not with
|
|
retrieving data. The <a href="#select">select</a>() function is used to populate the
|
|
cursor with data.
|
|
<p> <p>See also <a href="#setName">setName</a>() and <a href="#setMode">setMode</a>().
|
|
|
|
<h3 class=fn><a name="TQSqlCursor-2"></a>TQSqlCursor::TQSqlCursor ( const <a href="ntqsqlcursor.html">TQSqlCursor</a> & other )
|
|
</h3>
|
|
Constructs a copy of <em>other</em>.
|
|
|
|
<h3 class=fn><a name="~TQSqlCursor"></a>TQSqlCursor::~TQSqlCursor ()
|
|
</h3>
|
|
Destroys the object and frees any allocated resources.
|
|
|
|
<h3 class=fn>void <a name="append"></a>TQSqlCursor::append ( const <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a> & fieldInfo )<tt> [virtual]</tt>
|
|
</h3>
|
|
Append a copy of field <em>fieldInfo</em> to the end of the cursor. Note
|
|
that all references to the cursor edit buffer become invalidated.
|
|
|
|
<h3 class=fn><a href="ntqvariant.html">TQVariant</a> <a name="calculateField"></a>TQSqlCursor::calculateField ( const <a href="ntqstring.html">TQString</a> & name )<tt> [virtual protected]</tt>
|
|
</h3>
|
|
Protected virtual function which is called whenever a field needs
|
|
to be calculated. If calculated fields are being used, derived
|
|
classes must reimplement this function and return the appropriate
|
|
value for field <em>name</em>. The default implementation returns an
|
|
invalid <a href="ntqvariant.html">TQVariant</a>.
|
|
<p> <p>See also <a href="#setCalculated">setCalculated</a>().
|
|
|
|
<p>Examples: <a href="sql.html#x2259">sql/overview/subclass3/main.cpp</a> and <a href="sql.html#x2263">sql/overview/subclass4/main.cpp</a>.
|
|
<h3 class=fn>bool <a name="canDelete"></a>TQSqlCursor::canDelete () const
|
|
</h3>
|
|
Returns TRUE if the cursor will perform deletes; otherwise returns
|
|
FALSE.
|
|
<p> <p>See also <a href="#setMode">setMode</a>().
|
|
|
|
<h3 class=fn>bool <a name="canInsert"></a>TQSqlCursor::canInsert () const
|
|
</h3>
|
|
Returns TRUE if the cursor will perform inserts; otherwise returns
|
|
FALSE.
|
|
<p> <p>See also <a href="#setMode">setMode</a>().
|
|
|
|
<h3 class=fn>bool <a name="canUpdate"></a>TQSqlCursor::canUpdate () const
|
|
</h3>
|
|
Returns TRUE if the cursor will perform updates; otherwise returns
|
|
FALSE.
|
|
<p> <p>See also <a href="#setMode">setMode</a>().
|
|
|
|
<h3 class=fn>void <a name="clear"></a>TQSqlCursor::clear ()<tt> [virtual]</tt>
|
|
</h3>
|
|
Removes all fields from the cursor. Note that all references to
|
|
the cursor edit buffer become invalidated.
|
|
|
|
<p>Reimplemented from <a href="ntqsqlrecord.html#clear">TQSqlRecord</a>.
|
|
<h3 class=fn>int <a name="del"></a>TQSqlCursor::del ( bool invalidate = TRUE )<tt> [virtual]</tt>
|
|
</h3>
|
|
Deletes a record from the database using the cursor's primary
|
|
index and the contents of the cursor edit buffer. Returns the
|
|
number of records which were deleted.
|
|
For error information, use <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
<p> Only records which meet the filter criteria specified by the
|
|
cursor's primary index are deleted. If the cursor does not contain
|
|
a primary index, no delete is performed and 0 is returned. If <em>invalidate</em> is TRUE (the default), the current cursor can no longer
|
|
be navigated. A new <a href="#select">select</a>() call must be made before you can move
|
|
to a valid record. For example:
|
|
<p>
|
|
|
|
<pre> TQSqlCursor cur( "prices" );
|
|
<a name="x2207"></a> cur.<a href="#select">select</a>( "id=999" );
|
|
<a name="x2208"></a> if ( cur.<a href="ntqsqlquery.html#next">next</a>() ) {
|
|
<a name="x2206"></a> cur.<a href="#primeDelete">primeDelete</a>();
|
|
<a name="x2205"></a> cur.<a href="#del">del</a>();
|
|
}
|
|
</pre>
|
|
<p> In the above example, a cursor is created on the 'prices' table
|
|
and positioned to the record to be deleted. First <a href="#primeDelete">primeDelete</a>() is
|
|
called to populate the edit buffer with the current cursor values,
|
|
e.g. with an id of 999, and then <a href="#del">del</a>() is called to actually
|
|
delete the record from the database. Remember: all edit operations
|
|
(<a href="#insert">insert</a>(), <a href="#update">update</a>() and delete()) operate on the contents of the
|
|
cursor edit buffer and not on the contents of the cursor itself.
|
|
<p> <p>See also <a href="#primeDelete">primeDelete</a>(), <a href="#setMode">setMode</a>(), and <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
|
|
<p>Example: <a href="sql.html#x2205">sql/overview/delete/main.cpp</a>.
|
|
<h3 class=fn>int <a name="del-2"></a>TQSqlCursor::del ( const <a href="ntqstring.html">TQString</a> & filter, bool invalidate = TRUE )<tt> [virtual protected]</tt>
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Deletes the current cursor record from the database using the
|
|
filter <em>filter</em>. Only records which meet the filter criteria are
|
|
deleted. Returns the number of records which were deleted. If <em>invalidate</em> is TRUE (the default), the current cursor can no longer
|
|
be navigated. A new <a href="#select">select</a>() call must be made before you can move
|
|
to a valid record. For error information, use <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
<p> The <em>filter</em> is an SQL <tt>WHERE</tt> clause, e.g. <tt>id=500</tt>.
|
|
<p> <p>See also <a href="#setMode">setMode</a>() and <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
|
|
<h3 class=fn><a href="ntqsqlrecord.html">TQSqlRecord</a> * <a name="editBuffer"></a>TQSqlCursor::editBuffer ( bool copy = FALSE )<tt> [virtual]</tt>
|
|
</h3>
|
|
Returns the current internal edit buffer. If <em>copy</em> is TRUE (the
|
|
default is FALSE), the current cursor field values are first
|
|
copied into the edit buffer. The edit buffer is valid as long as
|
|
the cursor remains valid. The cursor retains ownership of the
|
|
returned pointer, so it must not be deleted or modified.
|
|
<p> <p>See also <a href="#primeInsert">primeInsert</a>(), <a href="#primeUpdate">primeUpdate</a>(), and <a href="#primeDelete">primeDelete</a>().
|
|
|
|
<h3 class=fn><a href="ntqstring.html">TQString</a> <a name="filter"></a>TQSqlCursor::filter () const
|
|
</h3>
|
|
Returns the current filter, or an empty string if there is no
|
|
current filter.
|
|
|
|
<h3 class=fn><a href="ntqsqlindex.html">TQSqlIndex</a> <a name="index"></a>TQSqlCursor::index ( const <a href="ntqstringlist.html">TQStringList</a> & fieldNames ) const<tt> [virtual]</tt>
|
|
</h3>
|
|
Returns an index composed of <em>fieldNames</em>, all in ASCending
|
|
order. Note that all field names must exist in the cursor,
|
|
otherwise an empty index is returned.
|
|
<p> <p>See also <a href="ntqsqlindex.html">TQSqlIndex</a>.
|
|
|
|
<p>Examples: <a href="sql.html#x2188">sql/overview/extract/main.cpp</a>, <a href="sql.html#x2181">sql/overview/order1/main.cpp</a>, <a href="sql.html#x2184">sql/overview/order2/main.cpp</a>, and <a href="sql.html#x2241">sql/overview/table3/main.cpp</a>.
|
|
<h3 class=fn><a href="ntqsqlindex.html">TQSqlIndex</a> <a name="index-2"></a>TQSqlCursor::index ( const <a href="ntqstring.html">TQString</a> & fieldName ) const
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Returns an index based on <em>fieldName</em>.
|
|
|
|
<h3 class=fn><a href="ntqsqlindex.html">TQSqlIndex</a> <a name="index-3"></a>TQSqlCursor::index ( const char * fieldName ) const
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Returns an index based on <em>fieldName</em>.
|
|
|
|
<h3 class=fn>void <a name="insert"></a>TQSqlCursor::insert ( int pos, const <a href="qsqlfieldinfo.html">TQSqlFieldInfo</a> & fieldInfo )<tt> [virtual]</tt>
|
|
</h3>
|
|
Insert a copy of <em>fieldInfo</em> at position <em>pos</em>. If a field
|
|
already exists at <em>pos</em>, it is removed. Note that all references
|
|
to the cursor edit buffer become invalidated.
|
|
|
|
<p>Examples: <a href="sql.html#x2194">sql/overview/insert/main.cpp</a> and <a href="ntqsqlcursor.html#x2446">sql/overview/insert2/main.cpp</a>.
|
|
<h3 class=fn>int <a name="insert-2"></a>TQSqlCursor::insert ( bool invalidate = TRUE )<tt> [virtual]</tt>
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Inserts the current contents of the cursor's edit record buffer
|
|
into the database, if the cursor allows inserts. Returns the
|
|
number of rows affected by the insert. For error information, use
|
|
<a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
<p> If <em>invalidate</em> is TRUE (the default), the cursor will no longer
|
|
be positioned on a valid record and can no longer be navigated. A
|
|
new <a href="#select">select</a>() call must be made before navigating to a valid
|
|
record.
|
|
<p>
|
|
|
|
<pre> TQSqlCursor cur( "prices" );
|
|
<a name="x2447"></a> <a href="ntqsqlrecord.html">TQSqlRecord</a> *buffer = cur.<a href="#primeInsert">primeInsert</a>();
|
|
<a name="x2448"></a> buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "id", 53981 );
|
|
buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "name", "Thingy" );
|
|
buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "price", 105.75 );
|
|
<a name="x2446"></a> cur.<a href="#insert">insert</a>();
|
|
</pre>
|
|
<p> In the above example, a cursor is created on the 'prices' table
|
|
and a pointer to the insert buffer is acquired using <a href="#primeInsert">primeInsert</a>().
|
|
Each field's value is set to the desired value and then <a href="#insert">insert</a>()
|
|
is called to insert the data into the database. Remember: all edit
|
|
operations (insert(), <a href="#update">update</a>() and delete()) operate on the
|
|
contents of the cursor edit buffer and not on the contents of the
|
|
cursor itself.
|
|
<p> <p>See also <a href="#setMode">setMode</a>() and <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
|
|
<h3 class=fn>bool <a name="isCalculated"></a>TQSqlCursor::isCalculated ( const <a href="ntqstring.html">TQString</a> & name ) const
|
|
</h3>
|
|
Returns TRUE if the field <em>name</em> exists and is calculated;
|
|
otherwise returns FALSE.
|
|
<p> <p>See also <a href="#setCalculated">setCalculated</a>().
|
|
|
|
<h3 class=fn>bool <a name="isNull"></a>TQSqlCursor::isNull ( int i ) const
|
|
</h3>
|
|
Returns TRUE if the field <em>i</em> is NULL or if there is no field at
|
|
position <em>i</em>; otherwise returns FALSE.
|
|
<p> This is the same as calling <a href="ntqsqlrecord.html#isNull">TQSqlRecord::isNull</a>( <em>i</em> )
|
|
|
|
<h3 class=fn>bool <a name="isNull-2"></a>TQSqlCursor::isNull ( const <a href="ntqstring.html">TQString</a> & name ) const
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Returns TRUE if the field called <em>name</em> is NULL or if there is no
|
|
field called <em>name</em>; otherwise returns FALSE.
|
|
<p> This is the same as calling <a href="ntqsqlrecord.html#isNull">TQSqlRecord::isNull</a>( <em>name</em> )
|
|
|
|
<h3 class=fn>bool <a name="isReadOnly"></a>TQSqlCursor::isReadOnly () const
|
|
</h3>
|
|
Returns TRUE if the cursor is read-only; otherwise returns FALSE.
|
|
The default is FALSE. Read-only cursors cannot be edited using
|
|
<a href="#insert">insert</a>(), <a href="#update">update</a>() or <a href="#del">del</a>().
|
|
<p> <p>See also <a href="#setMode">setMode</a>().
|
|
|
|
<h3 class=fn>bool <a name="isTrimmed"></a>TQSqlCursor::isTrimmed ( const <a href="ntqstring.html">TQString</a> & name ) const
|
|
</h3>
|
|
Returns TRUE if the field <em>name</em> exists and is trimmed; otherwise
|
|
returns FALSE.
|
|
<p> When a trimmed field of type string or cstring is read from the
|
|
database any trailing (right-most) spaces are removed.
|
|
<p> <p>See also <a href="#setTrimmed">setTrimmed</a>().
|
|
|
|
<h3 class=fn>int <a name="mode"></a>TQSqlCursor::mode () const
|
|
</h3>
|
|
Returns the current cursor mode.
|
|
<p> <p>See also <a href="#setMode">setMode</a>().
|
|
|
|
<h3 class=fn><a href="ntqstring.html">TQString</a> <a name="name"></a>TQSqlCursor::name () const
|
|
</h3>
|
|
Returns the name of the cursor.
|
|
|
|
<h3 class=fn><a href="ntqsqlcursor.html">TQSqlCursor</a> & <a name="operator-eq"></a>TQSqlCursor::operator= ( const <a href="ntqsqlcursor.html">TQSqlCursor</a> & other )
|
|
</h3>
|
|
Sets the cursor equal to <em>other</em>.
|
|
|
|
<h3 class=fn><a href="ntqsqlindex.html">TQSqlIndex</a> <a name="primaryIndex"></a>TQSqlCursor::primaryIndex ( bool setFromCursor = TRUE ) const<tt> [virtual]</tt>
|
|
</h3>
|
|
Returns the primary index associated with the cursor as defined in
|
|
the database, or an empty index if there is no primary index. If
|
|
<em>setFromCursor</em> is TRUE (the default), the index fields are
|
|
populated with the corresponding values in the cursor's current
|
|
record.
|
|
|
|
<h3 class=fn><a href="ntqsqlrecord.html">TQSqlRecord</a> * <a name="primeDelete"></a>TQSqlCursor::primeDelete ()<tt> [virtual]</tt>
|
|
</h3>
|
|
This function primes the edit buffer's field values for delete and
|
|
returns the edit buffer. The default implementation copies the
|
|
field values from the current cursor record into the edit buffer
|
|
(therefore, this function is equivalent to calling <a href="#editBuffer">editBuffer</a>(
|
|
TRUE ) ). The cursor retains ownership of the returned pointer, so
|
|
it must not be deleted or modified.
|
|
<p> <p>See also <a href="#editBuffer">editBuffer</a>() and <a href="#del">del</a>().
|
|
|
|
<p>Example: <a href="sql.html#x2206">sql/overview/delete/main.cpp</a>.
|
|
<h3 class=fn><a href="ntqsqlrecord.html">TQSqlRecord</a> * <a name="primeInsert"></a>TQSqlCursor::primeInsert ()<tt> [virtual]</tt>
|
|
</h3>
|
|
This function primes the edit buffer's field values for insert and
|
|
returns the edit buffer. The default implementation clears all
|
|
field values in the edit buffer. The cursor retains ownership of
|
|
the returned pointer, so it must not be deleted or modified.
|
|
<p> <p>See also <a href="#editBuffer">editBuffer</a>() and <a href="#insert">insert</a>().
|
|
|
|
<p>Examples: <a href="sql.html#x2195">sql/overview/insert/main.cpp</a>, <a href="ntqsqlcursor.html#x2447">sql/overview/insert2/main.cpp</a>, <a href="sql.html#x2267">sql/overview/subclass5/main.cpp</a>, and <a href="sqltable-example.html#x2453">sql/sqltable/main.cpp</a>.
|
|
<h3 class=fn><a href="ntqsqlrecord.html">TQSqlRecord</a> * <a name="primeUpdate"></a>TQSqlCursor::primeUpdate ()<tt> [virtual]</tt>
|
|
</h3>
|
|
This function primes the edit buffer's field values for update and
|
|
returns the edit buffer. The default implementation copies the
|
|
field values from the current cursor record into the edit buffer
|
|
(therefore, this function is equivalent to calling <a href="#editBuffer">editBuffer</a>(
|
|
TRUE ) ). The cursor retains ownership of the returned pointer, so
|
|
it must not be deleted or modified.
|
|
<p> <p>See also <a href="#editBuffer">editBuffer</a>() and <a href="#update">update</a>().
|
|
|
|
<p>Examples: <a href="sql.html#x2236">sql/overview/custom1/main.cpp</a>, <a href="sql.html#x2223">sql/overview/form1/main.cpp</a>, and <a href="sql.html#x2199">sql/overview/update/main.cpp</a>.
|
|
<h3 class=fn>void <a name="remove"></a>TQSqlCursor::remove ( int pos )<tt> [virtual]</tt>
|
|
</h3>
|
|
Removes the field at <em>pos</em>. If <em>pos</em> does not exist, nothing
|
|
happens. Note that all references to the cursor edit buffer become
|
|
invalidated.
|
|
|
|
<p>Reimplemented from <a href="ntqsqlrecord.html#remove">TQSqlRecord</a>.
|
|
<h3 class=fn>bool <a name="select"></a>TQSqlCursor::select ( const <a href="ntqstring.html">TQString</a> & filter, const <a href="ntqsqlindex.html">TQSqlIndex</a> & sort = TQSqlIndex ( ) )<tt> [virtual]</tt>
|
|
</h3>
|
|
Selects all fields in the cursor from the database matching the
|
|
filter criteria <em>filter</em>. The data is returned in the order
|
|
specified by the index <em>sort</em>. Returns TRUE if the data was
|
|
successfully selected; otherwise returns FALSE.
|
|
<p> The <em>filter</em> is a string containing a SQL <tt>WHERE</tt> clause but
|
|
without the 'WHERE' keyword. The cursor is initially positioned at
|
|
an invalid row after this function is called. To move to a valid
|
|
row, use <a href="ntqsqlquery.html#seek">seek</a>(), <a href="ntqsqlquery.html#first">first</a>(), <a href="ntqsqlquery.html#last">last</a>(), <a href="ntqsqlquery.html#prev">prev</a>() or <a href="ntqsqlquery.html#next">next</a>().
|
|
<p> Example:
|
|
<pre>
|
|
TQSqlCursor cur( "Employee" ); // Use the Employee table or view
|
|
cur.<a href="#select">select</a>( "deptno=10" ); // select all records in department 10
|
|
while( cur.<a href="ntqsqlquery.html#next">next</a>() ) {
|
|
... // process data
|
|
}
|
|
...
|
|
// select records in other departments, ordered by department number
|
|
cur.<a href="#select">select</a>( "deptno>10", cur.<a href="#index">index</a>( "deptno" ) );
|
|
...
|
|
</pre>
|
|
|
|
<p> The filter will apply to any subsequent <a href="#select">select</a>() calls that do not
|
|
explicitly specify another filter. Similarly the sort will apply
|
|
to any subsequent select() calls that do not explicitly specify
|
|
another sort.
|
|
<p> <pre>
|
|
TQSqlCursor cur( "Employee" );
|
|
cur.<a href="#select">select</a>( "deptno=10" ); // select all records in department 10
|
|
while( cur.<a href="ntqsqlquery.html#next">next</a>() ) {
|
|
... // process data
|
|
}
|
|
...
|
|
cur.<a href="#select">select</a>(); // re-selects all records in department 10
|
|
...
|
|
</pre>
|
|
|
|
<p>
|
|
<p>Examples: <a href="sql.html#x2207">sql/overview/delete/main.cpp</a>, <a href="sql.html#x2189">sql/overview/extract/main.cpp</a>, <a href="sql.html#x2182">sql/overview/order1/main.cpp</a>, <a href="sql.html#x2185">sql/overview/order2/main.cpp</a>, <a href="sql.html#x2178">sql/overview/retrieve2/main.cpp</a>, <a href="sql.html#x2242">sql/overview/table3/main.cpp</a>, and <a href="sql.html#x2200">sql/overview/update/main.cpp</a>.
|
|
<h3 class=fn>bool <a name="select-2"></a>TQSqlCursor::select ()
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Selects all fields in the cursor from the database. The rows are
|
|
returned in the order specified by the last call to <a href="#setSort">setSort</a>() or
|
|
the last call to <a href="#select">select</a>() that specified a sort, whichever is the
|
|
most recent. If there is no current sort, the order in which the
|
|
rows are returned is undefined. The records are filtered according
|
|
to the filter specified by the last call to <a href="#setFilter">setFilter</a>() or the
|
|
last call to select() that specified a filter, whichever is the
|
|
most recent. If there is no current filter, all records are
|
|
returned. The cursor is initially positioned at an invalid row. To
|
|
move to a valid row, use <a href="ntqsqlquery.html#seek">seek</a>(), <a href="ntqsqlquery.html#first">first</a>(), <a href="ntqsqlquery.html#last">last</a>(), <a href="ntqsqlquery.html#prev">prev</a>() or
|
|
<a href="ntqsqlquery.html#next">next</a>().
|
|
<p> <p>See also <a href="#setSort">setSort</a>() and <a href="#setFilter">setFilter</a>().
|
|
|
|
<h3 class=fn>bool <a name="select-3"></a>TQSqlCursor::select ( const <a href="ntqsqlindex.html">TQSqlIndex</a> & sort )
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Selects all fields in the cursor from the database. The data is
|
|
returned in the order specified by the index <em>sort</em>. The records
|
|
are filtered according to the filter specified by the last call to
|
|
<a href="#setFilter">setFilter</a>() or the last call to <a href="#select">select</a>() that specified a filter,
|
|
whichever is the most recent. The cursor is initially positioned
|
|
at an invalid row. To move to a valid row, use <a href="ntqsqlquery.html#seek">seek</a>(), <a href="ntqsqlquery.html#first">first</a>(),
|
|
<a href="ntqsqlquery.html#last">last</a>(), <a href="ntqsqlquery.html#prev">prev</a>() or <a href="ntqsqlquery.html#next">next</a>().
|
|
|
|
<h3 class=fn>bool <a name="select-4"></a>TQSqlCursor::select ( const <a href="ntqsqlindex.html">TQSqlIndex</a> & filter, const <a href="ntqsqlindex.html">TQSqlIndex</a> & sort )
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Selects all fields in the cursor matching the filter index <em>filter</em>. The data is returned in the order specified by the index
|
|
<em>sort</em>. The <em>filter</em> index works by constructing a WHERE clause
|
|
using the names of the fields from the <em>filter</em> and their values
|
|
from the current cursor record. The cursor is initially positioned
|
|
at an invalid row. To move to a valid row, use <a href="ntqsqlquery.html#seek">seek</a>(), <a href="ntqsqlquery.html#first">first</a>(),
|
|
<a href="ntqsqlquery.html#last">last</a>(), <a href="ntqsqlquery.html#prev">prev</a>() or <a href="ntqsqlquery.html#next">next</a>(). This function is useful, for example,
|
|
for retrieving data based upon a table's primary index:
|
|
<p> <pre>
|
|
TQSqlCursor cur( "Employee" );
|
|
<a href="ntqsqlindex.html">TQSqlIndex</a> pk = cur.<a href="#primaryIndex">primaryIndex</a>();
|
|
cur.<a href="ntqsqlrecord.html#setValue">setValue</a>( "id", 10 );
|
|
cur.<a href="#select">select</a>( pk, pk ); // generates "SELECT ... FROM Employee WHERE id=10 ORDER BY id"
|
|
...
|
|
</pre>
|
|
|
|
<p> In this example the <a href="ntqsqlindex.html">TQSqlIndex</a>, pk, is used for two different
|
|
purposes. When used as the filter (first) argument, the field
|
|
names it contains are used to construct the WHERE clause, each set
|
|
to the current cursor value, <tt>WHERE id=10</tt>, in this case. When
|
|
used as the sort (second) argument the field names it contains are
|
|
used for the ORDER BY clause, <tt>ORDER BY id</tt> in this example.
|
|
|
|
<h3 class=fn>void <a name="setCalculated"></a>TQSqlCursor::setCalculated ( const <a href="ntqstring.html">TQString</a> & name, bool calculated )<tt> [virtual]</tt>
|
|
</h3>
|
|
Sets field <em>name</em> to <em>calculated</em>. If the field <em>name</em> does not
|
|
exist, nothing happens. The value of a calculated field is set by
|
|
the <a href="#calculateField">calculateField</a>() virtual function which you must reimplement
|
|
(or the field value will be an invalid <a href="ntqvariant.html">TQVariant</a>). Calculated
|
|
fields do not appear in generated SQL statements sent to the
|
|
database.
|
|
<p> <p>See also <a href="#calculateField">calculateField</a>() and <a href="ntqsqlrecord.html#setGenerated">TQSqlRecord::setGenerated</a>().
|
|
|
|
<h3 class=fn>void <a name="setFilter"></a>TQSqlCursor::setFilter ( const <a href="ntqstring.html">TQString</a> & filter )<tt> [virtual]</tt>
|
|
</h3>
|
|
Sets the current filter to <em>filter</em>. Note that no new records are
|
|
selected. To select new records, use <a href="#select">select</a>(). The <em>filter</em> will
|
|
apply to any subsequent select() calls that do not explicitly
|
|
specify a filter.
|
|
<p> The filter is a SQL <tt>WHERE</tt> clause without the keyword 'WHERE',
|
|
e.g. <tt>name='Dave'</tt> which will be processed by the DBMS.
|
|
|
|
<h3 class=fn>void <a name="setGenerated"></a>TQSqlCursor::setGenerated ( const <a href="ntqstring.html">TQString</a> & name, bool generated )<tt> [virtual]</tt>
|
|
</h3>
|
|
Sets the generated flag for the field <em>name</em> to <em>generated</em>. If
|
|
the field does not exist, nothing happens. Only fields that have
|
|
<em>generated</em> set to TRUE are included in the SQL that is
|
|
generated by <a href="#insert">insert</a>(), <a href="#update">update</a>() or <a href="#del">del</a>().
|
|
<p> <p>See also <a href="ntqsqlrecord.html#isGenerated">isGenerated</a>().
|
|
|
|
<p>Reimplemented from <a href="ntqsqlrecord.html#setGenerated">TQSqlRecord</a>.
|
|
<h3 class=fn>void <a name="setGenerated-2"></a>TQSqlCursor::setGenerated ( int i, bool generated )<tt> [virtual]</tt>
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Sets the generated flag for the field <em>i</em> to <em>generated</em>.
|
|
<p> <p>See also <a href="ntqsqlrecord.html#isGenerated">isGenerated</a>().
|
|
|
|
<p>Reimplemented from <a href="ntqsqlrecord.html#setGenerated-2">TQSqlRecord</a>.
|
|
<h3 class=fn>void <a name="setMode"></a>TQSqlCursor::setMode ( int mode )<tt> [virtual]</tt>
|
|
</h3>
|
|
Sets the cursor mode to <em>mode</em>. This value can be an OR'ed
|
|
combination of <a href="#Mode-enum">TQSqlCursor::Mode</a> values. The default mode for a
|
|
cursor is <a href="#Mode-enum">TQSqlCursor::Writable</a>.
|
|
<p> <pre>
|
|
TQSqlCursor cur( "Employee" );
|
|
cur.<a href="#setMode">setMode</a>( TQSqlCursor::<a href="#Mode-enum">Writable</a> ); // allow insert/update/delete
|
|
...
|
|
cur.<a href="#setMode">setMode</a>( TQSqlCursor::<a href="#Mode-enum">Insert</a> | TQSqlCursor::<a href="#Mode-enum">Update</a> ); // allow inserts and updates only
|
|
...
|
|
cur.<a href="#setMode">setMode</a>( TQSqlCursor::<a href="#Mode-enum">ReadOnly</a> ); // no inserts/updates/deletes allowed
|
|
|
|
</pre>
|
|
|
|
|
|
<h3 class=fn>void <a name="setName"></a>TQSqlCursor::setName ( const <a href="ntqstring.html">TQString</a> & name, bool autopopulate = TRUE )<tt> [virtual]</tt>
|
|
</h3>
|
|
Sets the name of the cursor to <em>name</em>. If <em>autopopulate</em> is TRUE
|
|
(the default), the <em>name</em> must correspond to a valid table or
|
|
view name in the database. Also, note that all references to the
|
|
cursor edit buffer become invalidated when fields are
|
|
auto-populated. See the TQSqlCursor constructor documentation for
|
|
more information.
|
|
|
|
<h3 class=fn>void <a name="setPrimaryIndex"></a>TQSqlCursor::setPrimaryIndex ( const <a href="ntqsqlindex.html">TQSqlIndex</a> & idx )<tt> [virtual]</tt>
|
|
</h3>
|
|
Sets the primary index associated with the cursor to the index <em>idx</em>. Note that this index must contain a field or set of fields
|
|
which identify a unique record within the underlying database
|
|
table or view so that <a href="#update">update</a>() and <a href="#del">del</a>() will execute as expected.
|
|
<p> <p>See also <a href="#update">update</a>() and <a href="#del">del</a>().
|
|
|
|
<h3 class=fn>void <a name="setSort"></a>TQSqlCursor::setSort ( const <a href="ntqsqlindex.html">TQSqlIndex</a> & sort )<tt> [virtual]</tt>
|
|
</h3>
|
|
Sets the current sort to <em>sort</em>. Note that no new records are
|
|
selected. To select new records, use <a href="#select">select</a>(). The <em>sort</em> will
|
|
apply to any subsequent select() calls that do not explicitly
|
|
specify a sort.
|
|
|
|
<h3 class=fn>void <a name="setTrimmed"></a>TQSqlCursor::setTrimmed ( const <a href="ntqstring.html">TQString</a> & name, bool trim )<tt> [virtual]</tt>
|
|
</h3>
|
|
Sets field <em>name</em>'s trimmed status to <em>trim</em>. If the field <em>name</em> does not exist, nothing happens.
|
|
<p> When a trimmed field of type string or cstring is read from the
|
|
database any trailing (right-most) spaces are removed.
|
|
<p> <p>See also <a href="#isTrimmed">isTrimmed</a>() and <a href="ntqvariant.html">TQVariant</a>.
|
|
|
|
<h3 class=fn><a href="ntqsqlindex.html">TQSqlIndex</a> <a name="sort"></a>TQSqlCursor::sort () const
|
|
</h3>
|
|
Returns the current sort, or an empty index if there is no current
|
|
sort.
|
|
|
|
<h3 class=fn><a href="ntqstring.html">TQString</a> <a name="toString"></a>TQSqlCursor::toString ( <a href="ntqsqlrecord.html">TQSqlRecord</a> * rec, const <a href="ntqstring.html">TQString</a> & prefix, const <a href="ntqstring.html">TQString</a> & fieldSep, const <a href="ntqstring.html">TQString</a> & sep ) const<tt> [virtual protected]</tt>
|
|
</h3>
|
|
Returns a formatted string composed of all the fields in <em>rec</em>.
|
|
Each field is composed of the <em>prefix</em> (e.g. table or view name),
|
|
".", the field name, the <em>fieldSep</em> and the field value. If the
|
|
<em>prefix</em> is empty then each field will begin with the field name.
|
|
The fields are then joined together separated by <em>sep</em>. Fields
|
|
where <a href="ntqsqlrecord.html#isGenerated">isGenerated</a>() returns FALSE are not included. This function
|
|
is useful for generating SQL statements.
|
|
|
|
<h3 class=fn><a href="ntqstring.html">TQString</a> <a name="toString-3"></a>TQSqlCursor::toString ( const <a href="ntqstring.html">TQString</a> & prefix, <a href="ntqsqlfield.html">TQSqlField</a> * field, const <a href="ntqstring.html">TQString</a> & fieldSep ) const<tt> [virtual protected]</tt>
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Returns a formatted string composed of the <em>prefix</em> (e.g. table
|
|
or view name), ".", the <em>field</em> name, the <em>fieldSep</em> and the
|
|
field value. If the <em>prefix</em> is empty then the string will begin
|
|
with the <em>field</em> name. This function is useful for generating SQL
|
|
statements.
|
|
|
|
<h3 class=fn><a href="ntqstring.html">TQString</a> <a name="toString-4"></a>TQSqlCursor::toString ( const <a href="ntqsqlindex.html">TQSqlIndex</a> & i, <a href="ntqsqlrecord.html">TQSqlRecord</a> * rec, const <a href="ntqstring.html">TQString</a> & prefix, const <a href="ntqstring.html">TQString</a> & fieldSep, const <a href="ntqstring.html">TQString</a> & sep ) const<tt> [virtual protected]</tt>
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Returns a formatted string composed of all the fields in the index
|
|
<em>i</em>. Each field is composed of the <em>prefix</em> (e.g. table or view
|
|
name), ".", the field name, the <em>fieldSep</em> and the field value.
|
|
If the <em>prefix</em> is empty then each field will begin with the field
|
|
name. The field values are taken from <em>rec</em>. The fields are then
|
|
joined together separated by <em>sep</em>. Fields where <a href="ntqsqlrecord.html#isGenerated">isGenerated</a>()
|
|
returns FALSE are ignored. This function is useful for generating
|
|
SQL statements.
|
|
|
|
<h3 class=fn>int <a name="update"></a>TQSqlCursor::update ( bool invalidate = TRUE )<tt> [virtual]</tt>
|
|
</h3>
|
|
Updates the database with the current contents of the edit buffer.
|
|
Returns the number of records which were updated.
|
|
For error information, use <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
<p> Only records which meet the filter criteria specified by the
|
|
cursor's primary index are updated. If the cursor does not contain
|
|
a primary index, no update is performed and 0 is returned.
|
|
<p> If <em>invalidate</em> is TRUE (the default), the current cursor can no
|
|
longer be navigated. A new <a href="#select">select</a>() call must be made before you
|
|
can move to a valid record. For example:
|
|
<p>
|
|
|
|
<pre> TQSqlCursor cur( "prices" );
|
|
<a name="x2200"></a> cur.<a href="#select">select</a>( "id=202" );
|
|
if ( cur.<a href="ntqsqlquery.html#next">next</a>() ) {
|
|
<a name="x2199"></a> <a href="ntqsqlrecord.html">TQSqlRecord</a> *buffer = cur.<a href="#primeUpdate">primeUpdate</a>();
|
|
<a name="x2204"></a> double price = buffer-><a href="ntqsqlrecord.html#value">value</a>( "price" ).toDouble();
|
|
double newprice = price * 1.05;
|
|
<a name="x2203"></a> buffer-><a href="ntqsqlrecord.html#setValue">setValue</a>( "price", newprice );
|
|
<a name="x2201"></a> cur.<a href="#update">update</a>();
|
|
}
|
|
</pre>
|
|
<p> In the above example, a cursor is created on the 'prices' table
|
|
and is positioned on the record to be updated. Then a pointer to
|
|
the cursor's edit buffer is acquired using <a href="#primeUpdate">primeUpdate</a>(). A new
|
|
value is calculated and placed into the edit buffer with the
|
|
<a href="ntqsqlrecord.html#setValue">setValue</a>() call. Finally, an <a href="#update">update</a>() call is made on the cursor
|
|
which uses the tables's primary index to update the record in the
|
|
database with the contents of the cursor's edit buffer. Remember:
|
|
all edit operations (<a href="#insert">insert</a>(), update() and delete()) operate on
|
|
the contents of the cursor edit buffer and not on the contents of
|
|
the cursor itself.
|
|
<p> Note that if the primary index does not uniquely distinguish
|
|
records the database may be changed into an inconsistent state.
|
|
<p> <p>See also <a href="#setMode">setMode</a>() and <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
|
|
<p>Example: <a href="sql.html#x2201">sql/overview/update/main.cpp</a>.
|
|
<h3 class=fn>int <a name="update-2"></a>TQSqlCursor::update ( const <a href="ntqstring.html">TQString</a> & filter, bool invalidate = TRUE )<tt> [virtual protected]</tt>
|
|
</h3>
|
|
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
|
<p> Updates the database with the current contents of the cursor edit
|
|
buffer using the specified <em>filter</em>. Returns the number of
|
|
records which were updated.
|
|
For error information, use <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
<p> Only records which meet the filter criteria are updated, otherwise
|
|
all records in the table are updated.
|
|
<p> If <em>invalidate</em> is TRUE (the default), the cursor can no longer
|
|
be navigated. A new <a href="#select">select</a>() call must be made before you can move
|
|
to a valid record.
|
|
<p> <p>See also <a href="#primeUpdate">primeUpdate</a>(), <a href="#setMode">setMode</a>(), and <a href="ntqsqlquery.html#lastError">lastError</a>().
|
|
|
|
<!-- eof -->
|
|
<hr><p>
|
|
This file is part of the <a href="index.html">TQt toolkit</a>.
|
|
Copyright © 1995-2007
|
|
<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 © 2007
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|