com.trolltech.qt.sql
Class QSqlField

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.sql.QSqlField
All Implemented Interfaces:
QtJambiInterface

public class QSqlField
extends QtJambiObject

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.

See Also:
QSqlRecord

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)
          This method is used internally by Qt Jambi.
 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()
          This method is used internally by Qt Jambi.
 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

QSqlField

public QSqlField(java.lang.String fieldName)

Equivalent to QSqlField(fieldName, QVariant::Invalid).


QSqlField

public QSqlField()

Equivalent to QSqlField(QString(), QVariant::Invalid).


QSqlField

public QSqlField(java.lang.String fieldName,
                 int type)

Constructs an empty field called fieldName of variant type type.

See Also:
setRequiredStatus, setLength, setPrecision, setDefaultValue, setGenerated, setReadOnly

QSqlField

public QSqlField(QSqlField other)

Constructs a copy of other.

Method Detail

clear

public final void clear()

Clears the value of the field and sets it to NULL. If the field is read-only, nothing happens.

See Also:
setValue, isReadOnly, requiredStatus

defaultValue

public final java.lang.Object defaultValue()

Returns the field's default value (which may be NULL).

See Also:
setDefaultValue, type, requiredStatus, length, precision, isGenerated

isAutoValue

public final boolean isAutoValue()

Returns true if the value is auto-generated by the database, for example auto-increment primary key values.

See Also:
setAutoValue

isGenerated

public final boolean isGenerated()

Returns true if the field is generated; otherwise returns false.

See Also:
setGenerated, type, requiredStatus, length, precision, defaultValue

isNull

public final boolean isNull()

Returns true if the field's value is NULL; otherwise returns false.

See Also:
value

isReadOnly

public final boolean isReadOnly()

Returns true if the field's value is read-only; otherwise returns false.

See Also:
setReadOnly, type, requiredStatus, length, precision, defaultValue, isGenerated

isValid

public final boolean isValid()

Returns true if the field's variant type is valid; otherwise returns false.


length

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.

See Also:
setLength, type, requiredStatus, precision, defaultValue, isGenerated

name

public final java.lang.String name()

Returns the name of the field.

See Also:
setName

precision

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.

See Also:
setPrecision, type, requiredStatus, length, defaultValue, isGenerated

requiredStatus

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.

See Also:
setRequiredStatus, type, length, precision, defaultValue, isGenerated

setAutoValue

public final void setAutoValue(boolean autoVal)

Marks the field as an auto-generated value if autoVal is true.

See Also:
isAutoValue

setDefaultValue

public final void setDefaultValue(java.lang.Object value)

Sets the default value used for this field to value.

See Also:
defaultValue, value, setType, setRequiredStatus, setLength, setPrecision, setGenerated, setReadOnly

setGenerated

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.

See Also:
isGenerated, setType, setRequiredStatus, setLength, setPrecision, setDefaultValue, setReadOnly

setLength

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.

See Also:
length, setType, setRequiredStatus, setPrecision, setDefaultValue, setGenerated, setReadOnly

setName

public final void setName(java.lang.String name)

Sets the name of the field to name.

See Also:
name

setPrecision

public final void setPrecision(int precision)

Sets the field's precision. This only affects numeric fields.

See Also:
precision, setType, setRequiredStatus, setLength, setDefaultValue, setGenerated, setReadOnly

setReadOnly

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.

See Also:
isReadOnly

setRequired

public final void setRequired(boolean required)

Sets the required status of this field to Required if required is true; otherwise sets it to Optional.

See Also:
setRequiredStatus, requiredStatus

setRequiredStatus

public final void setRequiredStatus(QSqlField.RequiredStatus status)

Sets the required status of this field to status.

See Also:
requiredStatus, setType, setLength, setPrecision, setDefaultValue, setGenerated, setReadOnly

setSqlType

public final void setSqlType(int type)

This method is used internally by Qt Jambi. Do not use it in your applications.


setType

public final void setType(int type)

Set's the field's variant type to type.

See Also:
type, setRequiredStatus, setLength, setPrecision, setDefaultValue, setGenerated, setReadOnly

setValue

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.

See Also:
value, isReadOnly, defaultValue

type

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.

See Also:
setType

typeID

public final int typeID()

This method is used internally by Qt Jambi. Do not use it in your applications.


value

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.

See Also:
setValue

fromNativePointer

public static QSqlField fromNativePointer(QNativePointer nativePointer)
This function returns the QSqlField instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

nativePointerArray

public static QNativePointer nativePointerArray(QSqlField[] array)
This function returns a QNativePointer that is pointing to the specified QSqlField array.

Parameters:
array - the array that the returned pointer will point to.
Returns:
a QNativePointer that is pointing to the specified array.

equals

public boolean equals(java.lang.Object other)

Overrides:
equals in class java.lang.Object