The QSqlRecord class encapsulates a database record. More...
| Header: | #include <QSqlRecord> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Sql)target_link_libraries(mytarget PRIVATE Qt6::Sql) |
| qmake: | QT += sql |
| Inherited By: |
| QSqlRecord() | |
| QSqlRecord(const QSqlRecord &other) | |
(since 6.6) |
QSqlRecord(QSqlRecord &&other) |
| ~QSqlRecord() | |
| void | append(const QSqlField &field) |
| void | clear() |
| void | clearValues() |
| bool | contains(QAnyStringView name) const |
| int | count() const |
| QSqlField | field(int index) const |
| QSqlField | field(QAnyStringView name) const |
| QString | fieldName(int index) const |
| int | indexOf(QAnyStringView name) const |
| void | insert(int pos, const QSqlField &field) |
| bool | isEmpty() const |
| bool | isGenerated(int index) const |
| bool | isGenerated(QAnyStringView name) const |
| bool | isNull(int index) const |
| bool | isNull(QAnyStringView name) const |
| QSqlRecord | keyValues(const QSqlRecord &keyFields) const |
| void | remove(int pos) |
| void | replace(int pos, const QSqlField &field) |
| void | setGenerated(QAnyStringView name, bool generated) |
| void | setGenerated(int index, bool generated) |
| void | setNull(int index) |
| void | setNull(QAnyStringView name) |
| void | setValue(int index, const QVariant &val) |
| void | setValue(QAnyStringView name, const QVariant &val) |
(since 6.6) void |
swap(QSqlRecord &other) |
| QVariant | value(int index) const |
| QVariant | value(QAnyStringView name) const |
| bool | operator!=(const QSqlRecord &other) const |
(since 6.6) QSqlRecord & |
operator=(QSqlRecord &&other) |
| QSqlRecord & | operator=(const QSqlRecord &other) |
| bool | operator==(const QSqlRecord &other) const |
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 and QSqlQuery::record().
Constructs an empty record.
See also isEmpty(), append(), and insert().
Constructs a copy of other.
QSqlRecord is implicitly shared. This means you can make copies of a record in constant time.
[noexcept, since 6.6] QSqlRecord::QSqlRecord(QSqlRecord &&other)Move-constructs a new QSqlRecord from other.
Note: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.
This function was introduced in Qt 6.6.
[noexcept] QSqlRecord::~QSqlRecord()Destroys the object and frees any allocated resources.
Append a copy of field field to the end of the record.
See also insert(), replace(), and remove().
Removes all the record's fields.
See also clearValues() and isEmpty().
Clears the value of all fields in the record and sets each field to null.
See also setValue().
Returns true if 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.
Returns the number of fields in the record.
See also isEmpty().
Returns the field at position index. If the index is out of range, function returns a default-constructed value.
This is an overloaded function.
Returns the field called name. If the field called name is not found, function returns a default-constructed value.
Note: In Qt versions prior to 6.8, this function took QString, not QAnyStringView.
Returns the name of the field at position index. If the field does not exist, an empty string is returned.
See also indexOf().
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 fieldName().
Inserts the field field at position pos in the record.
See also append(), replace(), and remove().
Returns true if there are no fields in the record; otherwise returns false.
See also append(), insert(), and clear().
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().
This is an overloaded function.
Returns true if the record has a field called name and 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 setGenerated().
Returns true if the field index is null or if there is no field at position index; otherwise returns false.
See also setNull().
This is an overloaded function.
Returns true if the field called name is 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 setNull().
Returns a record containing the fields represented in keyFields set to values that match by field name.
Removes the field at position pos. If pos is out of range, nothing happens.
See also append(), insert(), and replace().
Replaces the field at position pos with the given field. If pos is out of range, nothing happens.
See also append(), insert(), and remove().
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.
Note: In Qt versions prior to 6.8, this function took QString, not QAnyStringView.
See also isGenerated().
Sets the generated flag for the field index to generated.
See also isGenerated().
Sets the value of field index to null. If the field does not exist, nothing happens.
See also isNull() and setValue().
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.
Sets the value of the field at position index to val. If the field does not exist, nothing happens.
See also value() and setNull().
This is an overloaded function.
Sets the value of the field called name to 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 setNull().
[noexcept, since 6.6] void QSqlRecord::swap(QSqlRecord &other)Swaps this SQL record with other. This operation is very fast and never fails.
This function was introduced in Qt 6.6.
Returns the value of the field located at position index in the record. If index is out of bounds, an invalid QVariant is returned.
See also setValue(), fieldName(), and isNull().
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.
Note: In Qt versions prior to 6.8, this function took QString, not QAnyStringView.
See also indexOf() and isNull().
Returns true if this object is not identical to other; otherwise returns false.
See also operator==().
[noexcept, since 6.6] QSqlRecord
&QSqlRecord::operator=(QSqlRecord &&other)Move-assigns other to this QSqlRecord instance.
Note: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.
This function was introduced in Qt 6.6.
Sets the record equal to other.
QSqlRecord is implicitly shared. This means you can make copies of a record in constant time.
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!=().