executeReturning

abstract fun executeReturning(vararg columns: KQLiteColumn<*>): KQLiteCursor

Executes the UPDATE statement and returns a KQLiteCursor containing the specified columns from the rows that were modified.

This function utilizes the RETURNING clause of the UPDATE statement, which is available in SQLite version 3.35.0 and newer. It allows you to retrieve data from the rows that have just been updated, without needing to perform a separate SELECT query.

The returned KQLiteCursor can be used to iterate over the updated rows and access the values of the columns specified in the columns parameter.

Example

// Update the status of old 'pending' orders to 'archived' and retrieve their IDs and original order dates.
val cursor =
Orders
.update {
it.status.bind("archived")
}.where {
it.status EQ "pending" AND
it.orderDate.GT(DATE().now().localtime().days(-365))
}.executeReturning(
Orders.orderId,
Orders.orderDate,
)
cursor.use { c ->
c.forEach {
val id = it.getLong(Orders.orderId)
val date = it.getString(Orders.orderDate)
println("Archived order $id from date $date")
}
}

Return

A KQLiteCursor containing the specified columns for each updated row.

Author

MOHAMMAD AZIM ANSARI

Parameters

columns

A variable number of KQLiteColumn instances to be returned for each updated row. If no columns are provided, the RETURNING clause will not be added, and the behavior will be similar to execute, but it will return an empty cursor.