|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.sql.QSqlField
public class QSqlField
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:
QSqlField field("age", QVariant::Int);
field.setValue(QPixmap()); // WRONG
However, the field will attempt to cast certain data types to the field data type where possible:
QSqlField field("age", QVariant::Int);
field.setValue(QString("123")); // casts QString to int
QSqlField objects are rarely created explicitly in application code. They are usually accessed indirectly through QSqlRecords that already contain a list of fields. For example:
QSqlQuery query; ... QSqlRecord record = query.record(); QSqlField field = record.field("country");
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.
Nested Class Summary | |
---|---|
static class |
QSqlField.RequiredStatus
Specifies whether the field is required or optional. |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Constructor Summary | |
---|---|
QSqlField()
Equivalent to QSqlField(QString(), QVariant::Invalid). |
|
QSqlField(QSqlField other)
Constructs a copy of other. |
|
QSqlField(java.lang.String fieldName)
Equivalent to QSqlField(fieldName, QVariant::Invalid). |
|
QSqlField(java.lang.String fieldName,
int type)
Constructs an empty field called fieldName of variant type type. |
Method Summary | |
---|---|
void |
clear()
Clears the value of the field and sets it to NULL. |
java.lang.Object |
defaultValue()
Returns the field's default value (which may be NULL). |
boolean |
equals(java.lang.Object other)
|
static QSqlField |
fromNativePointer(QNativePointer nativePointer)
This function returns the QSqlField instance pointed to by nativePointer |
boolean |
isAutoValue()
Returns true if the value is auto-generated by the database, for example auto-increment primary key values. |
boolean |
isGenerated()
Returns true if the field is generated; otherwise returns false. |
boolean |
isNull()
Returns true if the field's value is NULL; otherwise returns false. |
boolean |
isReadOnly()
Returns true if the field's value is read-only; otherwise returns false. |
boolean |
isValid()
Returns true if the field's variant type is valid; otherwise returns false. |
int |
length()
Returns the field's length. |
java.lang.String |
name()
Returns the name of the field. |
static QNativePointer |
nativePointerArray(QSqlField[] array)
This function returns a QNativePointer that is pointing to the specified QSqlField array. |
int |
precision()
Returns the field's precision; this is only meaningful for numeric types. |
QSqlField.RequiredStatus |
requiredStatus()
Returns true if this is a required field; otherwise returns false. |
void |
setAutoValue(boolean autoVal)
Marks the field as an auto-generated value if autoVal is true. |
void |
setDefaultValue(java.lang.Object value)
Sets the default value used for this field to value. |
void |
setGenerated(boolean gen)
Sets the generated state. |
void |
setLength(int fieldLength)
Sets the field's length to fieldLength. |
void |
setName(java.lang.String name)
Sets the name of the field to name. |
void |
setPrecision(int precision)
Sets the field's precision. |
void |
setReadOnly(boolean readOnly)
Sets the read only flag of the field's value to readOnly. |
void |
setRequired(boolean required)
Sets the required status of this field to Required if required is true; otherwise sets it to Optional. |
void |
setRequiredStatus(QSqlField.RequiredStatus status)
Sets the required status of this field to status. |
void |
setSqlType(int type)
|
void |
setType(int type)
Set's the field's variant type to type. |
void |
setValue(java.lang.Object value)
Sets the value of the field to value. |
int |
type()
Returns the field's type as stored in the database. |
int |
typeID()
|
java.lang.Object |
value()
Returns the value of the field as a QVariant. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QSqlField(java.lang.String fieldName)
Equivalent to QSqlField(fieldName, QVariant::Invalid).
public QSqlField()
Equivalent to QSqlField(QString(), QVariant::Invalid).
public QSqlField(java.lang.String fieldName, int type)
Constructs an empty field called fieldName of variant type type.
public QSqlField(QSqlField other)
Constructs a copy of other.
Method Detail |
---|
public final void clear()
Clears the value of the field and sets it to NULL. If the field is read-only, nothing happens.
public final java.lang.Object defaultValue()
Returns the field's default value (which may be NULL).
public final boolean isAutoValue()
Returns true if the value is auto-generated by the database, for example auto-increment primary key values.
public final boolean isGenerated()
Returns true if the field is generated; otherwise returns false.
public final boolean isNull()
Returns true if the field's value is NULL; otherwise returns false.
public final boolean isReadOnly()
Returns true if the field's value is read-only; otherwise returns false.
public final boolean isValid()
Returns true if the field's variant type is valid; otherwise returns false.
public final int length()
Returns the field's length.
If the returned value is negative, it means that the information is not available from the database.
public final java.lang.String name()
Returns the name of the field.
public final int precision()
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.
public final QSqlField.RequiredStatus requiredStatus()
Returns true if this is a required field; otherwise returns false. An INSERT will fail if a required field does not have a value.
public final void setAutoValue(boolean autoVal)
Marks the field as an auto-generated value if autoVal is true.
public final void setDefaultValue(java.lang.Object value)
Sets the default value used for this field to value.
public final void setGenerated(boolean 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.
public final void 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.
public final void setName(java.lang.String name)
Sets the name of the field to name.
public final void setPrecision(int precision)
Sets the field's precision. This only affects numeric fields.
public final void setReadOnly(boolean 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.
public final void setRequired(boolean required)
Sets the required status of this field to Required if required is true; otherwise sets it to Optional.
public final void setRequiredStatus(QSqlField.RequiredStatus status)
Sets the required status of this field to status.
public final void setSqlType(int type)
public final void setType(int type)
Set's the field's variant type to type.
public final void setValue(java.lang.Object 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.
public final int type()
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.
public final int typeID()
public final java.lang.Object value()
Returns the value of the field as a QVariant.
Use isNull to check if the field's value is NULL.
public static QSqlField fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public static QNativePointer nativePointerArray(QSqlField[] array)
array
- the array that the returned pointer will point to.
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |