The DatabaseFieldOptions object defines additional options for a database field represented by a DataObject <object_DataObject>
. It can be set through attached properties or instantiated as an arbitrarily-named custom property of the corresponding DataObject <object_DataObject>
. See the example for details.
This object was introduced in InCore 1.1.
- › Inherits
Object <object_Object>
autoIncrement <property_DatabaseFieldOptions_autoIncrement>
blank <property_DatabaseFieldOptions_blank>
dbColumn <property_DatabaseFieldOptions_dbColumn>
dbIndex <property_DatabaseFieldOptions_dbIndex>
maxLength <property_DatabaseFieldOptions_maxLength>
notNull <property_DatabaseFieldOptions_notNull>
onDelete <property_DatabaseFieldOptions_onDelete>
primaryKey <property_DatabaseFieldOptions_primaryKey>
unique <property_DatabaseFieldOptions_unique>
Object.objectId <property_Object_objectId>
Object.parent <property_Object_parent>
Object.deserializeProperties() <method_Object_deserializeProperties>
Object.fromJson() <method_Object_fromJson>
Object.serializeProperties() <method_Object_serializeProperties>
Object.toJson() <method_Object_toJson>
Object.completed() <signal_Object_completed>
ForeignKeyConstraint <enum_DatabaseFieldOptions_ForeignKeyConstraint>
single: autoIncrement
This property holds whether this field should be marked as auto-increment if this field is the primary key as well.
- › Type
Boolean
- › Default
false
- › Signal
autoIncrementChanged()
- › Attributes
Writable
single: blank
This property holds whether to allow this field to be empty when inserting a new data row.
- › Type
Boolean
- › Default
false
- › Signal
blankChanged()
- › Attributes
Writable
single: dbColumn
This property holds the name of the database column for the field, otherwise per default the object ID is be used.
- › Type
String
- › Signal
dbColumnChanged()
- › Attributes
Writable
single: dbIndex
This property holds whether to create an index on this field.
- › Type
Boolean
- › Default
false
- › Signal
dbIndexChanged()
- › Attributes
Writable
single: maxLength
This property holds the maximum length of the field used when creating the database table. Leave at 0
to disable a maximum length.
- › Type
SignedInteger
- › Default
0
- › Signal
maxLengthChanged()
- › Attributes
Writable
single: notNull
This property holds whether to insert empty values or NULL
values if the field value is empty or not specified.
- › Type
Boolean
- › Default
true
- › Signal
notNullChanged()
- › Attributes
Writable
single: onDelete
This property holds the foreign key constraint to create on this field. See SQL Server Foreign Key Update and Delete Rules and the ForeignKeyConstraint <enum_DatabaseFieldOptions_ForeignKeyConstraint>
enumeration for details.
- › Type
ForeignKeyConstraint <enum_DatabaseFieldOptions_ForeignKeyConstraint>
- › Default
DatabaseFieldOptions.NoAction <enumitem_DatabaseFieldOptions_NoAction>
- › Signal
onDeleteChanged()
- › Attributes
Writable
single: primaryKey
This property holds whether to use this field as the primary key. If no primary key is explicitly defined, an auto-increment integer field will be added.
- › Type
Boolean
- › Default
false
- › Signal
primaryKeyChanged()
- › Attributes
Writable
single: unique
This property holds whether this field must be unique throughout the table.
- › Type
Boolean
- › Default
false
- › Signal
uniqueChanged()
- › Attributes
Writable
single: ForeignKeyConstraint
This enumeration describes all possible constraints which can be set for foreign keys.
single: DatabaseFieldOptions.NoAction
single: DatabaseFieldOptions.Restrict
single: DatabaseFieldOptions.Cascade
single: DatabaseFieldOptions.SetNull
Name | Value | Description |
---|---|---|
DatabaseFieldOptions.NoAction |
0 |
No constraint will be set. |
DatabaseFieldOptions.Restrict |
1 |
Operation not allowed if it would alter the integrity of the database. |
DatabaseFieldOptions.Cascade |
2 |
The change is allowed and propagates on the child table. For example, if a parent row is deleted, the child row is also deleted; if a parent row's ID changes, the child row's ID will also change. |
DatabaseFieldOptions.SetNull |
3 |
The change is allowed and the child row's foreign key columns are set to NULL . . |
import InCore.Foundation 2.5
import InCore.Database 2.5
Application {
LocalDatabase {
id: exampleDatabase
DatabaseTable {
id: messages
DateTime {
id: date
DatabaseFieldOptions.dbIndex: true
}
DataObject {
id: text
dataType: DataObject.String
data: "<default message>"
property var options : DatabaseFieldOptions { maxLength: 127; notNull: true }
}
}
}
onCompleted: messages.submit()
}