def
__eq__
(other)
def
__ne__
(other)
def
clear
()
def
defaultValue
()
def
isAutoValue
()
def
isGenerated
()
def
isNull
()
def
isReadOnly
()
def
isValid
()
def
length
()
def
name
()
def
precision
()
def
requiredStatus
()
def
setAutoValue
(autoVal)
def
setDefaultValue
(value)
def
setGenerated
(gen)
def
setLength
(fieldLength)
def
setName
(name)
def
setPrecision
(precision)
def
setReadOnly
(readOnly)
def
setRequired
(required)
def
setRequiredStatus
(status)
def
setSqlType
(type)
def
setTableName
(tableName)
def
setType
(type)
def
setValue
(value)
def
tableName
()
def
type
()
def
typeID
()
def
value
()
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", 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(str(123)) # casts str to int
QSqlFieldobjects are rarely created explicitly in application code. They are usually accessed indirectly throughQSqlRecords 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, itsname(), varianttype(),length(),precision(),defaultValue(), , 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().另请参阅
QSqlField
(
other
)
¶
QSqlField([fieldName=””[, type={}]])
QSqlField(fieldName, type, tableName)
- param type
QVariant::Type- param other
- param fieldName
unicode
- param tableName
unicode
构造副本为
other
.
Constructs an empty field called
fieldName
of variant type
type
.
这是重载函数。
Constructs an empty field called
fieldName
of variant type
type
in
table
.
PySide2.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. |
另请参阅
PySide2.QtSql.QSqlField.
clear
(
)
¶
Clears the value of the field and sets it to NULL. If the field is read-only, nothing happens.
PySide2.QtSql.QSqlField.
defaultValue
(
)
¶
object
Returns the field’s default value (which may be NULL).
PySide2.QtSql.QSqlField.
isAutoValue
(
)
¶
bool
返回
true
if the value is auto-generated by the database, for example auto-increment primary key values.
注意
When using the ODBC driver, due to limitations in the ODBC API, the
isAutoValue()
field is only populated in a
QSqlField
resulting from a
QSqlRecord
obtained by executing a
SELECT
query. It is
false
在
QSqlField
resulting from a
QSqlRecord
returned from
record()
or
primaryIndex()
.
另请参阅
PySide2.QtSql.QSqlField.
isGenerated
(
)
¶
bool
返回
true
if the field is generated; otherwise returns false.
PySide2.QtSql.QSqlField.
isNull
(
)
¶
bool
返回
true
if the field’s value is NULL; otherwise returns false.
另请参阅
PySide2.QtSql.QSqlField.
isReadOnly
(
)
¶
bool
返回
true
if the field’s value is read-only; otherwise returns false.
PySide2.QtSql.QSqlField.
isValid
(
)
¶
bool
返回
true
if the field’s variant type is valid; otherwise returns
false
.
PySide2.QtSql.QSqlField.
length
(
)
¶
int
Returns the field’s length.
If the returned value is negative, it means that the information is not available from the database.
PySide2.QtSql.QSqlField.
__ne__
(
other
)
¶
other
–
QSqlField
bool
返回
true
if the field is unequal to
other
;否则返回 false。
PySide2.QtSql.QSqlField.
__eq__
(
other
)
¶
other
–
QSqlField
bool
返回
true
if the field is equal to
other
;否则返回 false。
PySide2.QtSql.QSqlField.
precision
(
)
¶
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.
PySide2.QtSql.QSqlField.
requiredStatus
(
)
¶
返回
true
if this is a required field; otherwise returns
false
. An
INSERT
will fail if a required field does not have a value.
PySide2.QtSql.QSqlField.
setAutoValue
(
autoVal
)
¶
autoVal
–
bool
Marks the field as an auto-generated value if
autoVal
为 true。
另请参阅
PySide2.QtSql.QSqlField.
setDefaultValue
(
value
)
¶
value – object
Sets the default value used for this field to
value
.
PySide2.QtSql.QSqlField.
setGenerated
(
gen
)
¶
gen
–
bool
Sets the generated state. If
gen
is false, no SQL will be generated for this field; otherwise, Qt classes such as
QSqlQueryModel
and
QSqlTableModel
will generate SQL for this field.
PySide2.QtSql.QSqlField.
setLength
(
fieldLength
)
¶
fieldLength
–
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.
PySide2.QtSql.QSqlField.
setName
(
name
)
¶
name – unicode
Sets the name of the field to
name
.
另请参阅
PySide2.QtSql.QSqlField.
setPrecision
(
precision
)
¶
precision
–
int
Sets the field’s
precision
. This only affects numeric fields.
PySide2.QtSql.QSqlField.
setReadOnly
(
readOnly
)
¶
readOnly
–
bool
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()
.
另请参阅
PySide2.QtSql.QSqlField.
setRequired
(
required
)
¶
required
–
bool
Sets the required status of this field to
Required
if
required
is true; otherwise sets it to
可选
.
PySide2.QtSql.QSqlField.
setRequiredStatus
(
status
)
¶
status
–
RequiredStatus
Sets the required status of this field to
required
.
PySide2.QtSql.QSqlField.
setSqlType
(
type
)
¶
type
–
int
PySide2.QtSql.QSqlField.
setTableName
(
tableName
)
¶
tableName – unicode
设置
tableName
of the field to
table
.
另请参阅
PySide2.QtSql.QSqlField.
setType
(
type
)
¶
type
–
QVariant::Type
Set’s the field’s variant type to
type
.
PySide2.QtSql.QSqlField.
setValue
(
value
)
¶
value – object
Sets the value of the field to
value
. If the field is read-only (
isReadOnly()
返回
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.
To set the value to NULL, use
clear()
.
PySide2.QtSql.QSqlField.
tableName
(
)
¶
unicode
Returns the of the field.
注意
When using the QPSQL driver, due to limitations in the libpq library, the
tableName()
field is not populated in a
QSqlField
resulting from a
QSqlRecord
obtained by
record()
of a forward-only query.
另请参阅
PySide2.QtSql.QSqlField.
type
(
)
¶
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.
另请参阅
PySide2.QtSql.QSqlField.
typeID
(
)
¶
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.