PySide6.QtSql.QSqlField¶
- class QSqlField¶
- The - QSqlFieldclass manipulates the fields in SQL database tables and views.- Details- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - QSqlFieldrepresents 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", QMetaType.fromType()) field.setValue(QPixmap()) # WRONG - However, the field will attempt to cast certain data types to the field data type where possible: - field = QSqlField("age", QMetaType.fromType()) field.setValue(QString("123")) # casts QString to int - QSqlFieldobjects are rarely created explicitly in application code. They are usually accessed indirectly through- QSqlRecords that already contain a list of fields. For example:- query = QSqlQuery() ... record = query.record() field = record.field("country") - A - QSqlFieldobject 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 - Synopsis¶- Properties¶- Methods¶- def - __init__()
- def - clear()
- def - defaultValue()
- def - isAutoValue()
- def - isGenerated()
- def - isNull()
- def - isReadOnly()
- def - isValid()
- def - length()
- def - metaType()
- def - name()
- def - __ne__()
- def - __eq__()
- def - precision()
- def - requiredStatus()
- def - setAutoValue()
- def - setGenerated()
- def - setLength()
- def - setMetaType()
- def - setName()
- def - setPrecision()
- def - setReadOnly()
- def - setRequired()
- def - setSqlType()
- def - setTableName()
- def - setValue()
- def - swap()
- def - tableName()
- def - typeID()
- def - value()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - class RequiredStatus¶
- Specifies whether the field is required or optional. - Constant - Description - QSqlField.RequiredStatus.Required - The field must be specified when inserting records. - QSqlField.RequiredStatus.Optional - The fields doesn’t have to be specified when inserting records. - QSqlField.RequiredStatus.Unknown - The database driver couldn’t determine whether the field is required or optional. - See also 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property autoValueᅟ: bool¶
 - If the value is auto-generated by the database, for example auto-increment primary key values, this value is - true.- Note - When using the ODBC driver, due to limitations in the ODBC API, the - isAutoValue()field is only populated in a- QSqlFieldresulting from a- QSqlRecordobtained by executing a- SELECTquery. It is- falsein a- QSqlFieldresulting from a- QSqlRecordreturned from- record()or- primaryIndex().- Access functions:
 - property defaultValueᅟ: object¶
 - This property holds the default value for this field. Only some database drivers supports this property. Currently those are SQLite, PostgreSQL, Oracle and MySQL/MariaDB. - Access functions:
 - property generatedᅟ: bool¶
 - This property holds the generated state. If - generatedis- false, no SQL will be generated for this field; otherwise, Qt classes such as- QSqlQueryModeland- QSqlTableModelwill generate SQL for this field.- Access functions:
 - property lengthᅟ: int¶
 - This property holds the field’s length. - If the value is negative, it means that the information is not available from the database. For strings this is the maximum number of characters the string can hold; the meaning varies for other types. - Access functions:
 - This property holds 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 - Access functions:
 - property nameᅟ: str¶
 - This property holds the name of the field. This can be the column name or a user given alias. - property precisionᅟ: int¶
 - This property holds 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. - Access functions:
 - property readOnlyᅟ: bool¶
 - When this property is - truethen this- QSqlFieldcannot be modified. A read-only field cannot have its value set with- setValue()and cannot be cleared to NULL with- clear().- Access functions:
 - property requiredStatusᅟ: QSqlField.RequiredStatus¶
 - This property holds the - RequiredStatusof the field. An- INSERTwill fail if a required field does not have a value.- See also - Access functions:
 - property tableNameᅟ: str¶
 - This property holds the - tableNameof the field.- Note - When using the QPSQL driver, due to limitations in the libpq library, the - tableName()field is not populated in a- QSqlFieldresulting from a- QSqlRecordobtained by- record()of a forward-only query.- Access functions:
 - property valueᅟ: object¶
 - This property holds the - valueas a QVariant- Setting a - valueto a read-only- QSqlFieldis a no-op. If the data type of- valuediffers 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.- To set the value to NULL, use - clear().- Access functions:
 - Constructs a copy of - other.- __init__([fieldName=""[, type=QMetaType()[, tableName=""]]])
