DatabaseSqlQuery

Description

The DatabaseSqlQuery object encapsulates a SQL query and handles errors or results.

› Inherits:Object

Properties

error

This property holds the most recently occurred error or DatabaseSqlQuery.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.

› Type:Error
› Signal:errorChanged()
› Attributes:Readonly

errorString

This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.

› Type:String
› Signal:errorStringChanged()
› Attributes:Readonly

forwardOnly

This property holds whether the query is forward only. For some queries forwardOnly has to be true to work properly. Forward only mode can be (depending on the driver) more memory efficient since results do not need to be cached. It will also improve performance on some databases.

› Type:Boolean
› Default:false
› Signal:forwardOnlyChanged()
› Attributes:Writable

lastInsertedId

This property holds the object ID of the most recent inserted row if the database supports it. undefined will be returned if the query did not insert any value or if the database does not report the id back. If more than one row was touched by the insert, the behavior is undefined. For MySQL databases the row’s auto-increment field will be returned.

This property was introduced in InCore 2.3.

› Type:Variant
› Signal:lastInsertedIdChanged()
› Attributes:Readonly

query

This property holds the query string which will be executed.

› Type:String
› Signal:queryChanged()
› Attributes:Writable

results

This property holds the results of the query. For example the column id of the second row can be read through results[1].id.

› Type:List
› Signal:resultsChanged()
› Attributes:Readonly, Requires Polling

Methods

execute()

This method executes the query and updates results. On success, true is returned, otherwise false.

› Returns:Boolean

pollResults()

This method polls the results property. It is called automatically when using a Polling property modifier on this property and usually does not have to be called manually.

Signals

errorOccurred()

This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.

Enumerations

Error

This enumeration describes all errors which can occur in DatabaseSqlQuery objects. The most recently occurred error is stored in the error property.

Name Value Description
DatabaseSqlQuery.NoError 0 No error occurred or was detected.
DatabaseSqlQuery.InvalidDatabase 1 Parent is not a database object.
DatabaseSqlQuery.EmptyQueryError 2 Empty query string.
DatabaseSqlQuery.InvalidQueryError 3 The query caused an error: .
DatabaseSqlQuery.TransactionError 4 The query caused an transaction error: .
DatabaseSqlQuery.UnknownError 5 The query caused an unknown error: .

Example

See LocalDatabase example on how to use DatabaseSqlQuery.