summaryrefslogtreecommitdiffstats
path: root/doc/html/qsqlfield.html
blob: f5d6f36389655f1cb1f204fe317825ea7dda18fa (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
<!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/qsqlfield.cpp:42 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QSqlField 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>QSqlField Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1>

<p>The QSqlField class manipulates the fields in SQL database tables
and views.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qsqlfield-h.html">qsqlfield.h</a>&gt;</tt>
<p><a href="qsqlfield-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QSqlField"><b>QSqlField</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;fieldName = QString::null, QVariant::Type&nbsp;type = QVariant::Invalid )</li>
<li class=fn><a href="#QSqlField-2"><b>QSqlField</b></a> ( const&nbsp;QSqlField&nbsp;&amp;&nbsp;other )</li>
<li class=fn>QSqlField &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QSqlField&nbsp;&amp;&nbsp;other )</li>
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QSqlField&nbsp;&amp;&nbsp;other ) const</li>
<li class=fn>virtual <a href="#~QSqlField"><b>~QSqlField</b></a> ()</li>
<li class=fn>virtual void <a href="#setValue"><b>setValue</b></a> ( const&nbsp;QVariant&nbsp;&amp;&nbsp;value )</li>
<li class=fn>virtual QVariant <a href="#value"><b>value</b></a> () const</li>
<li class=fn>virtual void <a href="#setName"><b>setName</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name )</li>
<li class=fn>QString <a href="#name"><b>name</b></a> () const</li>
<li class=fn>virtual void <a href="#setNull"><b>setNull</b></a> ()</li>
<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
<li class=fn>virtual void <a href="#setReadOnly"><b>setReadOnly</b></a> ( bool&nbsp;readOnly )</li>
<li class=fn>bool <a href="#isReadOnly"><b>isReadOnly</b></a> () const</li>
<li class=fn>void <a href="#clear"><b>clear</b></a> ( bool&nbsp;nullify = TRUE )</li>
<li class=fn>QVariant::Type <a href="#type"><b>type</b></a> () const</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QSqlField class manipulates the fields in SQL database tables
and views.
<p> 

<p> QSqlField represents the characteristics of a single column in a
database table or view, such as the data type and column name. A
field also contains the value of the database column, which can be
viewed or changed.
<p> Field data values are stored as QVariants. Using an incompatible
type is not permitted. For example:
<p> <pre>
    QSqlField f( "myfield", QVariant::Int );
    f.<a href="#setValue">setValue</a>( QPixmap() );  // will not work
    </pre>
 
<p> However, the field will attempt to cast certain data types to the
field data type where possible:
<p> <pre>
    QSqlField f( "myfield", QVariant::Int );
    f.<a href="#setValue">setValue</a>( QString("123") ); // casts QString to int
    </pre>
 
<p> QSqlField objects are rarely created explicitly in application
code. They are usually accessed indirectly through <a href="qsqlrecord.html">QSqlRecord</a>
or <a href="qsqlcursor.html">QSqlCursor</a> which already contain a list of fields. For
example:
<p> <pre>
    <a href="qsqlcursor.html">QSqlCursor</a> cur( "Employee" );        // create cursor using the 'Employee' table
    QSqlField* f = cur.<a href="qsqlrecord.html#field">field</a>( "name" );  // use the 'name' field
    f-&gt;<a href="#setValue">setValue</a>( "Dave" );               // set field value
    ...
    </pre>
 
<p> In practice we rarely need to extract a pointer to a field at all.
The previous example would normally be written:
<p> <pre>
    <a href="qsqlcursor.html">QSqlCursor</a> cur( "Employee" );
    cur.<a href="qsqlrecord.html#setValue">setValue</a>( "name", "Dave" );
    ...
    </pre>
 
<p>See also <a href="database.html">Database Classes</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QSqlField"></a>QSqlField::QSqlField ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;fieldName = QString::null, <a href="qvariant.html#Type-enum">QVariant::Type</a>&nbsp;type = QVariant::Invalid )
</h3>
Constructs an empty field called <em>fieldName</em> of type <em>type</em>.

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

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

<h3 class=fn>void <a name="clear"></a>QSqlField::clear ( bool&nbsp;nullify = TRUE )
</h3>
Clears the value of the field. If the field is read-only, nothing
happens. If <em>nullify</em> is TRUE (the default), the field is set to
NULL.