- Parameters:
- fieldName – str 
- type – - QMetaType
- tableName – str 
 
 
 - Constructs an empty field called - fieldNameof type- typein- table.- clear()¶
 - Clears the value of the field and sets it to NULL. If the field is read-only, nothing happens. - defaultValue()¶
- Return type:
- object 
 
 - Sets the value of defaultValue. - See also - Getter of property - defaultValueᅟ.- isAutoValue()¶
- Return type:
- bool 
 
 - Returns the value of - autoValue.- Getter of property - autoValueᅟ.- isGenerated()¶
- Return type:
- bool 
 
 - Returns the value of - generated.- Getter of property - generatedᅟ.- isNull()¶
- Return type:
- bool 
 
 - Returns - trueif the field’s value is NULL; otherwise returns false.- See also - isReadOnly()¶
- Return type:
- bool 
 
 - Returns the value of - readOnly.- Getter of property - readOnlyᅟ.- isValid()¶
- Return type:
- bool 
 
 - Returns - trueif the field’s variant type is valid; otherwise returns- false.- length()¶
- Return type:
- int 
 
 - Returns the value of length. - See also - Getter of property - lengthᅟ.- Returns the value of metaType. - See also - Getter of property - metaTypeᅟ.- name()¶
- Return type:
- str 
 
 - Returns the value of name. - See also - Getter of property - nameᅟ.- Returns - trueif the field is unequal to- other; otherwise returns false.- Returns - trueif the field is equal to- other; otherwise returns false.- precision()¶
- Return type:
- int 
 
 - Returns the value of precision. - See also - Getter of property - precisionᅟ.- requiredStatus()¶
- Return type:
 
 - Returns the value of requiredStatus. - See also - Getter of property - requiredStatusᅟ.- setAutoValue(autoVal)¶
- Parameters:
- autoVal – bool 
 
 - Sets - autoValueto- autoVal.- See also - Setter of property - autoValueᅟ.- setDefaultValue(value)¶
- Parameters:
- value – object 
 
 - Sets - defaultValueto- value.- See also - Setter of property - defaultValueᅟ.- setGenerated(gen)¶
- Parameters:
- gen – bool 
 
 - Sets - generatedto- gen.- See also - Setter of property - generatedᅟ.- setLength(fieldLength)¶
- Parameters:
- fieldLength – int 
 
 - Sets - lengthto- fieldLength.- See also - Setter of property - lengthᅟ.- Sets - metaTypeto- type.- See also - Setter of property - metaTypeᅟ.- setName(name)¶
- Parameters:
- name – str 
 
 - Sets - nameto- name.- See also - Setter of property - nameᅟ.- setPrecision(precision)¶
- Parameters:
- precision – int 
 
 - Sets - precisionto- precision.- See also - Setter of property - precisionᅟ.- setReadOnly(readOnly)¶
- Parameters:
- readOnly – bool 
 
 - Sets - readOnlyto- readOnly.- See also - Setter of property - readOnlyᅟ.- setRequired(required)¶
- Parameters:
- required – bool 
 
 - Sets the required status of this field to - Requiredif- requiredis true; otherwise sets it to- Optional.- See also - setRequiredStatus(status)¶
- Parameters:
- status – - RequiredStatus
 
 - Sets - requiredStatusto- required.- See also - Setter of property - requiredStatusᅟ.- setSqlType(type)¶
- Parameters:
- type – int 
 - Note - This function is deprecated. 
 - This internal value is no longer used. - setTableName(tableName)¶
- Parameters:
- tableName – str 
 
 - Sets - tableNameto- tableName.- See also - Setter of property - tableNameᅟ.- setValue(value)¶
- Parameters:
- value – object 
 
 - Sets - valueto- value.- See also - Setter of property - valueᅟ.- Swaps this field with - other. This operation is very fast and never fails.- tableName()¶
- Return type:
- str 
 
 - Returns the tableName. - See also - Getter of property - tableNameᅟ.- typeID()¶
- Return type:
- int 
 - Note - This function is deprecated. 
 - This internal value is no longer used. - Returns the type ID for the field. - If the returned value is negative, it means that the information is not available from the database. - value()¶
- Return type:
- object 
 
 - Returns the value of value. - See also - Getter of property - valueᅟ.