Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.sql
Class QSqlField

    java.lang.Object
      com.trolltech.qt.internal.QSignalEmitterInternal
          com.trolltech.qt.QSignalEmitter
              com.trolltech.qt.QtJambiObject
                  com.trolltech.qt.sql.QSqlField

All Implemented Interfaces:
  QtJambiInterface, java.lang.Cloneable

    public class QSqlField

extends QtJambiObject
implements java.lang.Cloneable

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 = new QSqlField("age");
            field.setValue(new QPixmap());  // WRONG

However, the field will attempt to cast certain data types to the field data type where possible:

            QSqlField field = new QSqlField("age");
            field.setValue("123");  // casts String to int

`QSqlField` objects are rarely created explicitly in application code. They are usually accessed indirectly through `QSqlRecord`s that already contain a list of fields. For example:

            QSqlQuery query = new QSqlQuery();
        ...
            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.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal`

Field Summary

Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`currentSender`

Constructor Summary
`QSqlField()` Constructs an empty field called `fieldName` of variant type `type`.
`QSqlField(QSqlField other)` Constructs a copy of `other`.
`QSqlField(java.lang.String fieldName)` Constructs an empty field called `fieldName` of variant type `type`.
`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.
`QSqlField` | `clone()` This method is reimplemented for internal reasons
`java.lang.Object` | `defaultValue()` Returns the field's default value (which may be NULL).
`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.
`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 `required`.
`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`.
`java.lang.String` | `toString()` Returns a string representation of the `this QSqlField`.
`int` | `type()` Returns the field's type as stored in the database.
`java.lang.Object` | `value()` Returns the value of the field as a `QVariant`.

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`__qt_signalInitialization`

Methods inherited from class java.lang.Object
`getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Constructor Detail

### QSqlField

    public QSqlField(QSqlField other)

  Constructs a copy of `other`.

### QSqlField

    public QSqlField(java.lang.String fieldName)

  Constructs an empty field called `fieldName` of variant type `type`.

See also:
  `setRequiredStatus()`, `setLength()`, `setPrecision()`, `setDefaultValue()`, `setGenerated()`, and `setReadOnly()`.

### QSqlField

    public QSqlField()

  Constructs an empty field called `fieldName` of variant type `type`.

See also:
  `setRequiredStatus()`, `setLength()`, `setPrecision()`, `setDefaultValue()`, `setGenerated()`, and `setReadOnly()`.

### 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()`, and `setReadOnly()`.

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()`, and `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()`, and `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()`, and `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()`, and `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()`, and `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()`, and `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()`, and `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()`, and `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()`, and `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()`, and `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()`, and `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()`, and `requiredStatus()`.

### setRequiredStatus

    public final void setRequiredStatus(QSqlField.RequiredStatus status)

  Sets the required status of this field to `required`.

See also:
  `requiredStatus()`, `setType()`, `setLength()`, `setPrecision()`, `setDefaultValue()`, `setGenerated()`, and `setReadOnly()`.

### setType

    public final void setType(int type)

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

See also:
  `type()`, `setRequiredStatus()`, `setLength()`, `setPrecision()`, `setDefaultValue()`, `setGenerated()`, and `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()`, and `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()`.

### 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()`.

### toString

    public java.lang.String toString()

  Returns a string representation of the `this QSqlField`.

  Overrides:
    `toString` in class `java.lang.Object`

### clone

    public QSqlField clone()

  This method is reimplemented for internal reasons

  Overrides:
    `clone` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD