- class QSqlRecord¶
The
QSqlRecord
class encapsulates a database record. More…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
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 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 aQSqlField
object 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()
.- __init__()¶
Constructs an empty record.
- __init__(other)
- Parameters:
other –
QSqlRecord
Constructs a copy of
other
.QSqlRecord
is implicitly shared. This means you can make copies of a record in constant time.Append a copy of field
field
to 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
true
if 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
This is an overloaded function.
Returns the field called
name
. If the field calledname
is 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 theindex
is 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
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.Note
In Qt versions prior to 6.8, this function took QString, not QAnyStringView.
See also
Inserts the field
field
at positionpos
in the record.- isEmpty()¶
- Return type:
bool
Returns
true
if there are no fields in the record; otherwise returnsfalse
.- isGenerated(name)¶
- Parameters:
name – str
- Return type:
bool
This is an overloaded function.
Returns
true
if the record has a field calledname
and 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
true
if the record has a field at positionindex
and this field is to be generated (the default); otherwise returnsfalse
.See also
- isNull(name)¶
- Parameters:
name – str
- Return type:
bool
This is an overloaded function.
Returns
true
if the field calledname
is 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
true
if the fieldindex
is 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
keyFields
set to values that match by field name.- __ne__(other)¶
- Parameters:
other –
QSqlRecord
- Return type:
bool
Returns
true
if this object is not identical toother
; otherwise returnsfalse
.See also
operator==()
- __eq__(other)¶
- Parameters:
other –
QSqlRecord
- Return type:
bool
Returns
true
if 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
. Ifpos
is out of range, nothing happens.Replaces the field at position
pos
with the givenfield
. Ifpos
is out of range, nothing happens.- setGenerated(name, generated)¶
- Parameters:
name – str
generated – bool
Sets the generated flag for the field called
name
togenerated
. If the field does not exist, nothing happens. Only fields that havegenerated
set to true are included in the SQL that is generated byQSqlQueryModel
for 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
index
togenerated
.See also
- 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.Note
In Qt versions prior to 6.8, this function took QString, not QAnyStringView.
- setNull(i)
- Parameters:
i – int
Sets the value of field
index
to null. If the field does not exist, nothing happens.See also
- setValue(name, val)¶
- Parameters:
name – str
val – object
This is an overloaded function.
Sets the value of the field called
name
toval
. 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
index
toval
. If the field does not exist, nothing happens.- swap(other)¶
- Parameters:
other –
QSqlRecord
Swaps SQL record
other
with this SQL record. This operation is very fast and never fails.- 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 fieldname
does 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
index
in the record. Ifindex
is out of bounds, an invalid QVariant is returned.See also