DatabaseUpdate¶
Description¶
The DatabaseUpdate object is used to update objects in a database table. The API is identical to DatabaseQuery except for the execute() method.
This object was introduced in InCore 2.5.
› Inherits: | DatabaseQuery |
---|
Properties¶
Methods¶
execute()¶
This method updates the columns specified by DatabaseQuery.objects and rows filtered through DatabaseQuery.filters. If at least one row has been updated and no error occurred, true
is returned, otherwise false
. The number of updated rows can be retrieved using the DatabaseQuery.results property.
› Returns: | Boolean |
---|
Example¶
import InCore.Foundation 2.5
import InCore.Database 2.5
Application {
LocalDatabase {
id: exampleDatabase
DatabaseTable {
id: exampleTable
// submit a new data row every 10s
submitInterval: 10000
submitMode: DatabaseTable.SubmitPeriodically
onSubmitted: lastIdQuery.execute()
DataObject {
id: exampleTableId
objectId: "id"
dataType: DataObject.SignedInteger
DatabaseFieldOptions.primaryKey: true
DatabaseFieldOptions.autoIncrement: true
}
Measurement {
id: sensor1
data: 1
onDataChanged: updateSensor1.execute()
}
Measurement {
id: sensor2
data: 123
}
queries: [
// always update last row with latest value of sensor1
DatabaseUpdate {
id: updateSensor1
objects: [sensor1]
DatabaseQueryFilter {
DatabaseQueryWhere {
key: exampleTableId
operation: DatabaseQueryWhere.Equals
value: lastIdQuery.results[0] ? lastIdQuery.results[0].id : -1
}
}
},
DatabaseQuery {
id: lastIdQuery
objects: [exampleTableId]
orderByNames: ["-id"]
limitPos: 0
limitLength: 1
}
]
}
}
Timer {
onTriggered: sensor1.data = Math.random() * 100
}
}