CAST
Explicitly converts the data type of value from one type to another.
This function corresponds to the CAST(expression AS typename) expression in SQLite. It attempts to convert the value of the column to the specified target type. The rules for conversion follow SQLite's type affinity rules.
For example, casting a text string like '123' to an integer will result in the integer value 123. Casting a number to text will result in its string representation.
The target type is specified using the androidx.sqlite.DataType constants.
Example
// Cast a text column containing numbers to a numeric type for calculations
// SELECT CAST(price_text AS REAL) * quantity FROM Orders
val total = select(CAST(Orders.priceText, SQLITE_DATA_FLOAT) * Orders.quantity)
.from(Orders)
// Cast an integer timestamp to a text representation
val timestampText = select(CAST(Events.timestamp, SQLITE_DATA_TEXT))
.from(Events)
// Casting literals
val cast = CAST(DoubleLiteral(10.23), SQLITE_DATA_INTEGER)
val c = select(cast, TYPEOF(cast)).execute(con)
assertEquals("integer", c[TYPEOF(cast)])Return
A new KQLiteColumn representing the value after being cast to the specified type. The returned column has a generic type Any? because the actual resulting Kotlin type
Author
MOHAMMAD AZIM ANSARI
Parameters
The column or expression whose value is to be cast.
The target DataType, specified using one of the SQLITE_DATA_* constants from androidx.sqlite.DataType (e.g., SQLITE_DATA_INTEGER, SQLITE_DATA_TEXT).