summaryrefslogtreecommitdiffstats
path: root/doc/html/qsqlrecord.html
blob: 02aca5035b36395324d7316c0cba465811d215a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<!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/qsqlrecord.cpp:151 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QSqlRecord 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&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;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>QSqlRecord Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1>

<p>The QSqlRecord class encapsulates a database record, i.e. a
set of database fields.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qsqlrecord-h.html">qsqlrecord.h</a>&gt;</tt>
<p>Inherited by <a href="qsqlcursor.html">QSqlCursor</a> and <a href="qsqlindex.html">QSqlIndex</a>.
<p><a href="qsqlrecord-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QSqlRecord"><b>QSqlRecord</b></a> ()</li>
<li class=fn><a href="#QSqlRecord-2"><b>QSqlRecord</b></a> ( const&nbsp;QSqlRecord&nbsp;&amp;&nbsp;other )</li>
<li class=fn>QSqlRecord &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QSqlRecord&nbsp;&amp;&nbsp;other )</li>
<li class=fn>virtual <a href="#~QSqlRecord"><b>~QSqlRecord</b></a> ()</li>
<li class=fn>virtual QVariant <a href="#value"><b>value</b></a> ( int&nbsp;i ) const</li>
<li class=fn>virtual QVariant <a href="#value-2"><b>value</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name ) const</li>
<li class=fn>virtual void <a href="#setValue"><b>setValue</b></a> ( int&nbsp;i, const&nbsp;QVariant&nbsp;&amp;&nbsp;val )</li>
<li class=fn>virtual void <a href="#setValue-2"><b>setValue</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name, const&nbsp;QVariant&nbsp;&amp;&nbsp;val )</li>
<li class=fn>bool <a href="#isGenerated-2"><b>isGenerated</b></a> ( int&nbsp;i ) const</li>
<li class=fn>bool <a href="#isGenerated"><b>isGenerated</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name ) const</li>
<li class=fn>virtual void <a href="#setGenerated"><b>setGenerated</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name, bool&nbsp;generated )</li>
<li class=fn>virtual void <a href="#setGenerated-2"><b>setGenerated</b></a> ( int&nbsp;i, bool&nbsp;generated )</li>
<li class=fn>virtual void <a href="#setNull"><b>setNull</b></a> ( int&nbsp;i )</li>
<li class=fn>virtual void <a href="#setNull-2"><b>setNull</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name )</li>
<li class=fn>bool <a href="#isNull-4"><b>isNull</b></a> ( int&nbsp;i ) const</li>
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name ) const</li>
<li class=fn>int <a href="#position"><b>position</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name ) const</li>
<li class=fn>QString <a href="#fieldName"><b>fieldName</b></a> ( int&nbsp;i ) const</li>
<li class=fn>QSqlField * <a href="#field"><b>field</b></a> ( int&nbsp;i )</li>
<li class=fn>QSqlField * <a href="#field-2"><b>field</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name )</li>
<li class=fn>const QSqlField * <a href="#field-3"><b>field</b></a> ( int&nbsp;i ) const</li>
<li class=fn>const QSqlField * <a href="#field-4"><b>field</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name ) const</li>
<li class=fn>virtual void <a href="#append"><b>append</b></a> ( const&nbsp;QSqlField&nbsp;&amp;&nbsp;field )</li>
<li class=fn>virtual void <a href="#insert"><b>insert</b></a> ( int&nbsp;pos, const&nbsp;QSqlField&nbsp;&amp;&nbsp;field )</li>
<li class=fn>virtual void <a href="#remove"><b>remove</b></a> ( int&nbsp;pos )</li>
<li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
<li class=fn>bool <a href="#contains"><b>contains</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name ) const</li>
<li class=fn>virtual void <a href="#clear"><b>clear</b></a> ()</li>
<li class=fn>virtual void <a href="#clearValues"><b>clearValues</b></a> ( bool&nbsp;nullify = FALSE )</li>
<li class=fn>uint <a href="#count"><b>count</b></a> () const</li>
<li class=fn>virtual QString <a href="#toString"><b>toString</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;prefix = QString::null, const&nbsp;QString&nbsp;&amp;&nbsp;sep = "," ) const</li>
<li class=fn>virtual QStringList <a href="#toStringList"><b>toStringList</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;prefix = QString::null ) const</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QSqlRecord class encapsulates a database record, i.e. a
set of database fields.
<p> 

<p> The QSqlRecord class encapsulates the functionality and
characteristics of a database record (usually a table or view within
the database). QSqlRecords support adding and removing fields as
well as setting and retrieving field values.
<p> QSqlRecord is <a href="shclass.html#implicitly-shared">implicitly shared</a>. This means you can make copies of
the record in time O(1). If multiple QSqlRecord instances share
the same data and one is modifying the record's data then this
modifying instance makes a copy and modifies its private copy -
thus it does not affect other instances.
<p> <p>See also <a href="qsqlrecordinfo.html">QSqlRecordInfo</a> and <a href="database.html">Database Classes</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QSqlRecord"></a>QSqlRecord::QSqlRecord ()
</h3>
Constructs an empty record.

