The QSqlField class manipulates the fields in SQL database tables and views.
.PP
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.
.PP
Field data values are stored as QVariants. Using an incompatible type is not permitted. For example:
.PP
.nf
.br
QSqlField f( "myfield", QVariant::Int );
.br
f.setValue( QPixmap() ); // will not work
.br
.fi
.PP
However, the field will attempt to cast certain data types to the field data type where possible:
QSqlField objects are rarely created explicitly in application code. They are usually accessed indirectly through QSqlRecord or QSqlCursor which already contain a list of fields. For example:
.PP
.nf
.br
QSqlCursor cur( "Employee" ); // create cursor using the 'Employee' table
.br
QSqlField* f = cur.field( "name" ); // use the 'name' field
.br
f->setValue( "Dave" ); // set field value
.br
...
.br
.fi
.PP
In practice we rarely need to extract a pointer to a field at all. The previous example would normally be written:
.SH "QSqlField & QSqlField::operator= ( const QSqlField & other )"
Sets the field equal to \fIother\fR.
.SH "bool QSqlField::operator== ( const QSqlField & other ) const"
Returns TRUE if the field is equal to \fIother\fR; otherwise returns FALSE. Fields are considered equal when the following field properties are the same:
Sets the value of the field to \fIvalue\fR. If the field is read-only (isReadOnly() returns TRUE), nothing happens. If the data type of \fIvalue\fR 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 TQString to an integer data type. For example:
QSqlField* f = cur.field( "student_count" ); // an integer field
.br
...
.br
f->setValue( myLineEdit->text() ); // cast the line edit text to an integer
.br
.fi
.PP
See also isReadOnly().
.SH "QVariant::Type QSqlField::type () const"
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.