Home · Overviews · Examples 

QSqlField Class Reference
[com.trolltech.qt.sql module]

The QSqlField class manipulates the fields in SQL database tables and views. More...


Detailed Description

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

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.

Field data values are stored as QVariants. Using an incompatible type is not permitted. For example:

        QSqlField field("age", QVariant::Int);
        field.setValue(QPixmap());  // WRONG

However, the field will attempt to cast certain data types to the field data type where possible:

        QSqlField field("age", QVariant::Int);
        field.setValue(QString("123"));  // casts QString to int

QSqlField objects are rarely created explicitly in application code. They are usually accessed indirectly through QSqlRecords that already contain a list of fields. For example:

        QSqlQuery query;
        ...
        QSqlRecord record = query.record();
        QSqlField field = record.field("country");

A QSqlField object can provide some meta-data about the field, for example, its name, variant type, length, precision, defaultValue, typeID, and its requiredStatus, isGenerated and isReadOnly. The field's data can be checked to see if it isNull, and its value retrieved. When editing the data can be set with setValue or set to NULL with clear.

See also QSqlRecord.


Copyright © 2008 Trolltech Trademarks
Qt Jambi 4.3.5_01