Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QSqlField class manipulates the fields in SQL database tables and views. More...
#include <QSqlField>
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 QCoreVariants. Using an incompatible type is not permitted. For example:
QSqlField field("myfield", QCoreVariant::Int); field.setValue(QPixmap()); // will not work
However, the field will attempt to cast certain data types to the field data type where possible:
QSqlField field("myfield", QCoreVariant::Int); field.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 a cursor for the 'EMPLOYEE' table QSqlField *field = cur.field("NAME"); // use the 'NAME' field field->setValue("Dave"); // set the field's 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"); ...
A QSqlField object can provide some meta-data about the field, for example, its name(), variant type(), length(), precision(), defaultValue(), typeID(), and whether it isRequired(), isAutoGenerated() 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().
Used to specify the auto-generated state and the required state.
QSqlField::Unknown | |
QSqlField::No | |
QSqlField::Yes |
Constructs an empty field called fieldName of variant type type.
See also setRequired(), setLength(), setPrecision(), setDefaultValue(), setAutoGenerated(), and setReadOnly().
Constructs a copy of other.
Destroys the object and frees any allocated resources.
Clears the value of the field and sets it to NULL. If the field is read-only, nothing happens.
See also setValue(), isReadOnly(), and isRequired().
Returns the field's default value (which may be NULL).
See also setDefaultValue(), type(), isRequired(), length(), precision(), and isAutoGenerated().
Returns true if the field is auto-generated; otherwise returns false.
See also setAutoGenerated(), type(), isRequired(), length(), precision(), and defaultValue().
Returns true if the field's value is NULL; otherwise returns false.
See also value().
Returns true if the field's value is read-only; otherwise returns false.
See also setReadOnly(), type(), isRequired(), length(), precision(), defaultValue(), and isAutoGenerated().
Returns true if this is a required field; otherwise returns false. An INSERT will fail if a required field does not have a value.
See also setRequired(), type(), length(), precision(), defaultValue(), and isAutoGenerated().
Returns true if the field's variant type is valid; otherwise returns false.
Returns the field's length.
See also setLength(), type(), isRequired(), precision(), defaultValue(), and isAutoGenerated().
Returns the name of the field.
See also setName().
Returns the field's precision; this is only meaningful for numeric types.
See also setPrecision(), type(), isRequired(), length(), defaultValue(), and isAutoGenerated().
Sets the auto-generated state. If autogen is Yes then SQL for this field will be generated for SQL queries; otherwise no SQL will be generated for this field.
See also isAutoGenerated(), setType(), setRequired(), setLength(), setPrecision(), setDefaultValue(), and setReadOnly().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
If autogen is true the auto-generated state is set to Yes; otherwise it is set to No.
Sets the default value used for this field to value.
See also defaultValue(), value(), setType(), setRequired(), setLength(), setPrecision(), setAutoGenerated(), and setReadOnly().
Sets the field's length to fieldLength. For strings this is the maximum number of characters the string can hold; the meaning varies for other types.
See also length(), setType(), setRequired(), setPrecision(), setDefaultValue(), setAutoGenerated(), and setReadOnly().
Sets the name of the field to name.
See also name().
Sets the field's precision. This only affects numeric fields.
See also precision(), setType(), setRequired(), setLength(), setDefaultValue(), setAutoGenerated(), and setReadOnly().
Sets the read only flag of the field's value to readOnly. A read-only field cannot have its value set with setValue() and cannot be cleared to NULL with clear().
If required is Yes, this is a required field that must be given a non-NULL value; otherwise the field can have any value, including NULL.
See also isRequired(), setType(), setLength(), setPrecision(), setDefaultValue(), setAutoGenerated(), and setReadOnly().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
If required is true the required state is set to Yes; otherwise it is set to No.
Set's the field's variant type to type.
See also type(), setRequired(), setLength(), setPrecision(), setDefaultValue(), setAutoGenerated(), and setReadOnly().
Sets the value of the field to value. If the field is read-only (isReadOnly() returns true), nothing happens. If the data type of value 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 QString to an integer data type. For example:
QSqlCursor cur("EMPLOYEE"); // 'EMPLOYEE' table QSqlField *field = cur.field("STUDENT_COUNT"); // an integer field ... field->setValue(myLineEdit->text()); // cast the line edit text to an integer
To set the value to NULL use clear().
See also value(), isReadOnly(), and defaultValue().
Returns the field's variant type.
See also setType().
Returns the value of the field as a QCoreVariant.
Use isNull() to check if the field's value is NULL.
Sets the field equal to other.
Returns true if the field is equal to other; otherwise returns false.
Copyright © 2004 Trolltech. | Trademarks | Qt 4.0.0-tp2 |