<h3 class=fn>bool <a name="isNull"></a>QSqlField::isNull () const
</h3>

<p> Returns TRUE if the field is currently NULL; otherwise returns
FALSE.

<h3 class=fn>bool <a name="isReadOnly"></a>QSqlField::isReadOnly () const
</h3>

<p> Returns TRUE if the field's value is read only; otherwise returns
FALSE.

<h3 class=fn><a href="qstring.html">QString</a> <a name="name"></a>QSqlField::name () const
</h3>

<p> Returns the name of the field.

<p>Example: <a href="sql.html#x2249">sql/overview/table4/main.cpp</a>.
<h3 class=fn><a href="qsqlfield.html">QSqlField</a>&nbsp;&amp; <a name="operator-eq"></a>QSqlField::operator= ( const&nbsp;<a href="qsqlfield.html">QSqlField</a>&nbsp;&amp;&nbsp;other )
</h3>
Sets the field equal to <em>other</em>.

<h3 class=fn>bool <a name="operator-eq-eq"></a>QSqlField::operator== ( const&nbsp;<a href="qsqlfield.html">QSqlField</a>&nbsp;&amp;&nbsp;other ) const
</h3>
Returns TRUE if the field is equal to <em>other</em>; otherwise returns
FALSE. Fields are considered equal when the following field
properties are the same:
<p> <ul>
<li> <a href="#name">name</a>()
<li> <a href="#isNull">isNull</a>()
<li> <a href="#value">value</a>()
<li> <a href="#isReadOnly">isReadOnly</a>()
</ul>
<p> 
<h3 class=fn>void <a name="setName"></a>QSqlField::setName ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;name )<tt> [virtual]</tt>
</h3>

<p> Sets the name of the field to <em>name</em>.

<h3 class=fn>void <a name="setNull"></a>QSqlField::setNull ()<tt> [virtual]</tt>
</h3>

<p> Sets the field to NULL and clears the value using <a href="#clear">clear</a>(). If the
field is read-only, nothing happens.
<p> <p>See also <a href="#isReadOnly">isReadOnly</a>() and <a href="#clear">clear</a>().

<h3 class=fn>void <a name="setReadOnly"></a>QSqlField::setReadOnly ( bool&nbsp;readOnly )<tt> [virtual]</tt>
</h3>

<p> Sets the read only flag of the field's value to <em>readOnly</em>.
<p> <p>See also <a href="#setValue">setValue</a>().

<h3 class=fn>void <a name="setValue"></a>QSqlField::setValue ( const&nbsp;<a href="qvariant.html">QVariant</a>&nbsp;&amp;&nbsp;value )<tt> [virtual]</tt>
</h3>
Sets the value of the field to <em>value</em>. If the field is read-only
(<a href="#isReadOnly">isReadOnly</a>() returns TRUE), nothing happens. If the data type of
<em>value</em> differs from the field's current data type, an attempt is
made to cast it to the proper type. This preserves the data type
of the field in the case of assignment, e.g. a <a href="qstring.html">QString</a> to an
integer data type. For example:
<p> <pre>
    <a href="qsqlcursor.html">QSqlCursor</a> cur( "Employee" );                 // 'Employee' table
    QSqlField* f = cur.<a href="qsqlrecord.html#field">field</a>( "student_count" );  // an integer field
    ...
    f-&gt;<a href="#setValue">setValue</a>( myLineEdit-&gt;text() );            // cast the line edit text to an integer
    </pre>
 
<p> <p>See also <a href="#isReadOnly">isReadOnly</a>().

<h3 class=fn><a href="qvariant.html#Type-enum">QVariant::Type</a> <a name="type"></a>QSqlField::type () const
</h3>

<p> Returns the field's type as stored in the database.
Note that the actual value might have a different type,
Numerical values that are too large to store in a long
int or double are usually stored as strings to prevent
precision loss.

<h3 class=fn><a href="qvariant.html">QVariant</a> <a name="value"></a>QSqlField::value () const<tt> [virtual]</tt>
</h3>

<p> Returns the value of the field as a <a href="qvariant.html">QVariant</a>.

<p>Example: <a href="sql.html#x2250">sql/overview/table4/main.cpp</a>.
<!-- 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>