<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/sql/qsqlfield.cpp:46 --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>QSqlField Class</title> <style type="text/css"><!-- h3.fn,span.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>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 <<a href="qsqlfield-h.html">qsqlfield.h</a>></tt> <p><a href="qsqlfield-members.html">List of all member functions.</a> <h2>Public Members</h2> <ul> <li><div class=fn><a href="#QSqlField"><b>QSqlField</b></a> ( const QString & fieldName = QString::null, QVariant::Type type = QVariant::Invalid )</div></li> <li><div class=fn><a href="#QSqlField-2"><b>QSqlField</b></a> ( const QSqlField & other )</div></li> <li><div class=fn>QSqlField & <a href="#operator-eq"><b>operator=</b></a> ( const QSqlField & other )</div></li> <li><div class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QSqlField & other ) const</div></li> <li><div class=fn>virtual <a href="#~QSqlField"><b>~QSqlField</b></a> ()</div></li> <li><div class=fn>virtual void <a href="#setValue"><b>setValue</b></a> ( const QVariant & value )</div></li> <li><div class=fn>virtual QVariant <a href="#value"><b>value</b></a> () const</div></li> <li><div class=fn>virtual void <a href="#setName"><b>setName</b></a> ( const QString & name )</div></li> <li><div class=fn>QString <a href="#name"><b>name</b></a> () const</div></li> <li><div class=fn>virtual void <a href="#setNull"><b>setNull</b></a> ()</div></li> <li><div class=fn>bool <a href="#isNull"><b>isNull</b></a> () const</div></li> <li><div class=fn>virtual void <a href="#setReadOnly"><b>setReadOnly</b></a> ( bool readOnly )</div></li> <li><div class=fn>bool <a href="#isReadOnly"><b>isReadOnly</b></a> () const</div></li> <li><div class=fn>void <a href="#clear"><b>clear</b></a> ( bool nullify = TRUE )</div></li> <li><div class=fn>QVariant::Type <a href="#type"><b>type</b></a> () const</div></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-><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> <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 <a href="qstring.html">QString</a> & fieldName = QString::null, <a href="qvariant.html#Type-enum">QVariant::Type</a> type = QVariant::Invalid ) </h3> Constructs an empty field called <em>fieldName</em> of type <em>type</em>. <p> <h3 class=fn><a name="QSqlField-2"></a>QSqlField::QSqlField ( const <a href="qsqlfield.html">QSqlField</a> & 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. <p> <h3 class=fn>void <a name="clear"></a>QSqlField::clear ( bool 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 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#x2363">sql/overview/table4/main.cpp</a>. <h3 class=fn><a href="qsqlfield.html">QSqlField</a> & <a name="operator-eq"></a>QSqlField::operator= ( const <a href="qsqlfield.html">QSqlField</a> & other ) </h3> Sets the field equal to <em>other</em>. <h3 class=fn>bool <a name="operator-eq-eq"></a>QSqlField::operator== ( const <a href="qsqlfield.html">QSqlField</a> & 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 <a href="qstring.html">QString</a> & 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 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 <a href="qvariant.html">QVariant</a> & 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-><a href="#setValue">setValue</a>( myLineEdit->text() ); // cast the line edit text to an integer </pre> <p> <p>See also <a href="#isReadOnly">isReadOnly</a>(). <p> <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. <h3 class=fn><a href="qvariant.html">QVariant</a> <a name="value"></a>QSqlField::value () const<tt> [virtual]</tt> </h3> <p> Returns the internal value of the field as a <a href="qvariant.html">QVariant</a>. <p> <p>Example: <a href="sql.html#x2364">sql/overview/table4/main.cpp</a>. <!-- eof --> <hr><p> This file is part of the <a href="index.html">Qt toolkit</a>. Copyright © 1995-2001 <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 © 2001 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a> <td align=right><div align=right>Qt version 3.0.2</div> </table></div></address></body> </html>