QSqlRecord Class
The QSqlRecord class encapsulates a database record. More…
| Header | #include <QSqlRecord> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Sql) |
| Module | Nt SQL C++ Classes |
| Inherited by | QSqlIndex |
List of all members, including inherited members
Public Functions
| QSqlRecord() | |
| QSqlRecord(const QSqlRecord &other) | |
| QSqlRecord(QSqlRecord &&other) | |
| QSqlRecord & | operator=(const QSqlRecord &other) |
| QSqlRecord & | operator=(QSqlRecord &&other) |
| virtual | ~QSqlRecord() |
| bool | operator==(const QSqlRecord &other) const |
| bool | operator!=(const QSqlRecord &other) const |
| QVariant | value(int i) const |
| QVariant | value(QAnyStringView name) const |
| void | setValue(int i, const QVariant &val) |
| void | setValue(QAnyStringView name, const QVariant &val) |
| void | setNull(int i) |
| void | setNull(QAnyStringView name) |
| bool | isNull(int i) const |
| bool | isNull(QAnyStringView name) const |
| int | indexOf(QAnyStringView name) const |
| QString | fieldName(int i) const |
| QSqlField | field(int i) const |
| QSqlField | field(QAnyStringView name) const |
| bool | isGenerated(int i) const |
| bool | isGenerated(QAnyStringView name) const |
| void | setGenerated(QAnyStringView name, bool generated) |
| void | setGenerated(int i, bool generated) |
| void | append(const QSqlField &field) |
| void | replace(int pos, const QSqlField &field) |
| void | insert(int pos, const QSqlField &field) |
| void | remove(int pos) |
| bool | isEmpty() const |
| bool | contains(QAnyStringView name) const |
| void | clear() |
| void | clearValues() |
| int | count() const |
| QSqlRecord | keyValues(const QSqlRecord &keyFields) const |
| void | swap(QSqlRecord &other) |
Detailed Description
A QSqlRecord is a list of fields with their values: one row of a table, a view or a query. QSqlQuery::record() gives the current row of a query, and QSqlDatabase::record() the columns of a table without values.
QSqlRecord row = query.record();
int name = row.indexOf("name");
while (query.next())
qDebug() << query.value(name).toString();
Fields are found by position or by name; names are compared without regard to case, and a name of the form table.field also names the field field of the table table. A position or a name that does not exist is ignored by the setters and gives a default value in the getters.
See also QSqlField and QSqlQuery::record().
Differences from Qt
A record is a plain value: copies are not implicitly shared.
Member Function Documentation
QSqlRecord::QSqlRecord()
Constructs an empty record.
See also isEmpty() and append().
QSqlRecord::QSqlRecord(const QSqlRecord &other)
Constructs a copy of other.
QSqlRecord::QSqlRecord(QSqlRecord &&other)
Constructs a record with the fields of other, which is left empty.
QSqlRecord::~QSqlRecord()
Destroys the record.
void QSqlRecord::append(const QSqlField &field)
Adds a copy of field to the end of the record.
See also insert(), replace() and remove().
void QSqlRecord::clear()
Removes all the fields of the record.
See also clearValues() and isEmpty().
void QSqlRecord::clearValues()
Sets the value of every field to null. Read-only fields keep their values.
See also clear() and setNull().
bool QSqlRecord::contains(QAnyStringView name) const
Returns true if the record has a field called name; otherwise returns false.
See also indexOf().
int QSqlRecord::count() const
Returns the number of fields in the record.
See also isEmpty().
QSqlField QSqlRecord::field(int i) const
Returns the field at position i, or a default-constructed field if there is no such field.
QSqlField QSqlRecord::field(QAnyStringView name) const
This is an overloaded function.
Returns the field called name.
QString QSqlRecord::fieldName(int i) const
Returns the name of the field at position i, or an empty string if there is no such field.
See also indexOf().
int QSqlRecord::indexOf(QAnyStringView name) const
Returns the position of the field called name, or -1 if there is no such field. Case does not matter, and name may have the form table.field.
See also fieldName().
void QSqlRecord::insert(int pos, const QSqlField &field)
Inserts a copy of field at position pos. A position that is out of range is moved to the nearest end of the record.
See also append() and remove().
bool QSqlRecord::isEmpty() const
Returns true if the record has no fields; otherwise returns false.
See also count().
bool QSqlRecord::isGenerated(int i) const
Returns true if the field at position i takes part in generated SQL statements; returns false if it does not or if there is no such field.
See also setGenerated().
bool QSqlRecord::isGenerated(QAnyStringView name) const
This is an overloaded function.
Returns true if the field called name takes part in generated SQL statements.
bool QSqlRecord::isNull(int i) const
Returns true if the value of the field at position i is null or if there is no such field; otherwise returns false.
See also setNull().
bool QSqlRecord::isNull(QAnyStringView name) const
This is an overloaded function.
Returns true if the value of the field called name is null or if there is no such field; otherwise returns false.
QSqlRecord QSqlRecord::keyValues(const QSqlRecord &keyFields) const
Returns a record with the fields of keyFields, by name, and the values that these fields have in this record. Fields of keyFields that this record does not have are left out.
bool QSqlRecord::operator!=(const QSqlRecord &other) const
Returns true if this record differs from other; otherwise returns false.
QSqlRecord & QSqlRecord::operator=(const QSqlRecord &other)
Makes this record a copy of other and returns a reference to it.
QSqlRecord & QSqlRecord::operator=(QSqlRecord &&other)
Moves the fields of other to this record and returns a reference to it.
bool QSqlRecord::operator==(const QSqlRecord &other) const
Returns true if this record has the same fields with the same values as other; otherwise returns false.
void QSqlRecord::remove(int pos)
Removes the field at position pos. Nothing happens if there is no such field.
See also append() and clear().
void QSqlRecord::replace(int pos, const QSqlField &field)
Replaces the field at position pos with a copy of field. Nothing happens if there is no such field.
See also append() and insert().
void QSqlRecord::setGenerated(QAnyStringView name, bool generated)
This is an overloaded function.
Sets whether the field called name takes part in generated SQL statements to generated.
void QSqlRecord::setGenerated(int i, bool generated)
Sets whether the field at position i takes part in generated SQL statements to generated. Nothing happens if there is no such field.
See also isGenerated().
void QSqlRecord::setNull(int i)
Sets the value of the field at position i to null. Nothing happens if there is no such field.
See also setValue().
void QSqlRecord::setNull(QAnyStringView name)
This is an overloaded function.
Sets the value of the field called name to null.
void QSqlRecord::setValue(int i, const QVariant &val)
Sets the value of the field at position i to val. Nothing happens if there is no such field, or if it is read-only.
See also setNull().
void QSqlRecord::setValue(QAnyStringView name, const QVariant &val)
This is an overloaded function.
Sets the value of the field called name to val.
void QSqlRecord::swap(QSqlRecord &other)
Swaps this record with other.
QVariant QSqlRecord::value(int i) const
Returns the value of the field at position i, or an invalid QVariant if there is no such field.
See also fieldName() and isNull().
QVariant QSqlRecord::value(QAnyStringView name) const
This is an overloaded function.
Returns the value of the field called name, or an invalid QVariant if there is no such field.