QSqlRecord — PyQt Documentation v5.15.7 (original) (raw)
PyQt5.QtSql.QSqlRecord
Inherited by QSqlIndex.
Description¶
The QSqlRecord class encapsulates a database record.
The QSqlRecord class encapsulates the functionality and characteristics of a database record (usually a row in a table or view within the database). QSqlRecord supports adding and removing fields as well as setting and retrieving field values.
The values of a record’s fields can be set by name or position with setValue(); if you want to set a field to null use setNull(). To find the position of a field by name use indexOf(), and to find the name of a field at a particular position use fieldName(). Use field() to retrieve a QSqlField object for a given field. Use contains() to see if the record contains a particular field name.
When queries are generated to be executed on the database only those fields for which isGenerated() is true are included in the generated SQL.
A record can have fields added with append() or insert(), replaced with replace(), and removed with remove(). All the fields can be removed with clear(). The number of fields is given by count(); all their values can be cleared (to null) using clearValues().
Methods¶
__init__()
Constructs an empty record.
See also
isEmpty(), append(), insert().
__init__(QSqlRecord)
Constructs a copy of other.
QSqlRecord is implicitly shared. This means you can make copies of a record in constant time.
append(QSqlField)
Append a copy of field field to the end of the record.
See also
insert(), replace(), remove().
clear()
Removes all the record’s fields.
See also
clearValues()
Clears the value of all fields in the record and sets each field to null.
contains(str) → bool
Returns true
if there is a field in the record called name; otherwise returns false
.
count() → int
Returns the number of fields in the record.
__eq__(QSqlRecord) → bool
TODO
field(int) → QSqlField
Returns the field at position index. If the index is out of range, function returns a default-constructed value.
field(str) → QSqlField
This is an overloaded function.
Returns the field called name.
fieldName(int) → str
Returns the name of the field at position index. If the field does not exist, an empty string is returned.
indexOf(str) → int
Returns the position of the field called name within the record, or -1 if it cannot be found. Field names are not case-sensitive. If more than one field matches, the first one is returned.
insert(int, QSqlField)
Inserts the field field at position pos in the record.
See also
append(), replace(), remove().
isEmpty() → bool
Returns true
if there are no fields in the record; otherwise returns false
.
See also
isGenerated(int) → bool
This is an overloaded function.
Returns true
if the record has a field at position index and this field is to be generated (the default); otherwise returns false
.
isGenerated(str) → bool
Returns true
if the record has a field called name and this field is to be generated (the default); otherwise returns false
.
isNull(int) → bool
This is an overloaded function.
Returns true
if the field index is null or if there is no field at position index; otherwise returns false
.
isNull(str) → bool
Returns true
if the field called name is null or if there is no field called name; otherwise returns false
.
keyValues(QSqlRecord) → QSqlRecord
TODO
__len__() → int
TODO
__ne__(QSqlRecord) → bool
TODO
remove(int)
Removes the field at position pos. If pos is out of range, nothing happens.
See also
append(), insert(), replace().
replace(int, QSqlField)
Replaces the field at position pos with the given field. If pos is out of range, nothing happens.
See also
setGenerated(str, bool)
Sets the generated flag for the field called name to generated. If the field does not exist, nothing happens. Only fields that have generated set to true are included in the SQL that is generated by QSqlQueryModel for example.
setGenerated(int, bool)
This is an overloaded function.
Sets the generated flag for the field index to generated.
setNull(int)
Sets the value of field index to null. If the field does not exist, nothing happens.
See also
setNull(str)
This is an overloaded function.
Sets the value of the field called name to null. If the field does not exist, nothing happens.
setValue(int, Any)
Sets the value of the field at position index to val. If the field does not exist, nothing happens.
See also
setValue(str, Any)
This is an overloaded function.
Sets the value of the field called name to val. If the field does not exist, nothing happens.
value(int) → Any
Returns the value of the field located at position index in the record. If index is out of bounds, an invalid QVariant is returned.
value(str) → Any
This is an overloaded function.
Returns the value of the field called name in the record. If field name does not exist an invalid variant is returned.