![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QSqlField class manipulates the fields in SQL database tables and views. More...
#include <qsqlfield.h>
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 f( "myfield", QVariant::Int ); f.setValue( QPixmap() ); // will not work
However, the field will attempt to cast certain data types to the field data type where possible:
QSqlField f( "myfield", QVariant::Int ); f.setValue( QString("123") ); // casts QString to int
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:
QSqlCursor cur( "Employee" ); // create cursor using the 'Employee' table QSqlField* f = cur.field( "name" ); // use the 'name' field f->setValue( "Dave" ); // set field value ...
In practice we rarely need to extract a pointer to a field at all. The previous example would normally be written:
QSqlCursor cur( "Employee" ); cur.setValue( "name", "Dave" ); ...
Returns TRUE if the field is currently null, otherwise returns FALSE.
Returns TRUE if the field's value is read only, otherwise FALSE.
Returns the name of the field.
Examples: sql/overview/subclass3/main.cpp, sql/overview/subclass4/main.cpp and sql/overview/table4/main.cpp.
Sets the name of the field to name.
Sets the null flag of the field to n. If the field is read-only, nothing happens. If n is TRUE, the field is also cleared with clear().
See also isReadOnly().
Sets the read only flag of the field's value to readOnly.
See also setValue().
QSqlCursor cur( "Employee" ); // 'Employee' table QSqlField* f = cur.field( "student_count" ); // an integer field ... f->setValue( myLineEdit->text() ); // cast the line edit text to an integer
See also isReadOnly().
Returns the field's type.
Returns the internal value of the field as a QVariant.
Example: sql/overview/table4/main.cpp.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks | Qt version 3.0.0-beta1-beta1
|