source: trunk/doc/html/qsqlfield.html@ 208

Last change on this file since 208 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 9.8 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/sql/qsqlfield.cpp:42 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QSqlField Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<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>
33
34<p>The QSqlField class manipulates the fields in SQL database tables
35and views.
36<a href="#details">More...</a>
37<p><tt>#include &lt;<a href="qsqlfield-h.html">qsqlfield.h</a>&gt;</tt>
38<p><a href="qsqlfield-members.html">List of all member functions.</a>
39<h2>Public Members</h2>
40<ul>
41<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>
42<li class=fn><a href="#QSqlField-2"><b>QSqlField</b></a> ( const&nbsp;QSqlField&nbsp;&amp;&nbsp;other )</li>
43<li class=fn>QSqlField &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;QSqlField&nbsp;&amp;&nbsp;other )</li>
44<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;QSqlField&nbsp;&amp;&nbsp;other ) const</li>
45<li class=fn>virtual <a href="#~QSqlField"><b>~QSqlField</b></a> ()</li>
46<li class=fn>virtual void <a href="#setValue"><b>setValue</b></a> ( const&nbsp;QVariant&nbsp;&amp;&nbsp;value )</li>
47<li class=fn>virtual QVariant <a href="#value"><b>value</b></a> () const</li>
48<li class=fn>virtual void <a href="#setName"><b>setName</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;name )</li>
49<li class=fn>QString <a href="#name"><b>name</b></a> () const</li>
50<li class=fn>virtual void <a href="#setNull"><b>setNull</b></a> ()</li>
51<li class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</li>
52<li class=fn>virtual void <a href="#setReadOnly"><b>setReadOnly</b></a> ( bool&nbsp;readOnly )</li>
53<li class=fn>bool <a href="#isReadOnly"><b>isReadOnly</b></a> () const</li>
54<li class=fn>void <a href="#clear"><b>clear</b></a> ( bool&nbsp;nullify = TRUE )</li>
55<li class=fn>QVariant::Type <a href="#type"><b>type</b></a> () const</li>
56</ul>
57<hr><a name="details"></a><h2>Detailed Description</h2>
58
59
60The QSqlField class manipulates the fields in SQL database tables
61and views.
62<p>
63
64<p> QSqlField represents the characteristics of a single column in a
65database table or view, such as the data type and column name. A
66field also contains the value of the database column, which can be
67viewed or changed.
68<p> Field data values are stored as QVariants. Using an incompatible
69type is not permitted. For example:
70<p> <pre>
71 QSqlField f( "myfield", QVariant::Int );
72 f.<a href="#setValue">setValue</a>( QPixmap() ); // will not work
73 </pre>
74
75<p> However, the field will attempt to cast certain data types to the
76field data type where possible:
77<p> <pre>
78 QSqlField f( "myfield", QVariant::Int );
79 f.<a href="#setValue">setValue</a>( QString("123") ); // casts QString to int
80 </pre>
81
82<p> QSqlField objects are rarely created explicitly in application
83code. They are usually accessed indirectly through <a href="qsqlrecord.html">QSqlRecord</a>
84or <a href="qsqlcursor.html">QSqlCursor</a> which already contain a list of fields. For
85example:
86<p> <pre>
87 <a href="qsqlcursor.html">QSqlCursor</a> cur( "Employee" ); // create cursor using the 'Employee' table
88 QSqlField* f = cur.<a href="qsqlrecord.html#field">field</a>( "name" ); // use the 'name' field
89 f-&gt;<a href="#setValue">setValue</a>( "Dave" ); // set field value
90 ...
91 </pre>
92
93<p> In practice we rarely need to extract a pointer to a field at all.
94The previous example would normally be written:
95<p> <pre>
96 <a href="qsqlcursor.html">QSqlCursor</a> cur( "Employee" );
97 cur.<a href="qsqlrecord.html#setValue">setValue</a>( "name", "Dave" );
98 ...
99 </pre>
100
101<p>See also <a href="database.html">Database Classes</a>.
102
103<hr><h2>Member Function Documentation</h2>
104<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 )
105</h3>
106Constructs an empty field called <em>fieldName</em> of type <em>type</em>.
107
108<h3 class=fn><a name="QSqlField-2"></a>QSqlField::QSqlField ( const&nbsp;<a href="qsqlfield.html">QSqlField</a>&nbsp;&amp;&nbsp;other )
109</h3>
110Constructs a copy of <em>other</em>.
111
112<h3 class=fn><a name="~QSqlField"></a>QSqlField::~QSqlField ()<tt> [virtual]</tt>
113</h3>
114Destroys the object and frees any allocated resources.
115
116<h3 class=fn>void <a name="clear"></a>QSqlField::clear ( bool&nbsp;nullify = TRUE )
117</h3>
118Clears the value of the field. If the field is read-only, nothing
119happens. If <em>nullify</em> is TRUE (the default), the field is set to
120NULL.
121
122<h3 class=fn>bool <a name="isNull"></a>QSqlField::isNull () const
123</h3>
124
125<p> Returns TRUE if the field is currently NULL; otherwise returns
126FALSE.
127
128<h3 class=fn>bool <a name="isReadOnly"></a>QSqlField::isReadOnly () const
129</h3>
130
131<p> Returns TRUE if the field's value is read only; otherwise returns
132FALSE.
133
134<h3 class=fn><a href="qstring.html">QString</a> <a name="name"></a>QSqlField::name () const
135</h3>
136
137<p> Returns the name of the field.
138
139<p>Example: <a href="sql.html#x2249">sql/overview/table4/main.cpp</a>.
140<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 )
141</h3>
142Sets the field equal to <em>other</em>.
143
144<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
145</h3>
146Returns TRUE if the field is equal to <em>other</em>; otherwise returns
147FALSE. Fields are considered equal when the following field
148properties are the same:
149<p> <ul>
150<li> <a href="#name">name</a>()
151<li> <a href="#isNull">isNull</a>()
152<li> <a href="#value">value</a>()
153<li> <a href="#isReadOnly">isReadOnly</a>()
154</ul>
155<p>
156<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>
157</h3>
158
159<p> Sets the name of the field to <em>name</em>.
160
161<h3 class=fn>void <a name="setNull"></a>QSqlField::setNull ()<tt> [virtual]</tt>
162</h3>
163
164<p> Sets the field to NULL and clears the value using <a href="#clear">clear</a>(). If the
165field is read-only, nothing happens.
166<p> <p>See also <a href="#isReadOnly">isReadOnly</a>() and <a href="#clear">clear</a>().
167
168<h3 class=fn>void <a name="setReadOnly"></a>QSqlField::setReadOnly ( bool&nbsp;readOnly )<tt> [virtual]</tt>
169</h3>
170
171<p> Sets the read only flag of the field's value to <em>readOnly</em>.
172<p> <p>See also <a href="#setValue">setValue</a>().
173
174<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>
175</h3>
176Sets the value of the field to <em>value</em>. If the field is read-only
177(<a href="#isReadOnly">isReadOnly</a>() returns TRUE), nothing happens. If the data type of
178<em>value</em> differs from the field's current data type, an attempt is
179made to cast it to the proper type. This preserves the data type
180of the field in the case of assignment, e.g. a <a href="qstring.html">QString</a> to an
181integer data type. For example:
182<p> <pre>
183 <a href="qsqlcursor.html">QSqlCursor</a> cur( "Employee" ); // 'Employee' table
184 QSqlField* f = cur.<a href="qsqlrecord.html#field">field</a>( "student_count" ); // an integer field
185 ...
186 f-&gt;<a href="#setValue">setValue</a>( myLineEdit-&gt;text() ); // cast the line edit text to an integer
187 </pre>
188
189<p> <p>See also <a href="#isReadOnly">isReadOnly</a>().
190
191<h3 class=fn><a href="qvariant.html#Type-enum">QVariant::Type</a> <a name="type"></a>QSqlField::type () const
192</h3>
193
194<p> Returns the field's type as stored in the database.
195Note that the actual value might have a different type,
196Numerical values that are too large to store in a long
197int or double are usually stored as strings to prevent
198precision loss.
199
200<h3 class=fn><a href="qvariant.html">QVariant</a> <a name="value"></a>QSqlField::value () const<tt> [virtual]</tt>
201</h3>
202
203<p> Returns the value of the field as a <a href="qvariant.html">QVariant</a>.
204
205<p>Example: <a href="sql.html#x2250">sql/overview/table4/main.cpp</a>.
206<!-- eof -->
207<hr><p>
208This file is part of the <a href="index.html">Qt toolkit</a>.
209Copyright &copy; 1995-2007
210<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
211<table width=100% cellspacing=0 border=0><tr>
212<td>Copyright &copy; 2007
213<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
214<td align=right><div align=right>Qt 3.3.8</div>
215</table></div></address></body>
216</html>
Note: See TracBrowser for help on using the repository browser.