
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQSqlField class manipulates the fields in SQL database tables and views.More...
| Header: | #include <QSqlField> |
| enum | RequiredStatus { Required, Optional, Unknown } |
| QSqlField(const QString & fieldName = QString(), QVariant::Type type = QVariant::Invalid) | |
| QSqlField(const QSqlField & other) | |
| ~QSqlField() | |
| void | clear() |
| QVariant | defaultValue() const |
| bool | isAutoValue() const |
| bool | isGenerated() const |
| bool | isNull() const |
| bool | isReadOnly() const |
| bool | isValid() const |
| int | length() const |
| QString | name() const |
| int | precision() const |
| RequiredStatus | requiredStatus() const |
| void | setAutoValue(bool autoVal) |
| void | setDefaultValue(const QVariant & value) |
| void | setGenerated(bool gen) |
| void | setLength(int fieldLength) |
| void | setName(const QString & name) |
| void | setPrecision(int precision) |
| void | setReadOnly(bool readOnly) |
| void | setRequired(bool required) |
| void | setRequiredStatus(RequiredStatus required) |
| void | setType(QVariant::Type type) |
| void | setValue(const QVariant & value) |
| QVariant::Type | type() const |
| QVariant | value() const |
| bool | operator!=(const QSqlField & other) const |
| QSqlField & | operator=(const QSqlField & other) |
| bool | operator==(const QSqlField & other) const |
TheQSqlField 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 asQVariants. Using an incompatible type is not permitted. For example:
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 throughQSqlRecords that already contain a list of fields. For example:
QSqlQuery query; ...QSqlRecord record= query.record();QSqlField field= record.field("country");
AQSqlField object can provide some meta-data about the field, for example, itsname(), varianttype(),length(),precision(),defaultValue(), typeID(), and itsrequiredStatus(),isGenerated() andisReadOnly(). The field's data can be checked to see if itisNull(), and itsvalue() retrieved. When editing the data can be set withsetValue() or set to NULL withclear().
See alsoQSqlRecord.
Specifies whether the field is required or optional.
| Constant | Value | Description |
|---|---|---|
QSqlField::Required | 1 | The field must be specified when inserting records. |
QSqlField::Optional | 0 | The fields doesn't have to be specified when inserting records. |
QSqlField::Unknown | -1 | The database driver couldn't determine whether the field is required or optional. |
See alsorequiredStatus().
Constructs an empty field calledfieldName of variant typetype.
See alsosetRequiredStatus(),setLength(),setPrecision(),setDefaultValue(),setGenerated(), andsetReadOnly().
Constructs a copy ofother.
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 alsosetValue(),isReadOnly(), andrequiredStatus().
Returns the field's default value (which may be NULL).
See alsosetDefaultValue(),type(),requiredStatus(),length(),precision(), andisGenerated().
Returns true if the value is auto-generated by the database, for example auto-increment primary key values.
See alsosetAutoValue().
Returns true if the field is generated; otherwise returns false.
See alsosetGenerated(),type(),requiredStatus(),length(),precision(), anddefaultValue().
Returns true if the field's value is NULL; otherwise returns false.
See alsovalue().
Returns true if the field's value is read-only; otherwise returns false.
See alsosetReadOnly(),type(),requiredStatus(),length(),precision(),defaultValue(), andisGenerated().
Returns true if the field's variant type is valid; otherwise returns false.
Returns the field's length.
If the returned value is negative, it means that the information is not available from the database.
See alsosetLength(),type(),requiredStatus(),precision(),defaultValue(), andisGenerated().
Returns the name of the field.
See alsosetName().
Returns the field's precision; this is only meaningful for numeric types.
If the returned value is negative, it means that the information is not available from the database.
See alsosetPrecision(),type(),requiredStatus(),length(),defaultValue(), andisGenerated().
Returns true if this is a required field; otherwise returns false. AnINSERT will fail if a required field does not have a value.
See alsosetRequiredStatus(),type(),length(),precision(),defaultValue(), andisGenerated().
Marks the field as an auto-generated value ifautoVal is true.
See alsoisAutoValue().
Sets the default value used for this field tovalue.
See alsodefaultValue(),value(),setType(),setRequiredStatus(),setLength(),setPrecision(),setGenerated(), andsetReadOnly().
Sets the generated state. Ifgen is false, no SQL will be generated for this field; otherwise, Qt classes such asQSqlQueryModel andQSqlTableModel will generate SQL for this field.
See alsoisGenerated(),setType(),setRequiredStatus(),setLength(),setPrecision(),setDefaultValue(), andsetReadOnly().
Sets the field's length tofieldLength. For strings this is the maximum number of characters the string can hold; the meaning varies for other types.
See alsolength(),setType(),setRequiredStatus(),setPrecision(),setDefaultValue(),setGenerated(), andsetReadOnly().
Sets the name of the field toname.
See alsoname().
Sets the field'sprecision. This only affects numeric fields.
See alsoprecision(),setType(),setRequiredStatus(),setLength(),setDefaultValue(),setGenerated(), andsetReadOnly().
Sets the read only flag of the field's value toreadOnly. A read-only field cannot have its value set withsetValue() and cannot be cleared to NULL withclear().
See alsoisReadOnly().
Sets the required status of this field toRequired ifrequired is true; otherwise sets it toOptional.
See alsosetRequiredStatus() andrequiredStatus().
Sets the required status of this field torequired.
See alsorequiredStatus(),setType(),setLength(),setPrecision(),setDefaultValue(),setGenerated(), andsetReadOnly().
Set's the field's variant type totype.
See alsotype(),setRequiredStatus(),setLength(),setPrecision(),setDefaultValue(),setGenerated(), andsetReadOnly().
Sets the value of the field tovalue. If the field is read-only (isReadOnly() returns true), nothing happens.
If the data type ofvalue 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. aQString to an integer data type.
To set the value to NULL, useclear().
See alsovalue(),isReadOnly(), anddefaultValue().
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.
See alsosetType().
Returns the value of the field as aQVariant.
UseisNull() to check if the field's value is NULL.
See alsosetValue().
Returns true if the field is unequal toother; otherwise returns false.
Sets the field equal toother.
Returns true if the field is equal toother; otherwise returns false.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.