Qt 4.8
|
The QSqlField class manipulates the fields in SQL database tables and views. More...
#include <qsqlfield.h>
Public Types | |
enum | RequiredStatus { Unknown = -1, Optional = 0, Required = 1 } |
Specifies whether the field is required or optional. More... | |
Public Functions | |
void | clear () |
Clears the value of the field and sets it to NULL. More... | |
QVariant | defaultValue () const |
Returns the field's default value (which may be NULL). More... | |
bool | isAutoValue () const |
Returns true if the value is auto-generated by the database, for example auto-increment primary key values. More... | |
bool | isGenerated () const |
Returns true if the field is generated; otherwise returns false. More... | |
bool | isNull () const |
Returns true if the field's value is NULL; otherwise returns false. More... | |
bool | isReadOnly () const |
Returns true if the field's value is read-only; otherwise returns false. More... | |
bool | isValid () const |
Returns true if the field's variant type is valid; otherwise returns false. More... | |
int | length () const |
Returns the field's length. More... | |
QString | name () const |
Returns the name of the field. More... | |
bool | operator!= (const QSqlField &other) const |
Returns true if the field is unequal to other; otherwise returns false. More... | |
QSqlField & | operator= (const QSqlField &other) |
Sets the field equal to other. More... | |
bool | operator== (const QSqlField &other) const |
Returns true if the field is equal to other; otherwise returns false. More... | |
int | precision () const |
Returns the field's precision; this is only meaningful for numeric types. More... | |
QSqlField (const QString &fieldName=QString(), QVariant::Type type=QVariant::Invalid) | |
Constructs an empty field called fieldName of variant type type. More... | |
QSqlField (const QSqlField &other) | |
Constructs a copy of other. More... | |
RequiredStatus | requiredStatus () const |
Returns true if this is a required field; otherwise returns false. More... | |
void | setAutoValue (bool autoVal) |
Marks the field as an auto-generated value if autoVal is true. More... | |
void | setDefaultValue (const QVariant &value) |
Sets the default value used for this field to value. More... | |
void | setGenerated (bool gen) |
Sets the generated state. More... | |
void | setLength (int fieldLength) |
Sets the field's length to fieldLength. More... | |
void | setName (const QString &name) |
Sets the name of the field to name. More... | |
void | setPrecision (int precision) |
Sets the field's precision. More... | |
void | setReadOnly (bool readOnly) |
Sets the read only flag of the field's value to readOnly. More... | |
void | setRequired (bool required) |
Sets the required status of this field to Required if required is true; otherwise sets it to Optional . More... | |
void | setRequiredStatus (RequiredStatus status) |
Sets the required status of this field to required. More... | |
void | setSqlType (int type) |
void | setType (QVariant::Type type) |
Set's the field's variant type to type. More... | |
void | setValue (const QVariant &value) |
Sets the value of the field to value. More... | |
QVariant::Type | type () const |
Returns the field's type as stored in the database. More... | |
int | typeID () const |
Returns the type ID for the field. More... | |
QVariant | value () const |
Returns the value of the field as a QVariant. More... | |
~QSqlField () | |
Destroys the object and frees any allocated resources. More... | |
Private Functions | |
void | detach () |
Properties | |
QSqlFieldPrivate * | d |
QVariant | val |
The QSqlField class manipulates the fields in SQL database tables and views.
QSqlField represents the characteristics of a single column in a database table or view, such as the data type and column name. A field also contains the value of the database column, which can be viewed or changed.
Field data values are stored as QVariants. Using an incompatible type is not permitted. For example:
However, the field will attempt to cast certain data types to the field data type where possible:
QSqlField objects are rarely created explicitly in application code. They are usually accessed indirectly through QSqlRecord that already contain a list of fields. For example:
...
A QSqlField object can provide some meta-data about the field, for example, its name(), variant type(), length(), precision(), defaultValue(), typeID(), and its requiredStatus(), isGenerated() and isReadOnly(). The field's data can be checked to see if it isNull(), and its value() retrieved. When editing the data can be set with setValue() or set to NULL with clear().
Definition at line 56 of file qsqlfield.h.
Specifies whether the field is required or optional.
Enumerator | |
---|---|
Unknown | |
Optional | |
Required |
Definition at line 59 of file qsqlfield.h.
QSqlField::QSqlField | ( | const QString & | fieldName = QString() , |
QVariant::Type | type = QVariant::Invalid |
||
) |
Constructs an empty field called fieldName of variant type type.
Definition at line 168 of file qsqlfield.cpp.
QSqlField::QSqlField | ( | const QSqlField & | other | ) |
QSqlField::~QSqlField | ( | ) |
Destroys the object and frees any allocated resources.
Definition at line 219 of file qsqlfield.cpp.
void QSqlField::clear | ( | void | ) |
Clears the value of the field and sets it to NULL.
If the field is read-only, nothing happens.
Definition at line 334 of file qsqlfield.cpp.
Referenced by QSqlResult::exec(), and qCreateParamString().
QVariant QSqlField::defaultValue | ( | ) | const |
Returns the field's default value (which may be NULL).
Definition at line 481 of file qsqlfield.cpp.
Referenced by operator<<().
|
private |
Definition at line 433 of file qsqlfield.cpp.
bool QSqlField::isAutoValue | ( | ) | const |
Returns true if the value is auto-generated by the database, for example auto-increment primary key values.
Definition at line 564 of file qsqlfield.cpp.
bool QSqlField::isGenerated | ( | ) | const |
Returns true if the field is generated; otherwise returns false.
Definition at line 508 of file qsqlfield.cpp.
Referenced by operator<<().
bool QSqlField::isNull | ( | ) | const |
Returns true if the field's value is NULL; otherwise returns false.
Definition at line 428 of file qsqlfield.cpp.
Referenced by QDB2Driver::formatValue(), QSqlDriver::formatValue(), QTDSDriver::formatValue(), QMYSQLDriver::formatValue(), QODBCDriver::formatValue(), and QPSQLDriver::formatValue().
bool QSqlField::isReadOnly | ( | ) | const |
Returns true if the field's value is read-only; otherwise returns false.
Definition at line 419 of file qsqlfield.cpp.
bool QSqlField::isValid | ( | ) | const |
Returns true if the field's variant type is valid; otherwise returns false.
Definition at line 517 of file qsqlfield.cpp.
Referenced by QDB2Result::data(), and QSqlTableModel::orderByClause().
int QSqlField::length | ( | ) | const |
Returns the field's length.
If the returned value is negative, it means that the information is not available from the database.
Definition at line 457 of file qsqlfield.cpp.
Referenced by QDB2Result::data(), QODBCResult::data(), and operator<<().
QString QSqlField::name | ( | ) | const |
Returns the name of the field.
Definition at line 380 of file qsqlfield.cpp.
Referenced by QSqlRecordPrivate::createField(), QSqlIndex::createField(), operator<<(), and QSqlTableModel::orderByClause().
|
inline |
Returns true if the field is unequal to other; otherwise returns false.
Definition at line 67 of file qsqlfield.h.
Sets the field equal to other.
Definition at line 189 of file qsqlfield.cpp.
bool QSqlField::operator== | ( | const QSqlField & | other | ) | const |
Returns true if the field is equal to other; otherwise returns false.
Definition at line 209 of file qsqlfield.cpp.
int QSqlField::precision | ( | ) | const |
Returns the field's precision; this is only meaningful for numeric types.
If the returned value is negative, it means that the information is not available from the database.
Definition at line 471 of file qsqlfield.cpp.
Referenced by operator<<().
QSqlField::RequiredStatus QSqlField::requiredStatus | ( | ) | const |
Returns true if this is a required field; otherwise returns false.
An INSERT
will fail if a required field does not have a value.
Definition at line 444 of file qsqlfield.cpp.
Referenced by operator<<().
void QSqlField::setAutoValue | ( | bool | autoVal | ) |
Marks the field as an auto-generated value if autoVal is true.
Definition at line 575 of file qsqlfield.cpp.
Referenced by qExtractSecurityPolicyFromString(), qGetTableInfo(), and qToField().
void QSqlField::setDefaultValue | ( | const QVariant & | value | ) |
Sets the default value used for this field to value.
Definition at line 276 of file qsqlfield.cpp.
Referenced by QPSQLDriver::record().
void QSqlField::setGenerated | ( | bool | gen | ) |
Sets the generated state.
If gen is false, no SQL will be generated for this field; otherwise, Qt classes such as QSqlQueryModel and QSqlTableModel will generate SQL for this field.
Definition at line 299 of file qsqlfield.cpp.
Referenced by QSqlQueryModel::insertColumns().
void QSqlField::setLength | ( | int | fieldLength | ) |
Sets the field's length to fieldLength.
For strings this is the maximum number of characters the string can hold; the meaning varies for other types.
Definition at line 254 of file qsqlfield.cpp.
Referenced by qFromOraInf(), qMakeFieldInfo(), qToField(), QIBaseResult::record(), QPSQLResult::record(), QIBaseDriver::record(), QTDSDriver::record(), QPSQLDriver::record(), and QTDSResult::reset().
void QSqlField::setName | ( | const QString & | name | ) |
Sets the name of the field to name.
Definition at line 347 of file qsqlfield.cpp.
Referenced by QPSQLResult::record().
void QSqlField::setPrecision | ( | int | precision | ) |
Sets the field's precision.
This only affects numeric fields.
Definition at line 265 of file qsqlfield.cpp.
Referenced by qFromOraInf(), qMakeFieldInfo(), qToField(), QPSQLResult::record(), QTDSDriver::record(), and QPSQLDriver::record().
void QSqlField::setReadOnly | ( | bool | readOnly | ) |
Sets the read only flag of the field's value to readOnly.
A read-only field cannot have its value set with setValue() and cannot be cleared to NULL with clear().
Definition at line 358 of file qsqlfield.cpp.
Referenced by QSqlQueryModel::insertColumns().
|
inline |
Sets the required status of this field to Required if required is true; otherwise sets it to Optional .
Definition at line 84 of file qsqlfield.h.
Referenced by qFromOraInf(), qMakeFieldInfo(), qToField(), QOCIDriver::record(), and QPSQLDriver::record().
void QSqlField::setRequiredStatus | ( | RequiredStatus | required | ) |
Sets the required status of this field to required.
Definition at line 230 of file qsqlfield.cpp.
void QSqlField::setSqlType | ( | int | type | ) |
Definition at line 285 of file qsqlfield.cpp.
Referenced by QSQLiteResultPrivate::initColumns(), qFromOraInf(), qMakeFieldInfo(), qToField(), QPSQLResult::record(), QTDSDriver::record(), QPSQLDriver::record(), and QTDSResult::reset().
void QSqlField::setType | ( | QVariant::Type | type | ) |
Set's the field's variant type to type.
Definition at line 404 of file qsqlfield.cpp.
Referenced by qCreateParamString(), and QPSQLResult::record().
void QSqlField::setValue | ( | const QVariant & | value | ) |
Sets the value of the field to value.
If the field is read-only (isReadOnly() returns true), nothing happens.
If the data type of value differs from the field's current data type, an attempt is made to cast it to the proper type. This preserves the data type of the field in the case of assignment, e.g. a QString to an integer data type.
To set the value to NULL, use clear().
Definition at line 320 of file qsqlfield.cpp.
Referenced by QSqlResult::exec(), and qCreateParamString().
QVariant::Type QSqlField::type | ( | ) | const |
Returns the field's type as stored in the database.
Note that the actual value might have a different type, Numerical values that are too large to store in a long int or double are usually stored as strings to prevent precision loss.
Definition at line 394 of file qsqlfield.cpp.
Referenced by QDB2Result::data(), QODBCResult::data(), QDB2Driver::formatValue(), QSqlDriver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QTDSDriver::formatValue(), QMYSQLDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QTDSResult::gotoNext(), operator<<(), and QSQLite2Driver::primaryIndex().
int QSqlField::typeID | ( | ) | const |
Returns the type ID for the field.
If the returned value is negative, it means that the information is not available from the database.
Definition at line 497 of file qsqlfield.cpp.
Referenced by operator<<().
|
inline |
Returns the value of the field as a QVariant.
Use isNull() to check if the field's value is NULL.
Definition at line 71 of file qsqlfield.h.
Referenced by QDB2Driver::formatValue(), QSqlDriver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QTDSDriver::formatValue(), QMYSQLDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), and QRelation::populateDictionary().
|
private |
Definition at line 108 of file qsqlfield.h.
Referenced by operator=(), operator==(), and QSqlField().
|
private |
Definition at line 107 of file qsqlfield.h.
Referenced by operator=(), operator==(), and QSqlField().