返回介绍

QSqlFieldInfo Class

发布于 2019-10-04 15:02:54 字数 7826 浏览 954 评论 0 收藏 0

The QSqlFieldInfo class stores meta data associated with a SQL field. More...

#include <qsqlfield.h>

List of all member functions.

Public Members

  • QSqlFieldInfo ( constQString&name = QString::null, QVariant::Typetyp = QVariant::Invalid, intrequired = -1, intlen = -1, intprec = -1, constQVariant&defValue = QVariant ( ), inttypeID = 0, boolgenerated = TRUE, booltrim = FALSE, boolcalculated = FALSE )
  • QSqlFieldInfo ( constQSqlFieldInfo&other )
  • QSqlFieldInfo ( constQSqlField&other, boolgenerated = TRUE )
  • virtual ~QSqlFieldInfo ()
  • QSqlFieldInfo & operator= ( constQSqlFieldInfo&other )
  • bool operator== ( constQSqlFieldInfo&f ) const
  • QSqlField toField () const
  • int isRequired () const
  • QVariant::Type type () const
  • int length () const
  • int precision () const
  • QVariant defaultValue () const
  • QString name () const
  • int typeID () const
  • bool isGenerated () const
  • bool isTrim () const
  • bool isCalculated () const
  • virtual void setTrim ( booltrim )
  • virtual void setGenerated ( boolgen )
  • virtual void setCalculated ( boolcalc )

Detailed Description

The QSqlFieldInfo class stores meta data associated with a SQL field.

QSqlFieldInfo objects only store meta data; field values are stored in QSqlField objects.

All values must be set in the constructor, and may be retrieved using isRequired(), type(), length(), precision(), defaultValue(), name(), isGenerated() and typeID().

See also Database Classes.


Member Function Documentation

QSqlFieldInfo::QSqlFieldInfo ( constQString&name = QString::null, QVariant::Typetyp = QVariant::Invalid, intrequired = -1, intlen = -1, intprec = -1, constQVariant&defValue = QVariant ( ), inttypeID = 0, boolgenerated = TRUE, booltrim = FALSE, boolcalculated = FALSE )

Constructs a QSqlFieldInfo with the following parameters:
  • name the name of the field.
  • typ the field's type in a QVariant.
  • required greater than 0 if the field is required, 0 if its value can be NULL and less than 0 if it cannot be determined whether the field is required or not.
  • len the length of the field. Note that for non-character types some databases return either the length in bytes or the number of digits. -1 signifies that the length cannot be determined.
  • prec the precision of the field, or -1 if the field has no precision or it cannot be determined.
  • defValue the default value that is inserted into the table if none is specified by the user. QVariant() if there is no default value or it cannot be determined.
  • typeID the internal typeID of the database system (only useful for low-level programming). 0 if unknown.
  • generated TRUE indicates that this field should be included in auto-generated SQL statments, e.g. in QSqlCursor.
  • trim TRUE indicates that widgets should remove trailing whitespace from character fields. This does not affect the field value but only its representation inside widgets.
  • calculated TRUE indicates that the value of this field is calculated. The value of calculated fields can by modified by subclassing QSqlCursor and overriding QSqlCursor::calculateField().

QSqlFieldInfo::QSqlFieldInfo ( constQSqlFieldInfo&other )

Constructs a copy of other.

QSqlFieldInfo::QSqlFieldInfo ( constQSqlField&other, boolgenerated = TRUE )

Creates a QSqlFieldInfo object with the type and the name of the QSqlField other. If generated is TRUE this field will be included in auto-generated SQL statments, e.g. in QSqlCursor.

QSqlFieldInfo::~QSqlFieldInfo () [virtual]

Destroys the object and frees any allocated resources.

QVariant QSqlFieldInfo::defaultValue () const

Returns the default value of this field or an empty QVariant if the field has no default value or the value couldn't be determined. The default value is the value inserted in the database when it was not explicitly specified by the user.

bool QSqlFieldInfo::isCalculated () const

Returns TRUE if the field is calculated.

See also setCalculated().

bool QSqlFieldInfo::isGenerated () const

Returns TRUE if this field should be included in auto-generated SQL statments, e.g. in QSqlCursor; otherwise returns FALSE.

See also setGenerated().

int QSqlFieldInfo::isRequired () const

Returns a value greater than 0 if the field is required (NULL values are not allowed), 0 if it isn't required (NULL values are allowed) or less than 0 if it cannot be determined whether the field is required or not.

bool QSqlFieldInfo::isTrim () const

Returns TRUE if trailing whitespace should be removed from character fields.

See also setTrim().

int QSqlFieldInfo::length () const

Returns the length of this field. For fields storing text the return value is the maximum number of characters the field can hold. For non-character fields some database systems return the number of bytes needed or the number of digits allowed. If the length cannot be determined -1 is returned.

QString QSqlFieldInfo::name () const

Returns the name of the field in the SQL table.

Examples: sql/overview/subclass3/main.cpp and sql/overview/subclass4/main.cpp.

QSqlFieldInfo& QSqlFieldInfo::operator= ( constQSqlFieldInfo&other )

Assigns other to this field info and returns a reference to it.

bool QSqlFieldInfo::operator== ( constQSqlFieldInfo&f ) const

Returns TRUE if this fieldinfo is equal to f; otherwise returns FALSE.

Two field infos are considered equal when all their attributes match.

int QSqlFieldInfo::precision () const

Returns the precision of this field or -1 if the field has no precision or it cannot be determined.

void QSqlFieldInfo::setCalculated ( boolcalc ) [virtual]

calc set to TRUE indicates that this field is a calculated field. The value of calculated fields can by modified by subclassing QSqlCursor and overriding QSqlCursor::calculateField().

See also isCalculated().

void QSqlFieldInfo::setGenerated ( boolgen ) [virtual]

gen set to FALSE indicates that this field should not appear in auto-generated SQL statements (for example in QSqlCursor).

See also isGenerated().

void QSqlFieldInfo::setTrim ( booltrim ) [virtual]

If trim is TRUE widgets should remove trailing whitespace from character fields. This does not affect the field value but only its representation inside widgets.

See also isTrim().

QSqlField QSqlFieldInfo::toField () const

Returns an empty QSqlField based on the information in this QSqlFieldInfo.

QVariant::Type QSqlFieldInfo::type () const

Returns the type of this field or QVariant::Invalid if the type is unknown.

int QSqlFieldInfo::typeID () const

Returns the internal type identifier as returned from the database system. The return value is 0 if the type is unknown.

Warning: This information is only useful for low-level database programming and is not database independent.

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

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

发布评论

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