<h3 class=fn><a name="QSqlRecord-2"></a>QSqlRecord::QSqlRecord ( const&nbsp;<a href="qsqlrecord.html">QSqlRecord</a>&nbsp;&amp;&nbsp;other )
</h3>
Constructs a copy of <em>other</em>.

<h3 class=fn><a name="~QSqlRecord"></a>QSqlRecord::~QSqlRecord ()<tt> [virtual]</tt>
</h3>
Destroys the object and frees any allocated resources.

<h3 class=fn>void <a name="append"></a>QSqlRecord::append ( const&nbsp;<a href="qsqlfield.html">QSqlField</a>&nbsp;&amp;&nbsp;field )<tt> [virtual]</tt>
</h3>
Append a copy of field <em>field</em> to the end of the record.

<p>Reimplemented in <a href="qsqlindex.html#append">QSqlIndex</a>.
<h3 class=fn>void <a name="clear"></a>QSqlRecord::clear ()<tt> [virtual]</tt>
</h3>
Removes all the record's fields.
<p> <p>See also <a href="#clearValues">clearValues</a>().

<p>Reimplemented in <a href="qsqlcursor.html#clear">QSqlCursor</a>.
<h3 class=fn>void <a name="clearValues"></a>QSqlRecord::clearValues ( bool&nbsp;nullify = FALSE )<tt> [virtual]</tt>
</h3>
Clears the value of all fields in the record. If <em>nullify</em> is
TRUE, (the default is FALSE), each field is set to NULL.

<h3 class=fn>bool <a name="contains"></a>QSqlRecord::contains ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name ) const
</h3>
Returns TRUE if there is a field in the record called <em>name</em>;
otherwise returns FALSE.

<h3 class=fn>uint <a name="count"></a>QSqlRecord::count () const
</h3>
Returns the number of fields in the record.

<h3 class=fn><a href="qsqlfield.html">QSqlField</a>&nbsp;* <a name="field"></a>QSqlRecord::field ( int&nbsp;i )
</h3>
Returns the field at position <em>i</em> within the record, or 0 if it
cannot be found.

<h3 class=fn><a href="qsqlfield.html">QSqlField</a>&nbsp;* <a name="field-2"></a>QSqlRecord::field ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the field called <em>name</em> within the record, or 0 if it
cannot be found. Field names are not case-sensitive.

<h3 class=fn>const&nbsp;<a href="qsqlfield.html">QSqlField</a>&nbsp;* <a name="field-3"></a>QSqlRecord::field ( int&nbsp;i ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> 
<h3 class=fn>const&nbsp;<a href="qsqlfield.html">QSqlField</a>&nbsp;* <a name="field-4"></a>QSqlRecord::field ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the field called <em>name</em> within the record, or 0 if it
cannot be found. Field names are not case-sensitive.

<h3 class=fn><a href="qstring.html">QString</a> <a name="fieldName"></a>QSqlRecord::fieldName ( int&nbsp;i ) const
</h3>
Returns the name of the field at position <em>i</em>. If the field does
not exist, <a href="qstring.html#QString-null">QString::null</a> is returned.

<h3 class=fn>void <a name="insert"></a>QSqlRecord::insert ( int&nbsp;pos, const&nbsp;<a href="qsqlfield.html">QSqlField</a>&nbsp;&amp;&nbsp;field )<tt> [virtual]</tt>
</h3>
Insert a copy of <em>field</em> at position <em>pos</em>. If a field already
exists at <em>pos</em>, it is removed.

<h3 class=fn>bool <a name="isEmpty"></a>QSqlRecord::isEmpty () const
</h3>
Returns TRUE if there are no fields in the record; otherwise
returns FALSE.

<h3 class=fn>bool <a name="isGenerated"></a>QSqlRecord::isGenerated ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name ) const
</h3>
Returns TRUE if the record has a field called <em>name</em> and this
field is to be generated (the default); otherwise returns FALSE.
<p> <p>See also <a href="#setGenerated">setGenerated</a>().

<h3 class=fn>bool <a name="isGenerated-2"></a>QSqlRecord::isGenerated ( int&nbsp;i ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns TRUE if the record has a field at position <em>i</em> and this
field is to be generated (the default); otherwise returns FALSE.
<p> <p>See also <a href="#setGenerated">setGenerated</a>().

<h3 class=fn>bool <a name="isNull"></a>QSqlRecord::isNull ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name ) const
</h3>
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> <p>See also <a href="#position">position</a>().

<h3 class=fn>bool <a name="isNull-4"></a>QSqlRecord::isNull ( int&nbsp;i ) const
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> 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> <p>See also <a href="#fieldName">fieldName</a>().

<h3 class=fn><a href="qsqlrecord.html">QSqlRecord</a>&nbsp;&amp; <a name="operator-eq"></a>QSqlRecord::operator= ( const&nbsp;<a href="qsqlrecord.html">QSqlRecord</a>&nbsp;&amp;&nbsp;other )
</h3>
Sets the record equal to <em>other</em>.

