execute

abstract fun execute(): KQLiteCursor

Same as calling execute(null). Uses last opened connection.


abstract fun execute(connection: SQLiteConnection?): KQLiteCursor

Executes the constructed SELECT query and returns the result set.

This is the terminal operation for a SelectStatement chain. It builds the final SQL query from all the preceding clauses (where, join, orderBy, etc.), prepares it, binds any arguments, and executes it against the database.

The method returns a KQLiteCursor which you can use to iterate over the resulting rows.

An optional SQLiteConnection can be provided if you want to execute the query within a specific transaction or on a particular database connection. If null, the default connection from KQLiteConnection will be used.

Note: A SelectStatement instance can only be executed once. Attempting to call execute() a second time on the same instance will result in an SQLiteException.

Example

// Build and execute a query
val cursor = Employees
.select(Employees.firstName, Employees.lastName)
.where { Employees.age GT 30 }
.limit(10)
.execute()

// Iterate over the results
cursor.forEach { row ->
val firstName = row[Employees.firstName]
val lastName = row[Employees.lastName]
println("Employee: $firstName $lastName")
}

// Don't forget to close the cursor. Not required after forEach.
cursor.close()

Return

A KQLiteCursor representing the result set of the query.

Author

MOHAMMAD AZIM ANSARI

Parameters

connection

The SQLiteConnection to use for executing the query. If null, a default connection is obtained from KQLiteConnection.

See also

Throws

if the statement has already been executed.