|
|||||||||
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 = new QSqlField("age"); field.setValue(new QPixmap()); // WRONGHowever, 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()
. 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, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
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). |
static QSqlField |
fromNativePointer(QNativePointer 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)
|
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()
|
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 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 |
---|
public QSqlField(QSqlField other)
public QSqlField(java.lang.String fieldName)
setRequiredStatus()
, setLength()
, setPrecision()
, setDefaultValue()
, setGenerated()
, and setReadOnly()
.
public QSqlField()
setRequiredStatus()
, setLength()
, setPrecision()
, setDefaultValue()
, setGenerated()
, and setReadOnly()
.
public QSqlField(java.lang.String fieldName, int type)
setRequiredStatus()
, setLength()
, setPrecision()
, setDefaultValue()
, setGenerated()
, and setReadOnly()
.
Method Detail |
---|
public final void clear()
setValue()
, isReadOnly()
, and requiredStatus()
.
public final java.lang.Object defaultValue()
setDefaultValue()
, type()
, requiredStatus()
, length()
, precision()
, and isGenerated()
.
public final boolean isAutoValue()
setAutoValue()
.
public final boolean isGenerated()
setGenerated()
, type()
, requiredStatus()
, length()
, precision()
, and defaultValue()
.
public final boolean isNull()
value()
.
public final boolean isReadOnly()
setReadOnly()
, type()
, requiredStatus()
, length()
, precision()
, defaultValue()
, and isGenerated()
.
public final boolean isValid()
public final int length()
If the returned value is negative, it means that the information is not available from the database.
setLength()
, type()
, requiredStatus()
, precision()
, defaultValue()
, and isGenerated()
.
public final java.lang.String name()
setName()
.
public final int precision()
If the returned value is negative, it means that the information is not available from the database.
setPrecision()
, type()
, requiredStatus()
, length()
, defaultValue()
, and isGenerated()
.
public final QSqlField.RequiredStatus requiredStatus()
setRequiredStatus()
, type()
, length()
, precision()
, defaultValue()
, and isGenerated()
.
public final void setAutoValue(boolean autoVal)
isAutoValue()
.
public final void setDefaultValue(java.lang.Object value)
defaultValue()
, value()
, setType()
, setRequiredStatus()
, setLength()
, setPrecision()
, setGenerated()
, and setReadOnly()
.
public final void setGenerated(boolean gen)
QSqlQueryModel
and QSqlTableModel
will generate SQL for this field. isGenerated()
, setType()
, setRequiredStatus()
, setLength()
, setPrecision()
, setDefaultValue()
, and setReadOnly()
.
public final void setLength(int fieldLength)
length()
, setType()
, setRequiredStatus()
, setPrecision()
, setDefaultValue()
, setGenerated()
, and setReadOnly()
.
public final void setName(java.lang.String name)
name()
.
public final void setPrecision(int precision)
precision()
, setType()
, setRequiredStatus()
, setLength()
, setDefaultValue()
, setGenerated()
, and setReadOnly()
.
public final void setReadOnly(boolean readOnly)
setValue()
and cannot be cleared to NULL with clear()
. isReadOnly()
.
public final void setRequired(boolean required)
Required
if required is true; otherwise sets it to Optional
. setRequiredStatus()
, and requiredStatus()
.
public final void setRequiredStatus(QSqlField.RequiredStatus status)
requiredStatus()
, setType()
, setLength()
, setPrecision()
, setDefaultValue()
, setGenerated()
, and setReadOnly()
.
public final void setType(int type)
type()
, setRequiredStatus()
, setLength()
, setPrecision()
, setDefaultValue()
, setGenerated()
, and setReadOnly()
.
public final void setValue(java.lang.Object value)
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()
.
value()
, isReadOnly()
, and defaultValue()
.
public final int type()
setType()
.
public final java.lang.Object value()
QVariant
. Use isNull()
to check if the field's value is NULL.
setValue()
.
public static QSqlField fromNativePointer(QNativePointer nativePointer)
public static QNativePointer nativePointerArray(QSqlField[] array)
public java.lang.String toString()
toString
in class java.lang.Object
public QSqlField clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |