The PySide.QtSql.QSqlField class manipulates the fields in SQL database tables and views.
PySide.QtSql.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:
field = QSqlField("age", QVariant.Int) field.setValue(QPixmap()) # WRONGHowever, the field will attempt to cast certain data types to the field data type where possible:
field = QSqlField("age", QVariant.Int) field.setValue(QString("123")) # casts QString to intPySide.QtSql.QSqlField objects are rarely created explicitly in application code. They are usually accessed indirectly through PySide.QtSql.QSqlRecord s that already contain a list of fields. For example:
query = QSqlQuery() ... record = query.record() field = record.field("country")A PySide.QtSql.QSqlField object can provide some meta-data about the field, for example, its PySide.QtSql.QSqlField.name() , variant PySide.QtSql.QSqlField.type() , PySide.QtSql.QSqlField.length() , PySide.QtSql.QSqlField.precision() , PySide.QtSql.QSqlField.defaultValue() , PySide.QtSql.QSqlField.typeID() , and its PySide.QtSql.QSqlField.requiredStatus() , PySide.QtSql.QSqlField.isGenerated() and PySide.QtSql.QSqlField.isReadOnly() . The field’s data can be checked to see if it PySide.QtSql.QSqlField.isNull() , and its PySide.QtSql.QSqlField.value() retrieved. When editing the data can be set with PySide.QtSql.QSqlField.setValue() or set to NULL with PySide.QtSql.QSqlField.clear() .
See also
Parameters: |
|
---|
Constructs a copy of other .
Specifies whether the field is required or optional.
Constant | Description |
---|---|
QSqlField.Required | The field must be specified when inserting records. |
QSqlField.Optional | The fields doesn’t have to be specified when inserting records. |
QSqlField.Unknown | The database driver couldn’t determine whether the field is required or optional. |
Clears the value of the field and sets it to NULL. If the field is read-only, nothing happens.
Return type: | object |
---|
Returns the field’s default value (which may be NULL).
Return type: | PySide.QtCore.bool |
---|
Returns true if the value is auto-generated by the database, for example auto-increment primary key values.
Return type: | PySide.QtCore.bool |
---|
Returns true if the field is generated; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if the field’s value is NULL; otherwise returns false.
See also
Return type: | PySide.QtCore.bool |
---|
Returns true if the field’s value is read-only; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if the field’s variant type is valid; otherwise returns false.
Return type: | PySide.QtCore.int |
---|
Returns the field’s length.
If the returned value is negative, it means that the information is not available from the database.
Return type: | unicode |
---|
Returns the name of the field.
See also
Parameters: | other – PySide.QtSql.QSqlField |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if the field is unequal to other ; otherwise returns false.
Parameters: | other – PySide.QtSql.QSqlField |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if the field is equal to other ; otherwise returns false.
Return type: | PySide.QtCore.int |
---|
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.
Return type: | PySide.QtSql.QSqlField.RequiredStatus |
---|
Returns true if this is a required field; otherwise returns false. An INSERT will fail if a required field does not have a value.
Parameters: | autoVal – PySide.QtCore.bool |
---|
Marks the field as an auto-generated value if autoVal is true.
See also
Parameters: | value – object |
---|
Sets the default value used for this field to value .
See also
PySide.QtSql.QSqlField.defaultValue() PySide.QtSql.QSqlField.value() PySide.QtSql.QSqlField.setType() PySide.QtSql.QSqlField.setRequiredStatus() PySide.QtSql.QSqlField.setLength() PySide.QtSql.QSqlField.setPrecision() PySide.QtSql.QSqlField.setGenerated() PySide.QtSql.QSqlField.setReadOnly()
Parameters: | gen – PySide.QtCore.bool |
---|
Sets the generated state. If gen is false, no SQL will be generated for this field; otherwise, Qt classes such as PySide.QtSql.QSqlQueryModel and PySide.QtSql.QSqlTableModel will generate SQL for this field.
Parameters: | fieldLength – PySide.QtCore.int |
---|
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.
Parameters: | name – unicode |
---|
Sets the name of the field to name .
See also
Parameters: | precision – PySide.QtCore.int |
---|
Sets the field’s precision . This only affects numeric fields.
Parameters: | readOnly – PySide.QtCore.bool |
---|
Sets the read only flag of the field’s value to readOnly . A read-only field cannot have its value set with PySide.QtSql.QSqlField.setValue() and cannot be cleared to NULL with PySide.QtSql.QSqlField.clear() .
See also
Parameters: | required – PySide.QtCore.bool |
---|
Sets the required status of this field to Required if required is true; otherwise sets it to Optional .
Parameters: | status – PySide.QtSql.QSqlField.RequiredStatus |
---|
Sets the required status of this field to required .
Parameters: | type – PySide.QtCore.int |
---|
Parameters: | type – PySide.QtCore.QVariant::Type |
---|
Parameters: | value – object |
---|
Sets the value of the field to value . If the field is read-only ( PySide.QtSql.QSqlField.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 PySide.QtCore.QString to an integer data type.
To set the value to NULL, use PySide.QtSql.QSqlField.clear() .
Return type: | PySide.QtCore.QVariant::Type |
---|
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 also
Return type: | PySide.QtCore.int |
---|
Returns the type ID for the field.
If the returned value is negative, it means that the information is not available from the database.
Return type: | object |
---|
Returns the value of the field as a PySide.QtCore.QVariant .
Use PySide.QtSql.QSqlField.isNull() to check if the field’s value is NULL.
See also