QSqlRecord#

The QSqlRecord class encapsulates a database record. More

Inheritance diagram of PySide6.QtSql.QSqlRecord

Inherited by: QSqlIndex

Synopsis#

Functions#

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

Detailed Description#

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

See also

QSqlField record()

class PySide6.QtSql.QSqlRecord#

PySide6.QtSql.QSqlRecord(other)

Parameters:

otherPySide6.QtSql.QSqlRecord

Constructs an empty record.

Constructs a copy of other.

QSqlRecord is implicitly shared . This means you can make copies of a record in constant time .

PySide6.QtSql.QSqlRecord.append(field)#
Parameters:

fieldPySide6.QtSql.QSqlField

Append a copy of field field to the end of the record.

PySide6.QtSql.QSqlRecord.clear()#

Removes all the record’s fields.

PySide6.QtSql.QSqlRecord.clearValues()#

Clears the value of all fields in the record and sets each field to null.

See also

setValue()

PySide6.QtSql.QSqlRecord.contains(name)#
Parameters:

name – str

Return type:

bool

Returns true if there is a field in the record called name; otherwise returns false.

PySide6.QtSql.QSqlRecord.count()#
Return type:

int

Returns the number of fields in the record.

See also

isEmpty()

PySide6.QtSql.QSqlRecord.field(name)#
Parameters:

name – str

Return type:

PySide6.QtSql.QSqlField

This is an overloaded function.

Returns the field called name.

PySide6.QtSql.QSqlRecord.field(i)
Parameters:

i – int

Return type:

PySide6.QtSql.QSqlField

Returns the field at position index. If the index is out of range, function returns a default-constructed value .

PySide6.QtSql.QSqlRecord.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()

PySide6.QtSql.QSqlRecord.indexOf(name)#
Parameters:

name – str

Return type:

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.

See also

fieldName()

PySide6.QtSql.QSqlRecord.insert(pos, field)#
Parameters:

Inserts the field field at position pos in the record.

PySide6.QtSql.QSqlRecord.isEmpty()#
Return type:

bool

Returns true if there are no fields in the record; otherwise returns false.

PySide6.QtSql.QSqlRecord.isGenerated(name)#
Parameters:

name – str

Return type:

bool

Returns true if the record has a field called name and this field is to be generated (the default); otherwise returns false.

See also

setGenerated()

PySide6.QtSql.QSqlRecord.isGenerated(i)
Parameters:

i – int

Return type:

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.

See also

setGenerated()

PySide6.QtSql.QSqlRecord.isNull(i)#
Parameters:

i – int

Return type:

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.

PySide6.QtSql.QSqlRecord.isNull(name)
Parameters:

name – str

Return type:

bool

Returns true if the field called name is null or if there is no field called name; otherwise returns false.

See also

setNull()

PySide6.QtSql.QSqlRecord.keyValues(keyFields)#
Parameters:

keyFieldsPySide6.QtSql.QSqlRecord

Return type:

PySide6.QtSql.QSqlRecord

Returns a record containing the fields represented in keyFields set to values that match by field name.

PySide6.QtSql.QSqlRecord.__ne__(other)#
Parameters:

otherPySide6.QtSql.QSqlRecord

Return type:

bool

Returns true if this object is not identical to other; otherwise returns false.

See also

operator==()

PySide6.QtSql.QSqlRecord.__eq__(other)#
Parameters:

otherPySide6.QtSql.QSqlRecord

Return type:

bool

Returns true if this object is identical to other (i.e., has the same fields in the same order); otherwise returns false.

See also

operator!=()

PySide6.QtSql.QSqlRecord.remove(pos)#
Parameters:

pos – int

Removes the field at position pos. If pos is out of range, nothing happens.

PySide6.QtSql.QSqlRecord.replace(pos, field)#
Parameters:

Replaces the field at position pos with the given field. If pos is out of range, nothing happens.

PySide6.QtSql.QSqlRecord.setGenerated(name, generated)#
Parameters:
  • name – str

  • generated – 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.

See also

isGenerated()

PySide6.QtSql.QSqlRecord.setGenerated(i, generated)
Parameters:
  • i – int

  • generated – bool

This is an overloaded function.

Sets the generated flag for the field index to generated.

See also

isGenerated()

PySide6.QtSql.QSqlRecord.setNull(name)#
Parameters:

name – str

This is an overloaded function.

Sets the value of the field called name to null. If the field does not exist, nothing happens.

PySide6.QtSql.QSqlRecord.setNull(i)
Parameters:

i – int

Sets the value of field index to null. If the field does not exist, nothing happens.

See also

isNull() setValue()

PySide6.QtSql.QSqlRecord.setValue(name, val)#
Parameters:
  • name – str

  • val – object

This is an overloaded function.

Sets the value of the field called name to val. If the field does not exist, nothing happens.

PySide6.QtSql.QSqlRecord.setValue(i, val)
Parameters:
  • i – int

  • val – object

Sets the value of the field at position index to val. If the field does not exist, nothing happens.

See also

value() setNull()

PySide6.QtSql.QSqlRecord.value(name)#
Parameters:

name – str

Return type:

object

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.

See also

indexOf()

PySide6.QtSql.QSqlRecord.value(i)
Parameters:

i – int

Return type:

object

Returns the value of the field located at position index in the record. If index is out of bounds, an invalid QVariant is returned.