Skip to content

Latest commit

 

History

History
316 lines (206 loc) · 7.46 KB

DatabaseFieldOptions.rst

File metadata and controls

316 lines (206 loc) · 7.46 KB

DatabaseFieldOptions

Description

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>

Overview

Properties

  • 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>

Methods

  • Object.deserializeProperties() <method_Object_deserializeProperties>
  • Object.fromJson() <method_Object_fromJson>
  • Object.serializeProperties() <method_Object_serializeProperties>
  • Object.toJson() <method_Object_toJson>

Signals

  • Object.completed() <signal_Object_completed>

Enumerations

  • ForeignKeyConstraint <enum_DatabaseFieldOptions_ForeignKeyConstraint>

Properties

single: autoIncrement

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

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

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

dbIndex

This property holds whether to create an index on this field.

› Type

Boolean

› Default

false

› Signal

dbIndexChanged()

› Attributes

Writable

single: maxLength

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

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

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

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

unique

This property holds whether this field must be unique throughout the table.

› Type

Boolean

› Default

false

› Signal

uniqueChanged()

› Attributes

Writable

Enumerations

single: ForeignKeyConstraint

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. .

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()
}