<h3 class=fn>int <a name="position"></a>QSqlRecord::position ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name ) const
</h3>
Returns the position of the field called <em>name</em> within the
record, or -1 if it cannot be found. Field names are not
case-sensitive. If more than one field matches, the first one is
returned.

<h3 class=fn>void <a name="remove"></a>QSqlRecord::remove ( int&nbsp;pos )<tt> [virtual]</tt>
</h3>
Removes the field at <em>pos</em>. If <em>pos</em> does not exist, nothing
happens.

<p>Reimplemented in <a href="qsqlcursor.html#remove">QSqlCursor</a>.
<h3 class=fn>void <a name="setGenerated"></a>QSqlRecord::setGenerated ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name, bool&nbsp;generated )<tt> [virtual]</tt>
</h3>
Sets the generated flag for the field called <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, e.g. by <a href="qsqlcursor.html">QSqlCursor</a>.
<p> <p>See also <a href="#isGenerated">isGenerated</a>().

<p>Reimplemented in <a href="qsqlcursor.html#setGenerated">QSqlCursor</a>.
<h3 class=fn>void <a name="setGenerated-2"></a>QSqlRecord::setGenerated ( int&nbsp;i, bool&nbsp;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="#isGenerated">isGenerated</a>().

<p>Reimplemented in <a href="qsqlcursor.html#setGenerated-2">QSqlCursor</a>.
<h3 class=fn>void <a name="setNull"></a>QSqlRecord::setNull ( int&nbsp;i )<tt> [virtual]</tt>
</h3>
Sets the value of field <em>i</em> to NULL. If the field does not exist,
nothing happens.

<h3 class=fn>void <a name="setNull-2"></a>QSqlRecord::setNull ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name )<tt> [virtual]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Sets the value of the field called <em>name</em> to NULL. If the field
does not exist, nothing happens.

<h3 class=fn>void <a name="setValue"></a>QSqlRecord::setValue ( int&nbsp;i, const&nbsp;<a href="qvariant.html">QVariant</a>&nbsp;&amp;&nbsp;val )<tt> [virtual]</tt>
</h3>
Sets the value of the field at position <em>i</em> to <em>val</em>. If the
field does not exist, nothing happens.

<p>Examples: <a href="sql.html#x2196">sql/overview/insert/main.cpp</a>, <a href="qsqlcursor.html#x2448">sql/overview/insert2/main.cpp</a>, <a href="sql.html#x2270">sql/overview/subclass5/main.cpp</a>, <a href="sql.html#x2203">sql/overview/update/main.cpp</a>, and <a href="sqltable-example.html#x2464">sql/sqltable/main.cpp</a>.
<h3 class=fn>void <a name="setValue-2"></a>QSqlRecord::setValue ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name, const&nbsp;<a href="qvariant.html">QVariant</a>&nbsp;&amp;&nbsp;val )<tt> [virtual]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Sets the value of the field called <em>name</em> to <em>val</em>. If the field
does not exist, nothing happens.

<h3 class=fn><a href="qstring.html">QString</a> <a name="toString"></a>QSqlRecord::toString ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;prefix = QString::null, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;sep = "," ) const<tt> [virtual]</tt>
</h3>
Returns a list of all the record's field names as a string
separated by <em>sep</em>.
<p> Note that fields which are not generated are <em>not</em> included (see
<a href="#isGenerated">isGenerated</a>()). The returned string is suitable, for example, for
generating SQL SELECT statements. If a <em>prefix</em> is specified,
e.g. a table name, all fields are prefixed in the form:
<p> "<em>prefix</em>.&lt;fieldname&gt;"

<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="toStringList"></a>QSqlRecord::toStringList ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;prefix = QString::null ) const<tt> [virtual]</tt>
</h3>
Returns a list of all the record's field names, each having the
prefix <em>prefix</em>.
<p> Note that fields which have generated set to FALSE are <em>not</em>
included. (See <a href="#isGenerated">isGenerated</a>()). If <em>prefix</em> is supplied, e.g.
a table name, all fields are prefixed in the form:
<p> "<em>prefix</em>.&lt;fieldname&gt;"

<h3 class=fn><a href="qvariant.html">QVariant</a> <a name="value"></a>QSqlRecord::value ( int&nbsp;i ) const<tt> [virtual]</tt>
</h3>
Returns the value of the field located at position <em>i</em> in the
record. If field <em>i</em> does not exist the resultant behaviour is
undefined.
<p> This function should be used with <a href="qsqlquery.html">QSqlQuery</a>s. When working
with a <a href="qsqlcursor.html">QSqlCursor</a> the <a href="qsqlquery.html#value">value(const
    QString&)</a> overload which uses field names is more
appropriate.

<p>Example: <a href="sql.html#x2204">sql/overview/update/main.cpp</a>.
<h3 class=fn><a href="qvariant.html">QVariant</a> <a name="value-2"></a>QSqlRecord::value ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name ) const<tt> [virtual]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns the value of the field called <em>name</em> in the record. If
field <em>name</em> does not exist the resultant behaviour is undefined.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 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 &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>