返回介绍

QSqlRecord Class

发布于 2019-10-04 15:03:01 字数 11351 浏览 1075 评论 0 收藏 0

The QSqlRecord class encapsulates a database record, i.e. a
set of database fields.
More...

#include <qsqlrecord.h>

Inherited by QSqlCursor and QSqlIndex.

List of all member functions.

Public Members

  • QSqlRecord ()
  • QSqlRecord ( constQSqlRecord&other )
  • QSqlRecord & operator= ( constQSqlRecord&other )
  • virtual ~QSqlRecord ()
  • virtual QVariant value ( inti ) const
  • virtual QVariant value ( constQString&name ) const
  • virtual void setValue ( inti, constQVariant&val )
  • virtual void setValue ( constQString&name, constQVariant&val )
  • bool isGenerated ( inti ) const
  • bool isGenerated ( constQString&name ) const
  • virtual void setGenerated ( constQString&name, boolgenerated )
  • virtual void setGenerated ( inti, boolgenerated )
  • virtual void setNull ( inti )
  • virtual void setNull ( constQString&name )
  • bool isNull ( inti )
  • bool isNull ( constQString&name )
  • int position ( constQString&name ) const
  • QString fieldName ( inti ) const
  • QSqlField * field ( inti )
  • QSqlField * field ( constQString&name )
  • const QSqlField * field ( inti ) const
  • const QSqlField * field ( constQString&name ) const
  • virtual void append ( constQSqlField&field )
  • virtual void insert ( intpos, constQSqlField&field )
  • virtual void remove ( intpos )
  • bool isEmpty () const
  • bool contains ( constQString&name ) const
  • virtual void clear ()
  • virtual void clearValues ( boolnullify = FALSE )
  • uint count () const
  • virtual QString toString ( constQString&prefix = QString::null, constQString&sep = "," ) const
  • virtual QStringList toStringList ( constQString&prefix = QString::null ) const

Detailed Description

The QSqlRecord class encapsulates a database record, i.e. a
set of database fields.

The QSqlRecord class encapsulates the functionality and
characteristics of a database record (usually a table or view within
the database). QSqlRecords support adding and removing fields as
well as setting and retrieving field values.

QSqlRecord is implicitly shared. This means you can make copies of
the record in time O(1). If multiple QSqlRecord instances share
the same data and one is modifying the record's data then this
modifying instance makes a copy and modifies its private copy -
thus it does not affect other instances.

See also Database Classes.


Member Function Documentation

QSqlRecord::QSqlRecord ()

Constructs an empty record.

QSqlRecord::QSqlRecord ( constQSqlRecord&other )

Constructs a copy of other.

QSqlRecord::~QSqlRecord () [virtual]

Destroys the object and frees any allocated resources.

void QSqlRecord::append ( constQSqlField&field ) [virtual]

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

Reimplemented in QSqlIndex.

void QSqlRecord::clear () [virtual]

Removes all fields from the record.

See also clearValues().

Reimplemented in QSqlCursor.

void QSqlRecord::clearValues ( boolnullify = FALSE ) [virtual]

Clears the value of all fields in the record. If nullify is
TRUE, (it's default is FALSE), each field is set to null.

bool QSqlRecord::contains ( constQString&name ) const

Returns TRUE if there is a field in the record called name,
otherwise returns FALSE.

uint QSqlRecord::count () const

Returns the number of fields in the record.

QSqlField* QSqlRecord::field ( inti )

Returns a pointer to the field at position i within the
record, or 0 if it cannot be found.

QSqlField* QSqlRecord::field ( constQString&name )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns a pointer to the field with name name within the
record, or 0 if it cannot be found. Field names are not
case-sensitive.

constQSqlField* QSqlRecord::field ( inti ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

constQSqlField* QSqlRecord::field ( constQString&name ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns a pointer to the field with name name within the
record, or 0 if it cannot be found. Field names are not
case-sensitive.

QString QSqlRecord::fieldName ( inti ) const

Returns the name of the field at position i. If the field does
not exist, QString::null is returned.

void QSqlRecord::insert ( intpos, constQSqlField&field ) [virtual]

Insert a copy of field at position pos. If a field
already exists at pos, it is removed.

bool QSqlRecord::isEmpty () const

Returns TRUE if there are no fields in the record, otherwise
returns FALSE.

bool QSqlRecord::isGenerated ( constQString&name ) const

Returns TRUE if the field name is to be generated (the
default), otherwise returns FALSE. If the field does not exist,
FALSE is returned.

See also setGenerated().

bool QSqlRecord::isGenerated ( inti ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if the field with the index i is to be generated
(the default), otherwise returns FALSE. If the field does not exist,
FALSE is returned.

See also setGenerated().

bool QSqlRecord::isNull ( constQString&name )

Returns TRUE if the field name is currently null, otherwise returns FALSE.
If the field name doesn't exist the return value is TRUE.

See also position().

bool QSqlRecord::isNull ( inti )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if the field i is currently null, otherwise returns FALSE.
If the index i doesn't exist the return value is TRUE.

See also fieldName().

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

Sets the record equal to other.

int QSqlRecord::position ( constQString&name ) const

Returns the position of the field named 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.

void QSqlRecord::remove ( intpos ) [virtual]

Removes the field at pos. If pos does not exist, nothing
happens.

Reimplemented in QSqlCursor.

void QSqlRecord::setGenerated ( constQString&name, boolgenerated ) [virtual]

Sets the generated flag for the field 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, e.g.
by QSqlCursor.

See also isGenerated().

Reimplemented in QSqlCursor.

void QSqlRecord::setGenerated ( inti, boolgenerated ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the generated flag for the field i to generated.

See also isGenerated().

Reimplemented in QSqlCursor.

void QSqlRecord::setNull ( inti ) [virtual]

Sets the value of field i to NULL. If the field does not
exist, nothing happens.

void QSqlRecord::setNull ( constQString&name ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

void QSqlRecord::setValue ( inti, constQVariant&val ) [virtual]

Sets the value of the field at position i to val. If the
field does not exist, nothing happens.

Examples: sql/overview/extract/main.cpp, sql/overview/insert/main.cpp, sql/overview/insert2/main.cpp, sql/overview/order2/main.cpp, sql/overview/subclass5/main.cpp, sql/overview/update/main.cpp and sql/sqltable/main.cpp.

void QSqlRecord::setValue ( constQString&name, constQVariant&val ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

QString QSqlRecord::toString ( constQString&prefix = QString::null, constQString&sep = "," ) const [virtual]

Returns a list of all the record's field names as a string
separated by sep.

Note that fields which are not generated are not included (see
isGenerated() ). The returned string is suitable, for example, for
generating SQL SELECT statements. If a prefix is specified,
e.g. a table name, all fields are prefixed in the form:

"prefix. <fieldname>"

QStringList QSqlRecord::toStringList ( constQString&prefix = QString::null ) const [virtual]

Returns a list of all the record's field names, each having the
prefix prefix.

Note that fields which have generated set to FALSE are not
included. (See isGenerated() ). If prefix is supplied, e.g. a
table name, all fields are prefixed in the form:

"prefix. <fieldname>"

QVariant QSqlRecord::value ( inti ) const [virtual]

Returns the value of the field located at position i in the
record. If field i does not exist the resultant behaviour is
undefined.

This function should be used with QSqlQuerys. When working with a
QSqlCursor the value(const QString&) overload which uses field names
is more appropriate.

Example: sql/overview/update/main.cpp.

QVariant QSqlRecord::value ( constQString&name ) const [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the value of the field named name in the record. If
field name does not exist the resultant behaviour is undefined.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文