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.
tqt3/doc/html/ntqsqlfield.html

217 lines
9.7 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/qsqlfield.cpp:42 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQSqlField 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>TQSqlField Class Reference<br><small>[<a href="sql.html">sql module</a>]</small></h1>
<p>The TQSqlField class manipulates the fields in SQL database tables
and views.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qsqlfield-h.html">ntqsqlfield.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="#TQSqlField"><b>TQSqlField</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;fieldName = TQString::null, TQVariant::Type&nbsp;type = TQVariant::Invalid )</li>
<li class=fn><a href="#TQSqlField-2"><b>TQSqlField</b></a> ( const&nbsp;TQSqlField&nbsp;&amp;&nbsp;other )</li>
<li class=fn>TQSqlField &amp; <a href="#operator-eq"><b>operator=</b></a> ( const&nbsp;TQSqlField&nbsp;&amp;&nbsp;other )</li>
<li class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const&nbsp;TQSqlField&nbsp;&amp;&nbsp;other ) const</li>
<li class=fn>virtual <a href="#~TQSqlField"><b>~TQSqlField</b></a> ()</li>
<li class=fn>virtual void <a href="#setValue"><b>setValue</b></a> ( const&nbsp;TQVariant&nbsp;&amp;&nbsp;value )</li>
<li class=fn>virtual TQVariant <a href="#value"><b>value</b></a> () const</li>
<li class=fn>virtual void <a href="#setName"><b>setName</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;name )</li>
<li class=fn>TQString <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>TQVariant::Type <a href="#type"><b>type</b></a> () const</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The TQSqlField class manipulates the fields in SQL database tables
and views.
<p>
<p> TQSqlField 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 TQVariants. Using an incompatible
type is not permitted. For example:
<p> <pre>
TQSqlField f( "myfield", TQVariant::Int );
f.<a href="#setValue">setValue</a>( TQPixmap() ); // will not work
</pre>
<p> However, the field will attempt to cast certain data types to the
field data type where possible:
<p> <pre>
TQSqlField f( "myfield", TQVariant::Int );
f.<a href="#setValue">setValue</a>( TQString("123") ); // casts TQString to int
</pre>
<p> TQSqlField objects are rarely created explicitly in application
code. They are usually accessed indirectly through <a href="ntqsqlrecord.html">TQSqlRecord</a>
or <a href="ntqsqlcursor.html">TQSqlCursor</a> which already contain a list of fields. For
example:
<p> <pre>
<a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "Employee" ); // create cursor using the 'Employee' table
TQSqlField* f = cur.<a href="ntqsqlrecord.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="ntqsqlcursor.html">TQSqlCursor</a> cur( "Employee" );
cur.<a href="ntqsqlrecord.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="TQSqlField"></a>TQSqlField::TQSqlField ( const&nbsp;<a href="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;fieldName = TQString::null, <a href="ntqvariant.html#Type-enum">TQVariant::Type</a>&nbsp;type = TQVariant::Invalid )
</h3>
Constructs an empty field called <em>fieldName</em> of type <em>type</em>.
<h3 class=fn><a name="TQSqlField-2"></a>TQSqlField::TQSqlField ( const&nbsp;<a href="ntqsqlfield.html">TQSqlField</a>&nbsp;&amp;&nbsp;other )
</h3>
Constructs a copy of <em>other</em>.
<h3 class=fn><a name="~TQSqlField"></a>TQSqlField::~TQSqlField ()<tt> [virtual]</tt>
</h3>
Destroys the object and frees any allocated resources.
<h3 class=fn>void <a name="clear"></a>TQSqlField::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>TQSqlField::isNull () const
</h3>
<p> Returns TRUE if the field is currently NULL; otherwise returns
FALSE.
<h3 class=fn>bool <a name="isReadOnly"></a>TQSqlField::isReadOnly () const
</h3>
<p> Returns TRUE if the field's value is read only; otherwise returns
FALSE.
<h3 class=fn><a href="ntqstring.html">TQString</a> <a name="name"></a>TQSqlField::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="ntqsqlfield.html">TQSqlField</a>&nbsp;&amp; <a name="operator-eq"></a>TQSqlField::operator= ( const&nbsp;<a href="ntqsqlfield.html">TQSqlField</a>&nbsp;&amp;&nbsp;other )
</h3>
Sets the field equal to <em>other</em>.
<h3 class=fn>bool <a name="operator-eq-eq"></a>TQSqlField::operator== ( const&nbsp;<a href="ntqsqlfield.html">TQSqlField</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>TQSqlField::setName ( const&nbsp;<a href="ntqstring.html">TQString</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>TQSqlField::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>TQSqlField::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>TQSqlField::setValue ( const&nbsp;<a href="ntqvariant.html">TQVariant</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="ntqstring.html">TQString</a> to an
integer data type. For example:
<p> <pre>
<a href="ntqsqlcursor.html">TQSqlCursor</a> cur( "Employee" ); // 'Employee' table
TQSqlField* f = cur.<a href="ntqsqlrecord.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="ntqvariant.html#Type-enum">TQVariant::Type</a> <a name="type"></a>TQSqlField::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="ntqvariant.html">TQVariant</a> <a name="value"></a>TQSqlField::value () const<tt> [virtual]</tt>
</h3>
<p> Returns the value of the field as a <a href="ntqvariant.html">TQVariant</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">TQt 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>TQt 3.3.8</div>
</table></div></address></body>
</html>