CopperSpice API
1.9.2
|
The QSqlField class manipulates the fields in SQL database tables and views. More...
Public Types | |
enum | RequiredStatus |
Public Methods | |
QSqlField (const QSqlField &other) | |
QSqlField (const QString &fieldName=QString (), QVariant::Type type=QVariant::Invalid) | |
~QSqlField () | |
void | clear () |
QVariant | defaultValue () const |
bool | isAutoValue () const |
bool | isGenerated () const |
bool | isNull () const |
bool | isReadOnly () const |
bool | isValid () const |
int | length () const |
QString | name () const |
bool | operator!= (const QSqlField &other) const |
QSqlField & | operator= (const QSqlField &other) |
bool | operator== (const QSqlField &other) const |
int | precision () const |
RequiredStatus | requiredStatus () const |
void | setAutoValue (bool autoVal) |
void | setDefaultValue (const QVariant &value) |
void | setGenerated (bool gen) |
void | setLength (int fieldLength) |
void | setName (const QString &name) |
void | setPrecision (int precision) |
void | setReadOnly (bool readOnly) |
void | setRequired (bool status) |
void | setRequiredStatus (RequiredStatus status) |
void | setType (QVariant::Type type) |
void | setValue (const QVariant &value) |
QVariant::Type | type () const |
QVariant | value () const |
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 QVariant. Using an incompatible type is not permitted.
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 QSqlRecords that already contain a list of fields.
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().
Specifies whether the field is required or optional.
Constant | Value | Description |
---|---|---|
QSqlField::Required | 1 | Field must be specified when inserting records. |
QSqlField::Optional | 0 | Field does not have to be specified when inserting records. |
QSqlField::Unknown | -1 | Database driver could not determine whether the field is required or optional. |
QSqlField::QSqlField | ( | const QString & | fieldName = QString() , |
QVariant::Type | type = QVariant::Invalid |
||
) |
Constructs an empty field called fieldName of variant type.
QSqlField::QSqlField | ( | const QSqlField & | other | ) |
Constructs a copy of other.
QSqlField::~QSqlField | ( | ) |
Destroys the object and frees any allocated resources.
void QSqlField::clear | ( | ) |
Clears the value of the field and sets it to NULL. If the field is read-only, nothing happens.
QVariant QSqlField::defaultValue | ( | ) | const |
Returns the field's default value (which may be NULL).
bool QSqlField::isAutoValue | ( | ) | const |
Returns true if the value is auto-generated by the database, for example auto-increment primary key values.
bool QSqlField::isGenerated | ( | ) | const |
Returns true if the field is generated, otherwise returns false.
bool QSqlField::isNull | ( | ) | const |
Returns true if the field's value is NULL, otherwise returns false.
bool QSqlField::isReadOnly | ( | ) | const |
Returns true if the field's value is read-only, otherwise returns false.
bool QSqlField::isValid | ( | ) | const |
Returns true if the field's variant type is valid, otherwise returns false.
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.
|
inline |
Returns true if the field is unequal to other, otherwise returns false.
QSqlField & QSqlField::operator= | ( | const QSqlField & | other | ) |
Sets the field equal to other.
bool QSqlField::operator== | ( | const QSqlField & | other | ) | const |
Returns true if the field is equal to other, otherwise returns false.
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.
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.
void QSqlField::setAutoValue | ( | bool | autoVal | ) |
Marks the field as an auto-generated value if autoVal is true.
void QSqlField::setDefaultValue | ( | const QVariant & | value | ) |
Sets the default value used for this field to value.
void QSqlField::setGenerated | ( | bool | gen | ) |
Sets the generated state. If gen is false, no SQL will be generated for this field, otherwise, CopperSpice classes such as QSqlQueryModel and QSqlTableModel will generate SQL for this field.
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.
void QSqlField::setPrecision | ( | int | precision | ) |
Sets the field's precision. This only affects numeric fields.
void QSqlField::setReadOnly | ( | bool | readOnly | ) |
Sets the read only flag of the field's value to readOnly. A read-only field can not have its value set with setValue() and can not be cleared to NULL with clear().
|
inline |
Sets the required status of this field to Required if status is true, otherwise sets it to Optional.
void QSqlField::setRequiredStatus | ( | RequiredStatus | status | ) |
Sets the required status of this field to status.
void QSqlField::setType | ( | QVariant::Type | type | ) |
Set's the field's variant type to type.
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().
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.
|
inline |
Returns the value of the field as a QVariant.
Use isNull() to check if the field's value is NULL.