Qt 4.8
|
The QSqlRecord class encapsulates a database record. More...
#include <qsqlrecord.h>
Public Functions | |
void | append (const QSqlField &field) |
Append a copy of field field to the end of the record. More... | |
void | clear () |
Removes all the record's fields. More... | |
void | clearValues () |
Clears the value of all fields in the record and sets each field to null. More... | |
bool | contains (const QString &name) const |
Returns true if there is a field in the record called name; otherwise returns false. More... | |
int | count () const |
Returns the number of fields in the record. More... | |
QSqlField | field (int i) const |
Returns the field at position index. More... | |
QSqlField | field (const QString &name) const |
Returns the field called name. More... | |
QString | fieldName (int i) const |
Returns the name of the field at position index. More... | |
int | indexOf (const QString &name) const |
Returns the position of the field called name within the record, or -1 if it cannot be found. More... | |
void | insert (int pos, const QSqlField &field) |
Inserts the field field at position pos in the record. More... | |
bool | isEmpty () const |
Returns true if there are no fields in the record; otherwise returns false. More... | |
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. More... | |
bool | isGenerated (const QString &name) const |
Returns true if the record has a field called name and this field is to be generated (the default); otherwise returns false. More... | |
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. More... | |
bool | isNull (const QString &name) const |
Returns true if the field called name is null or if there is no field called name; otherwise returns false. More... | |
bool | operator!= (const QSqlRecord &other) const |
Returns true if this object is not identical to other; otherwise returns false. More... | |
QSqlRecord & | operator= (const QSqlRecord &other) |
Sets the record equal to other. More... | |
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. More... | |
QSqlRecord () | |
Constructs an empty record. More... | |
QSqlRecord (const QSqlRecord &other) | |
Constructs a copy of other. More... | |
void | remove (int pos) |
Removes the field at position pos. More... | |
void | replace (int pos, const QSqlField &field) |
Replaces the field at position pos with the given field. More... | |
void | setGenerated (const QString &name, bool generated) |
Sets the generated flag for the field called name to generated. More... | |
void | setGenerated (int i, bool generated) |
Sets the generated flag for the field index to generated. More... | |
void | setNull (int i) |
Sets the value of field index to null. More... | |
void | setNull (const QString &name) |
Sets the value of the field called name to null. More... | |
void | setValue (int i, const QVariant &val) |
Sets the value of the field at position index to val. More... | |
void | setValue (const QString &name, const QVariant &val) |
Sets the value of the field called name to val. More... | |
QVariant | value (int i) const |
Returns the value of the field located at position index in the record. More... | |
QVariant | value (const QString &name) const |
Returns the value of the field called name in the record. More... | |
~QSqlRecord () | |
Destroys the object and frees any allocated resources. More... | |
Private Functions | |
void | detach () |
Properties | |
QSqlRecordPrivate * | d |
The QSqlRecord class encapsulates a database record.
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 58 of file qsqlrecord.h.
QSqlRecord::QSqlRecord | ( | ) |
Constructs an empty record.
Definition at line 131 of file qsqlrecord.cpp.
QSqlRecord::QSqlRecord | ( | const QSqlRecord & | other | ) |
Constructs a copy of other.
QSqlRecord is implicitly shared. This means you can make copies of a record in constant time.
Definition at line 143 of file qsqlrecord.cpp.
QSqlRecord::~QSqlRecord | ( | ) |
Destroys the object and frees any allocated resources.
Definition at line 166 of file qsqlrecord.cpp.
void QSqlRecord::append | ( | const QSqlField & | field | ) |
Append a copy of field field to the end of the record.
Definition at line 312 of file qsqlrecord.cpp.
Referenced by QSqlIndex::append(), QDB2Result::exec(), QODBCResult::exec(), QSQLite2ResultPrivate::init(), QSQLiteResultPrivate::initColumns(), QSymSQLResultPrivate::initColumns(), QDB2Result::nextResult(), QODBCResult::nextResult(), QOCICols::QOCICols(), QIBaseResult::record(), QPSQLResult::record(), QMYSQLResult::record(), QDB2Driver::record(), QIBaseDriver::record(), QOCIDriver::record(), QTDSDriver::record(), QMYSQLDriver::record(), QODBCDriver::record(), QPSQLDriver::record(), QDB2Result::reset(), QTDSResult::reset(), and QODBCResult::reset().
void QSqlRecord::clear | ( | void | ) |
Removes all the record's fields.
Definition at line 367 of file qsqlrecord.cpp.
Referenced by QTDSResult::cleanup(), QSQLite2ResultPrivate::cleanup(), QSQLiteResultPrivate::cleanup(), QSqlTableModelPrivate::clear(), QDB2Result::exec(), QSQLiteResult::exec(), QODBCResult::exec(), QSQLite2ResultPrivate::init(), QDB2Result::nextResult(), QODBCResult::nextResult(), QDB2Result::prepare(), QODBCResult::prepare(), QDB2Result::reset(), and QODBCResult::reset().
void QSqlRecord::clearValues | ( | ) |
Clears the value of all fields in the record and sets each field to null.
Definition at line 403 of file qsqlrecord.cpp.
bool QSqlRecord::contains | ( | const QString & | name | ) | const |
Returns true if there is a field in the record called name; otherwise returns false.
Definition at line 391 of file qsqlrecord.cpp.
Referenced by QSQLite2Driver::primaryIndex().
int QSqlRecord::count | ( | ) | const |
Returns the number of fields in the record.
Definition at line 573 of file qsqlrecord.cpp.
Referenced by QSqlTableModelPrivate::clearGenerated(), QDB2Result::data(), QODBCResult::data(), QSqlTableModelPrivate::exec(), QSQLiteResultPrivate::fetchNext(), QTDSResult::gotoNext(), operator<<(), QSqlTableModelPrivate::primaryValues(), qmlsqldatabase_item(), QSqlQueryModel::record(), QSqlTableModelPrivate::record(), QSqlQuery::record(), QSqlRelationalTableModel::selectStatement(), QSqlIndex::setDescending(), QSqlQueryModel::setQuery(), QSqlTableModelPrivate::setRecord(), QSqlTableModel::setRecord(), QSqlDriver::sqlStatement(), and QSqlRelationalTableModelPrivate::translateFieldNames().
|
private |
Definition at line 612 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 default-constructed value.
Definition at line 289 of file qsqlrecord.cpp.
Referenced by QSqlIndex::createField(), QDB2Result::data(), QODBCResult::data(), QTDSResult::gotoNext(), operator<<(), QRelation::populateDictionary(), QDB2Driver::primaryIndex(), QSQLite2Driver::primaryIndex(), QTDSDriver::primaryIndex(), QMYSQLDriver::primaryIndex(), QODBCDriver::primaryIndex(), and QSqlDriver::sqlStatement().
Returns the field called name.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 300 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 232 of file qsqlrecord.cpp.
Referenced by QSqlTableModelPrivate::primaryValues(), qmlsqldatabase_item(), QSqlRelationalTableModel::selectStatement(), QSqlTableModelPrivate::setRecord(), QSqlTableModel::setRecord(), and QSqlDriver::sqlStatement().
int QSqlRecord::indexOf | ( | const QString & | 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 246 of file qsqlrecord.cpp.
Referenced by QSqlTableModelPrivate::nameToIndex(), QSqlTableModelPrivate::primaryValues(), and QSqlTableModel::setRecord().
void QSqlRecord::insert | ( | int | pos, |
const QSqlField & | field | ||
) |
Inserts the field field at position pos in the record.
Definition at line 323 of file qsqlrecord.cpp.
bool QSqlRecord::isEmpty | ( | ) | const |
Returns true if there are no fields in the record; otherwise returns false.
Definition at line 380 of file qsqlrecord.cpp.
Referenced by QSQLiteResult::exec(), QSQLite2ResultPrivate::fetchNext(), QSQLiteResultPrivate::fetchNext(), QSqlTableModelPrivate::primaryValues(), and QSQLite2Result::reset().
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.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 519 of file qsqlrecord.cpp.
Referenced by QSqlTableModel::data(), QSqlRelationalTableModel::data(), QSqlTableModelPrivate::exec(), QSqlTableModel::isDirty(), QSqlTableModelPrivate::setRecord(), QSqlTableModel::setRecord(), QSqlDriver::sqlStatement(), and QSqlRelationalTableModelPrivate::translateFieldNames().
bool QSqlRecord::isGenerated | ( | const QString & | name | ) | const |
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 504 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.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 453 of file qsqlrecord.cpp.
Referenced by QSqlTableModelPrivate::exec(), and QSqlDriver::sqlStatement().
bool QSqlRecord::isNull | ( | const QString & | name | ) | const |
Returns true if the field called name is null or if there is no field called name; otherwise returns false.
Definition at line 464 of file qsqlrecord.cpp.
|
inline |
Returns true if this object is not identical to other; otherwise returns false.
Definition at line 67 of file qsqlrecord.h.
QSqlRecord & QSqlRecord::operator= | ( | const QSqlRecord & | other | ) |
Sets the record equal to other.
QSqlRecord is implicitly shared. This means you can make copies of a record in constant time.
Definition at line 156 of file qsqlrecord.cpp.
Referenced by QSqlIndex::operator=().
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 190 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 352 of file qsqlrecord.cpp.
void QSqlRecord::replace | ( | int | pos, |
const QSqlField & | field | ||
) |
Replaces the field at position pos with the given field.
If pos is out of range, nothing happens.
Definition at line 336 of file qsqlrecord.cpp.
Referenced by QSqlRelationalTableModelPrivate::translateFieldNames().
void QSqlRecord::setGenerated | ( | const QString & | 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 420 of file qsqlrecord.cpp.
Referenced by QSqlTableModelPrivate::clearGenerated(), QSqlTableModelPrivate::setGeneratedValue(), QSqlTableModel::setRecord(), and QSqlRelationalTableModelPrivate::translateFieldNames().
void QSqlRecord::setGenerated | ( | int | index, |
bool | generated | ||
) |
Sets the generated flag for the field index to generated.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 436 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 475 of file qsqlrecord.cpp.
void QSqlRecord::setNull | ( | const QString & | name | ) |
Sets the value of the field called name to null.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If the field does not exist, nothing happens.
Definition at line 492 of file qsqlrecord.cpp.
void QSqlRecord::setValue | ( | int | index, |
const QVariant & | val | ||
) |
Sets the value of the field at position index to val.
If the field does not exist, nothing happens.
Definition at line 585 of file qsqlrecord.cpp.
Referenced by QSqlTableModelPrivate::primaryValues(), QSqlQueryModel::record(), QSqlTableModelPrivate::record(), QSqlQuery::record(), QSqlTableModelPrivate::setGeneratedValue(), QSqlTableModel::setRecord(), and QSqlRelationalTableModelPrivate::translateFieldNames().
Sets the value of the field called name to val.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If the field does not exist, nothing happens.
Definition at line 604 of file qsqlrecord.cpp.
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 203 of file qsqlrecord.cpp.
Referenced by QSqlTableModel::data(), QSqlRelationalTableModel::data(), QSqlTableModelPrivate::exec(), operator<<(), qmlsqldatabase_item(), QSqlTableModelPrivate::setRecord(), QSqlTableModel::setRecord(), and QSqlRelationalTableModelPrivate::translateFieldNames().
Returns the value of the field called name in the record.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If field name does not exist an invalid variant is returned.
Definition at line 220 of file qsqlrecord.cpp.
|
private |
Definition at line 112 of file qsqlrecord.h.
Referenced by operator=(), operator==(), and QSqlRecord().