SelectStatement

Represents a builder for a SQL SELECT statement.

This interface provides methods to construct a SELECT query by chaining clauses like WHERE, JOIN, GROUP BY, ORDER BY, HAVING, and LIMIT.

An instance of this interface is typically obtained by calling the select() extension function on a KQLiteTable object. The query is executed by calling the execute method at the end of the chain, which returns a KQLiteCursor to iterate over the results.

It also inherits from JoinStatement to support JOIN operations and CompoundStatement to support UNION, INTERSECT, and EXCEPT.

Example

val cursor = Employees
.select(Employees.id, Employees.firstName)
.innerJoin(Departments)
.on(Employees.departmentId, Departments.id)
.where { Employees.age GT 30 }
.orderBy(Employees.lastName, Sort.ASC)
.limit(10)
.execute()

Author

MOHAMMAD AZIM ANSARI

Type Parameters

T

The type of the primary KQLiteTable the query is being performed on.

See also

Functions

Link copied to clipboard

Creates an alias for a subquery (a SELECT statement) using SQL AS.

Link copied to clipboard
abstract fun crossJoin(selectStatement: SelectStatement<*>): JoinStatement<T>

abstract fun crossJoin(table: KQLiteTable): JoinStatement<T>

Adds a CROSS JOIN clause to the SELECT statement

Link copied to clipboard
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.

Link copied to clipboard
abstract fun fullJoin(selectStatement: SelectStatement<*>): JoinStatement<T>
abstract fun fullJoin(table: KQLiteTable): JoinStatement<T>
Link copied to clipboard
abstract fun groupBy(column: KQLiteColumn<*>): SelectStatement<T>

Same as calling groupBy(column, null)

abstract fun groupBy(column1: KQLiteColumn<*>, column2: KQLiteColumn<*>?): SelectStatement<T>

Adds a GROUP BY clause to the SELECT statement.

Link copied to clipboard
abstract fun having(clause: Clause.(T) -> Unit): SelectStatement<T>

Adds a HAVING clause to the SELECT statement to filter the results of GROUP BY.

Link copied to clipboard
abstract fun innerJoin(selectStatement: SelectStatement<*>): JoinStatement<T>

abstract fun innerJoin(table: KQLiteTable): JoinStatement<T>

Adds an INNER JOIN clause to the SELECT statement.

Link copied to clipboard
abstract fun join(selectStatement: SelectStatement<*>): JoinStatement<T>

abstract fun join(table: KQLiteTable): JoinStatement<T>

Adds a JOIN clause to the SELECT statement.

Link copied to clipboard
abstract fun leftJoin(selectStatement: SelectStatement<*>): JoinStatement<T>

abstract fun leftJoin(table: KQLiteTable): JoinStatement<T>

Adds a LEFT JOIN clause to the SELECT statement.

Link copied to clipboard
abstract fun limit(limit: Int): SelectStatement<T>

Same as calling limit(limit, -1)

abstract fun limit(limit: Int, offset: Int): SelectStatement<T>

Adds a LIMIT clause to the SELECT statement, constraining the number of rows returned.

Link copied to clipboard
abstract fun orderBy(column: KQLiteColumn<*>): SelectStatement<T>
abstract fun orderBy(column: OrderColumn): SelectStatement<T>

Same as calling orderBy(column, null)

abstract fun orderBy(column: KQLiteColumn<*>, sort: Sort?): SelectStatement<T>

Adds an ORDER BY clause to the SELECT statement to sort the result set.

abstract fun orderBy(orderColumn1: OrderColumn, orderColumn2: OrderColumn?): SelectStatement<T>

Adds an ORDER BY clause to the SELECT statement to sort the result set by one or more columns, each with its own specific sorting order.

Link copied to clipboard
abstract fun rightJoin(selectStatement: SelectStatement<*>): JoinStatement<T>
abstract fun rightJoin(table: KQLiteTable): JoinStatement<T>
Link copied to clipboard
abstract fun where(clause: Clause.(T) -> Unit): SelectStatement<T>

Adds a WHERE clause to the SELECT statement, filtering the result set.