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 usesetNull(). To find the position of a field by name useindexOf(), and to find the name of a field at a particular position usefieldName(). Usefield()to retrieve aQSqlFieldobject for a given field. Usecontains()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()orinsert(), replaced withreplace(), and removed withremove(). All the fields can be removed withclear(). The number of fields is given bycount(); all their values can be cleared (to null) usingclearValues().Inherited by:
QSqlIndexSynopsis¶
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 calledname; otherwise returnsfalse.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 callednameis 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 theindexis 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 positionposin the record.- isEmpty()¶
- Return type:
bool
Returns
trueif there are no fields in the record; otherwise returnsfalse.- isGenerated(name)¶
- Parameters:
name – str
- Return type:
bool
Returns
trueif the record has a field callednameand this field is to be generated (the default); otherwise returnsfalse.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 positionindexand this field is to be generated (the default); otherwise returnsfalse.See also
- isNull(name)¶
- Parameters:
name – str
- Return type:
bool
Returns
trueif the field callednameis null or if there is no field calledname; otherwise returnsfalse.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 fieldindexis null or if there is no field at positionindex; otherwise returnsfalse.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 toother; otherwise returnsfalse.See also
operator==()- __eq__(other)¶
- Parameters:
other –
QSqlRecord- Return type:
bool
Returns
trueif this object is identical toother(i.e., has the same fields in the same order); otherwise returnsfalse.See also
operator!=()- remove(pos)¶
- Parameters:
pos – int
Removes the field at position
pos. Ifposis out of range, nothing happens.Replaces the field at position
poswith the givenfield. Ifposis out of range, nothing happens.- setGenerated(name, generated)¶
- Parameters:
name – str
generated – bool
Sets the generated flag for the field called
nametogenerated. If the field does not exist, nothing happens. Only fields that havegeneratedset to true are included in the SQL that is generated byQSqlQueryModelfor 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
indextogenerated.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
nametoval. 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
indextoval. 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 fieldnamedoes 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. Ifindexis out of bounds, an invalid QVariant is returned.See also