![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QSqlRecord class encapsulates a database record. More...
#include <qsqlrecord.h>
Public Member Functions | |
QSqlRecord () | |
Constructs an empty record. | |
QSqlRecord (const QSqlRecord &other) | |
Constructs a copy of other. | |
QSqlRecord (QSqlRecord &&other) noexcept=default | |
QSqlRecord & | operator= (const QSqlRecord &other) |
Sets the record equal to other. | |
~QSqlRecord () | |
Destroys the object and frees any allocated resources. | |
void | swap (QSqlRecord &other) noexcept |
bool | operator== (const QSqlRecord &other) const |
Returns true if this object is identical to other (i.e., has the same fields in the same order); otherwise returns false . | |
bool | operator!= (const QSqlRecord &other) const |
Returns true if this object is not identical to other; otherwise returns false . | |
QVariant | value (int i) const |
Returns the value of the field located at position index in the record. | |
QVariant | value (QAnyStringView name) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the value of the field called name in the record. | |
void | setValue (int i, const QVariant &val) |
Sets the value of the field at position index to val. | |
void | setValue (QAnyStringView name, const QVariant &val) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the value of the field called name to val. | |
void | setNull (int i) |
Sets the value of field index to null. | |
void | setNull (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the value of the field called name to null. | |
bool | isNull (int i) const |
Returns true if the field index is null or if there is no field at position index; otherwise returns false . | |
bool | isNull (QAnyStringView name) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if the field called name is null or if there is no field called name; otherwise returns false . | |
int | indexOf (QAnyStringView name) const |
Returns the position of the field called name within the record, or -1 if it cannot be found. | |
QString | fieldName (int i) const |
Returns the name of the field at position index. | |
QSqlField | field (int i) const |
Returns the field at position index. | |
QSqlField | field (QAnyStringView name) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the field called name. | |
bool | isGenerated (int i) const |
Returns true if the record has a field at position index and this field is to be generated (the default); otherwise returns false . | |
bool | isGenerated (QAnyStringView name) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if the record has a field called name and this field is to be generated (the default); otherwise returns false . | |
void | setGenerated (QAnyStringView name, bool generated) |
Sets the generated flag for the field called name to generated. | |
void | setGenerated (int i, bool generated) |
Sets the generated flag for the field index to generated. | |
void | append (const QSqlField &field) |
Append a copy of field field to the end of the record. | |
void | replace (int pos, const QSqlField &field) |
Replaces the field at position pos with the given field. | |
void | insert (int pos, const QSqlField &field) |
Inserts the field field at position pos in the record. | |
void | remove (int pos) |
Removes the field at position pos. | |
bool | isEmpty () const |
Returns true if there are no fields in the record; otherwise returns false . | |
bool | contains (QAnyStringView name) const |
Returns true if there is a field in the record called name; otherwise returns false . | |
void | clear () |
Removes all the record's fields. | |
void | clearValues () |
Clears the value of all fields in the record and sets each field to null. | |
int | count () const |
Returns the number of fields in the record. | |
QSqlRecord | keyValues (const QSqlRecord &keyFields) const |
The QSqlRecord class encapsulates a database record.
\inmodule QtSql
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().
Definition at line 19 of file qsqlrecord.h.
QSqlRecord::QSqlRecord | ( | ) |
Constructs an empty record.
Definition at line 93 of file qsqlrecord.cpp.
|
default |
Constructs a copy of other.
QSqlRecord is \l{implicitly shared}. This means you can make copies of a record in \l{constant time}.
|
defaultnoexcept |
Move-constructs a new QSqlRecord from other.
|
default |
Destroys the object and frees any allocated resources.
Append a copy of field field to the end of the record.
Definition at line 267 of file qsqlrecord.cpp.
void QSqlRecord::clear | ( | ) |
Removes all the record's fields.
Definition at line 322 of file qsqlrecord.cpp.
void QSqlRecord::clearValues | ( | ) |
Clears the value of all fields in the record and sets each field to null.
Definition at line 359 of file qsqlrecord.cpp.
bool QSqlRecord::contains | ( | QAnyStringView | name | ) | const |
Returns true
if there is a field in the record called name; otherwise returns false
.
Definition at line 347 of file qsqlrecord.cpp.
int QSqlRecord::count | ( | ) | const |
Returns the number of fields in the record.
Definition at line 484 of file qsqlrecord.cpp.
QSqlField QSqlRecord::field | ( | int | index | ) | const |
Returns the field at position index.
If the index is out of range, function returns a \l{default-constructed value}.
Definition at line 240 of file qsqlrecord.cpp.
QSqlField QSqlRecord::field | ( | QAnyStringView | name | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the field called name.
If the field called name is not found, function returns a \l{default-constructed value}.
Definition at line 255 of file qsqlrecord.cpp.
QString QSqlRecord::fieldName | ( | int | index | ) | const |
Returns the name of the field at position index.
If the field does not exist, an empty string is returned.
Definition at line 211 of file qsqlrecord.cpp.
int QSqlRecord::indexOf | ( | QAnyStringView | name | ) | const |
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.
Definition at line 227 of file qsqlrecord.cpp.
Inserts the field field at position pos in the record.
Definition at line 278 of file qsqlrecord.cpp.
bool QSqlRecord::isEmpty | ( | ) | const |
Returns true
if there are no fields in the record; otherwise returns false
.
Definition at line 335 of file qsqlrecord.cpp.
bool QSqlRecord::isGenerated | ( | int | index | ) | const |
Returns true
if the record has a field at position index and this field is to be generated (the default); otherwise returns false
.
Definition at line 473 of file qsqlrecord.cpp.
bool QSqlRecord::isGenerated | ( | QAnyStringView | name | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true
if the record has a field called name and this field is to be generated (the default); otherwise returns false
.
Definition at line 462 of file qsqlrecord.cpp.
bool QSqlRecord::isNull | ( | int | index | ) | const |
Returns true
if the field index is null or if there is no field at position index; otherwise returns false
.
Definition at line 402 of file qsqlrecord.cpp.
bool QSqlRecord::isNull | ( | QAnyStringView | name | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true
if the field called name is null or if there is no field called name; otherwise returns false
.
Definition at line 418 of file qsqlrecord.cpp.
QSqlRecord QSqlRecord::keyValues | ( | const QSqlRecord & | keyFields | ) | const |
Definition at line 550 of file qsqlrecord.cpp.
|
inline |
Returns true
if this object is not identical to other; otherwise returns false
.
Definition at line 32 of file qsqlrecord.h.
|
default |
Sets the record equal to other.
Move-assigns other to this QSqlRecord instance.
QSqlRecord is \l{implicitly shared}. This means you can make copies of a record in \l{constant time}.
bool QSqlRecord::operator== | ( | const QSqlRecord & | other | ) | const |
Returns true
if this object is identical to other (i.e., has the same fields in the same order); otherwise returns false
.
Definition at line 170 of file qsqlrecord.cpp.
void QSqlRecord::remove | ( | int | pos | ) |
Removes the field at position pos.
If pos is out of range, nothing happens.
Definition at line 307 of file qsqlrecord.cpp.
Replaces the field at position pos with the given field.
If pos is out of range, nothing happens.
Definition at line 291 of file qsqlrecord.cpp.
void QSqlRecord::setGenerated | ( | int | index, |
bool | generated ) |
Sets the generated flag for the field index to generated.
Definition at line 388 of file qsqlrecord.cpp.
void QSqlRecord::setGenerated | ( | QAnyStringView | name, |
bool | generated ) |
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.
Definition at line 377 of file qsqlrecord.cpp.
void QSqlRecord::setNull | ( | int | index | ) |
Sets the value of field index to null.
If the field does not exist, nothing happens.
Definition at line 429 of file qsqlrecord.cpp.
void QSqlRecord::setNull | ( | QAnyStringView | name | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the value of the field called name to null.
If the field does not exist, nothing happens.
Definition at line 446 of file qsqlrecord.cpp.
Sets the value of the field at position index to val.
If the field does not exist, nothing happens.
Definition at line 496 of file qsqlrecord.cpp.
void QSqlRecord::setValue | ( | QAnyStringView | name, |
const QVariant & | val ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the value of the field called name to val.
If the field does not exist, nothing happens.
Definition at line 515 of file qsqlrecord.cpp.
|
inlinenoexcept |
Definition at line 29 of file qsqlrecord.h.
QVariant QSqlRecord::value | ( | int | index | ) | const |
Returns the value of the field located at position index in the record.
If index is out of bounds, an invalid QVariant is returned.
Definition at line 183 of file qsqlrecord.cpp.
QVariant QSqlRecord::value | ( | QAnyStringView | name | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the value of the field called name in the record.
If field name does not exist an invalid variant is returned.
Definition at line 199 of file qsqlrecord.cpp.