PySide6.QtSql.QSqlRecord¶
- class QSqlRecord¶
- The - QSqlRecordclass encapsulates a database record.- Details- The - QSqlRecordclass encapsulates the functionality and characteristics of a database record (usually a row in a table or view within the database).- QSqlRecordsupports 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- QSqlFieldobject 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().- Inherited by: - QSqlIndex- Synopsis¶- Methods¶- def - __init__()
- def - append()
- def - clear()
- def - clearValues()
- def - contains()
- def - count()
- def - field()
- def - fieldName()
- def - indexOf()
- def - insert()
- def - isEmpty()
- def - isGenerated()
- def - isNull()
- def - keyValues()
- def - __ne__()
- def - __eq__()
- def - remove()
- def - replace()
- def - setGenerated()
- def - setNull()
- def - setValue()
- def - swap()
- 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 - __init__()¶
 - Constructs an empty record. - __init__(other)
- Parameters:
- other – - QSqlRecord
 
 - Constructs a copy of - other.- QSqlRecordis implicitly shared. This means you can make copies of a record in constant time.- Append a copy of field - fieldto the end of the record.- 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. - See also - contains(name)¶
- Parameters:
- name – str 
- Return type:
- bool 
 
 - Returns - trueif there is a field in the record called- name; otherwise returns- false.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - count()¶
- Return type:
- int 
 
 - Returns the number of fields in the record. - See also - Returns the field called - name. If the field called- nameis not found, function returns a default-constructed value.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - field(i)
- Parameters:
- i – int 
- Return type:
 
 - Returns the field at position - index. If the- indexis out of range, function returns a default-constructed value.- fieldName(i)¶
- Parameters:
- i – int 
- Return type:
- str 
 
 - Returns the name of the field at position - index. If the field does not exist, an empty string is returned.- See also - indexOf(name)¶
- Parameters:
- name – str 
- Return type:
- int 
 
 - Returns the position of the field called - namewithin 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.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - See also - Inserts the field - fieldat position- posin the record.- isEmpty()¶
- Return type:
- bool 
 
 - Returns - trueif there are no fields in the record; otherwise returns- false.- isGenerated(name)¶
- Parameters:
- name – str 
- Return type:
- bool 
 
 - Returns - trueif the record has a field called- nameand this field is to be generated (the default); otherwise returns- false.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - See also - isGenerated(i)
- Parameters:
- i – int 
- Return type:
- bool 
 
 - Returns - trueif the record has a field at position- indexand this field is to be generated (the default); otherwise returns- false.- See also - isNull(name)¶
- Parameters:
- name – str 
- Return type:
- bool 
 
 - Returns - trueif the field called- nameis null or if there is no field called- name; otherwise returns- false.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - See also - isNull(i)
- Parameters:
- i – int 
- Return type:
- bool 
 
 - Returns - trueif the field- indexis null or if there is no field at position- index; otherwise returns- false.- See also - keyValues(keyFields)¶
- Parameters:
- keyFields – - QSqlRecord
- Return type:
 
 - Returns a record containing the fields represented in - keyFieldsset to values that match by field name.- __ne__(other)¶
- Parameters:
- other – - QSqlRecord
- Return type:
- bool 
 
 - Returns - trueif this object is not identical to- other; otherwise returns- false.- See also - operator==()- __eq__(other)¶
- Parameters:
- other – - QSqlRecord
- Return type:
- bool 
 
 - Returns - trueif this object is identical to- other(i.e., has the same fields in the same order); otherwise returns- false.- See also - operator!=()- remove(pos)¶
- Parameters:
- pos – int 
 
 - Removes the field at position - pos. If- posis out of range, nothing happens.- Replaces the field at position - poswith the given- field. If- posis out of range, nothing happens.- setGenerated(name, generated)¶
- Parameters:
- name – str 
- generated – bool 
 
 
 - Sets the generated flag for the field called - nameto- generated. If the field does not exist, nothing happens. Only fields that have- generatedset to true are included in the SQL that is generated by- QSqlQueryModelfor example.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - See also - setGenerated(i, generated)
- Parameters:
- i – int 
- generated – bool 
 
 
 - Sets the generated flag for the field - indexto- generated.- See also - setNull(name)¶
- Parameters:
- name – str 
 
 - Sets the value of the field called - nameto null. If the field does not exist, nothing happens.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - setNull(i)
- Parameters:
- i – int 
 
 - Sets the value of field - indexto null. If the field does not exist, nothing happens.- See also - setValue(name, val)¶
- Parameters:
- name – str 
- val – object 
 
 
 - Sets the value of the field called - nameto- val. If the field does not exist, nothing happens.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - See also - setValue(i, val)
- Parameters:
- i – int 
- val – object 
 
 
 - Sets the value of the field at position - indexto- val. If the field does not exist, nothing happens.- swap(other)¶
- Parameters:
- other – - QSqlRecord
 
 - Swaps this SQL record with - other. This operation is very fast and never fails.- value(name)¶
- Parameters:
- name – str 
- Return type:
- object 
 
 - Returns the value of the field called - namein the record. If field- namedoes not exist an invalid variant is returned.- Note - In Qt versions prior to 6.8, this function took QString, not QAnyStringView. - value(i)
- Parameters:
- i – int 
- Return type:
- object 
 
 - Returns the value of the field located at position - indexin the record. If- indexis out of bounds, an invalid QVariant is returned.- See also