• PySide 模块
  • PySide.QtSql
  • 内容表

    上一话题

    QSqlIndex

    下一话题

    QSqlError

    QSqlField

    概要

    函数

    详细描述

    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())  # WRONG
    										

    However, 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 int
    										

    PySide.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() .

    class PySide.QtSql. QSqlField ( other )
    class PySide.QtSql. QSqlField ( [ fieldName="" [ , type=QVariant.Invalid ] ] )
    参数:

    构造副本为 other .

    PySide.QtSql.QSqlField. RequiredStatus

    Specifies whether the field is required or optional.

    常量 描述
    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.
    PySide.QtSql.QSqlField. clear ( )

    Clears the value of the field and sets it to NULL. If the field is read-only, nothing happens.

    PySide.QtSql.QSqlField. defaultValue ( )
    返回类型: object

    Returns the field's default value (which may be NULL).

    PySide.QtSql.QSqlField. isAutoValue ( )
    返回类型: PySide.QtCore.bool

    Returns true if the value is auto-generated by the database, for example auto-increment primary key values.

    PySide.QtSql.QSqlField. isGenerated ( )
    返回类型: PySide.QtCore.bool

    Returns true if the field is generated; otherwise returns false.

    PySide.QtSql.QSqlField. isNull ( )
    返回类型: PySide.QtCore.bool

    Returns true if the field's value is NULL; otherwise returns false.

    PySide.QtSql.QSqlField. isReadOnly ( )
    返回类型: PySide.QtCore.bool

    Returns true if the field's value is read-only; otherwise returns false.

    PySide.QtSql.QSqlField. isValid ( )
    返回类型: PySide.QtCore.bool

    Returns true if the field's variant type is valid; otherwise returns false.

    PySide.QtSql.QSqlField. length ( )
    返回类型: 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.

    PySide.QtSql.QSqlField. name ( )
    返回类型: unicode

    Returns the name of the field.

    PySide.QtSql.QSqlField. __ne__ ( other )
    参数: other PySide.QtSql.QSqlField
    返回类型: PySide.QtCore.bool

    Returns true if the field is unequal to other ;否则返回 false。

    PySide.QtSql.QSqlField. __eq__ ( other )
    参数: other PySide.QtSql.QSqlField
    返回类型: PySide.QtCore.bool

    Returns true if the field is equal to other ;否则返回 false。

    PySide.QtSql.QSqlField. precision ( )
    返回类型: 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.

    PySide.QtSql.QSqlField. requiredStatus ( )
    返回类型: 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.

    PySide.QtSql.QSqlField. setAutoValue ( autoVal )
    参数: autoVal PySide.QtCore.bool

    Marks the field as an auto-generated value if autoVal 为 true。

    PySide.QtSql.QSqlField. setDefaultValue ( value )
    参数: value – object

    Sets the default value used for this field to value .

    PySide.QtSql.QSqlField. setGenerated ( gen )
    参数: 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.

    PySide.QtSql.QSqlField. setLength ( fieldLength )
    参数: 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.

    PySide.QtSql.QSqlField. setName ( name )
    参数: name – unicode

    Sets the name of the field to name .

    PySide.QtSql.QSqlField. setPrecision ( precision )
    参数: precision PySide.QtCore.int

    Sets the field's precision . This only affects numeric fields.

    PySide.QtSql.QSqlField. setReadOnly ( readOnly )
    参数: 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() .

    PySide.QtSql.QSqlField. setRequired ( required )
    参数: required PySide.QtCore.bool

    Sets the required status of this field to Required if required is true; otherwise sets it to 可选 .

    PySide.QtSql.QSqlField. setRequiredStatus ( status )
    参数: status PySide.QtSql.QSqlField.RequiredStatus

    Sets the required status of this field to required .

    PySide.QtSql.QSqlField. setSqlType ( type )
    参数: type PySide.QtCore.int
    PySide.QtSql.QSqlField. setType ( type )
    参数: type PySide.QtCore.QVariant::Type
    PySide.QtSql.QSqlField. setValue ( value )
    参数: 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() .

    PySide.QtSql.QSqlField. 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.

    PySide.QtSql.QSqlField. typeID ( )
    返回类型: 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.

    PySide.QtSql.QSqlField. value ( )
    返回类型: object

    Returns the value of the field as a PySide.QtCore.QVariant .

    使用 PySide.QtSql.QSqlField.isNull() to check if the field's value is NULL.