DatabaseFieldOptions¶
Description¶
The DatabaseFieldOptions object defines additional options for a database field represented by a DataObject. It can be set through attached properties or instantiated as an arbitrarily-named custom property of the corresponding DataObject. See the example for details.
This object was introduced in InCore 1.1.
› Inherits: | Object |
---|
Properties¶
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 |
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 |
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 |
dbIndex¶
This property holds whether to create an index on this field.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | dbIndexChanged() |
› Attributes: | Writable |
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 |
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 |
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 enumeration for details.
› Type: | ForeignKeyConstraint |
---|---|
› Default: | DatabaseFieldOptions.NoAction |
› Signal: | onDeleteChanged() |
› Attributes: | Writable |
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 |
unique¶
This property holds whether this field must be unique throughout the table.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | uniqueChanged() |
› Attributes: | Writable |
Enumerations¶
ForeignKeyConstraint¶
This enumeration describes all possible constraints which can be set for foreign keys.
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 . . |
Example¶
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()
}