QSqlRecord 类

QSqlRecord 类封装数据库记录。 更多...

头: #include <QSqlRecord>
CMake: find_package(Qt6 REQUIRED COMPONENTS Sql)
target_link_libraries(mytarget PRIVATE Qt6::Sql)
qmake: QT += sql
继承者:

QSqlIndex

公共函数

QSqlRecord ()
QSqlRecord (const QSqlRecord & other )
(从 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 )
(从 6.6 起) void swap (QSqlRecord & other )
QVariant value (int index ) const
QVariant value (QAnyStringView name ) const
bool operator!= (const QSqlRecord & other ) const
(从 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 ()。使用 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 () 或 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 ().

另请参阅 QSqlField and QSqlQuery::record ().

成员函数文档编制

QSqlRecord:: QSqlRecord ()

Constructs an empty record.

另请参阅 isEmpty (), append (),和 insert ().

QSqlRecord:: QSqlRecord (const QSqlRecord & other )

构造副本为 other .

QSqlRecord is 隐式共享 . This means you can make copies of a record in 常量时间 .

[noexcept, since 6.6] QSqlRecord:: QSqlRecord ( QSqlRecord && other )

Move-constructs a new QSqlRecord from other .

注意: 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.

该函数在 Qt 6.6 引入。

[noexcept] QSqlRecord:: ~QSqlRecord ()

销毁对象并释放任何分配资源。

void QSqlRecord:: append (const QSqlField & field )

Append a copy of field field to the end of the record.

另请参阅 insert (), replace (),和 remove ().

void QSqlRecord:: clear ()

Removes all the record's fields.

另请参阅 clearValues () 和 isEmpty ().

void QSqlRecord:: clearValues ()

Clears the value of all fields in the record and sets each field to null.

另请参阅 setValue ().

bool QSqlRecord:: contains ( QAnyStringView name ) const

返回 true if there is a field in the record called name ;否则返回 false .

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

int QSqlRecord:: count () const

Returns the number of fields in the record.

另请参阅 isEmpty ().

QSqlField QSqlRecord:: field ( int index ) const

Returns the field at position index 。若 index is out of range, function returns a 默认构造值 .

QSqlField QSqlRecord:: field ( QAnyStringView name ) const

这是重载函数。

Returns the field called name . If the field called name is not found, function returns a 默认构造值 .

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

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.

另请参阅 indexOf ().

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.

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

另请参阅 fieldName ().

void QSqlRecord:: insert ( int pos , const QSqlField & field )

Inserts the field field 在位置 pos in the record.

另请参阅 append (), replace (),和 remove ().

bool QSqlRecord:: isEmpty () const

返回 true if there are no fields in the record; otherwise returns false .

另请参阅 append (), insert (),和 clear ().

bool QSqlRecord:: isGenerated ( int index ) const

返回 true if the record has a field at position index and this field is to be generated (the default); otherwise returns false .

另请参阅 setGenerated ().

bool QSqlRecord:: isGenerated ( QAnyStringView name ) const

这是重载函数。

返回 true if the record has a field called name and this field is to be generated (the default); otherwise returns false .

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

另请参阅 setGenerated ().

bool QSqlRecord:: isNull ( int index ) const

返回 true if the field index is null or if there is no field at position index ;否则返回 false .

另请参阅 setNull ().

bool QSqlRecord:: isNull ( QAnyStringView name ) const

这是重载函数。

返回 true if the field called name is null or if there is no field called name ;否则返回 false .

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

另请参阅 setNull ().

QSqlRecord QSqlRecord:: keyValues (const QSqlRecord & keyFields ) const

Returns a record containing the fields represented in keyFields set to values that match by field name.

void QSqlRecord:: remove ( int pos )

Removes the field at position pos 。若 pos is out of range, nothing happens.

另请参阅 append (), insert (),和 replace ().

void QSqlRecord:: replace ( int pos , const QSqlField & field )

Replaces the field at position pos 采用给定 field 。若 pos is out of range, nothing happens.

另请参阅 append (), insert (),和 remove ().

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 例如。

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

另请参阅 isGenerated ().

void QSqlRecord:: setGenerated ( int index , bool generated )

Sets the generated flag for the field index to generated .

另请参阅 isGenerated ().

void QSqlRecord:: setNull ( int index )

Sets the value of field index to null. If the field does not exist, nothing happens.

另请参阅 isNull () 和 setValue ().

void QSqlRecord:: setNull ( QAnyStringView name )

这是重载函数。

Sets the value of the field called name to null. If the field does not exist, nothing happens.

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

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.

另请参阅 value () 和 setNull ().

void QSqlRecord:: setValue ( QAnyStringView name , const QVariant & val )

这是重载函数。

Sets the value of the field called name to val . If the field does not exist, nothing happens.

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

另请参阅 setNull ().

[noexcept, since 6.6] void QSqlRecord:: swap ( QSqlRecord & other )

Swaps this SQL record with other 。此操作非常快且从不失败。

该函数在 Qt 6.6 引入。

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 被返回。

另请参阅 setValue (), fieldName (),和 isNull ().

QVariant QSqlRecord:: value ( QAnyStringView name ) const

这是重载函数。

Returns the value of the field called name in the record. If field name does not exist an invalid variant is returned.

注意: In Qt versions prior to 6.8, this function took QString , not QAnyStringView .

另请参阅 indexOf () 和 isNull ().

bool QSqlRecord:: operator!= (const QSqlRecord & other ) const

返回 true if this object is not identical to other ;否则返回 false .

另请参阅 operator== ().

[noexcept, since 6.6] QSqlRecord &QSqlRecord:: operator= ( QSqlRecord && other )

移动赋值 other 到此 QSqlRecord 实例。

注意: 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.

该函数在 Qt 6.6 引入。

QSqlRecord &QSqlRecord:: operator= (const QSqlRecord & other )

Sets the record equal to other .

QSqlRecord is 隐式共享 . This means you can make copies of a record in 常量时间 .

bool QSqlRecord:: operator== (const QSqlRecord & other ) const

返回 true if this object is identical to other (i.e., has the same fields in the same order); otherwise returns false .

另请参阅 operator!= ().