sqlite.Row
type pub inline RowA single row produced by the Rows iterator.
Instance methods
bool
Show source codeHide source code
fn pub bool(index: Int) -> Result[Bool, Error] {
match try int(index) {
case 0 -> Result.Ok(false)
case _ -> Result.Ok(true)
}
}fn pub bool(index: Int) -> Result[Bool, Error]Reads a column value as an Int and converts it to a Bool.
If the integer value is zero then false is returned. For any other value,
true is returned instead.
Refer to the documentation of Row.int for more details.
Examples
import sqlite (Database)
let db = Database.new(':memory:').or_panic
let st = db.prepare('SELECT 1').or_panic
let row = st.rows.next.get.or_panic
row.bool(0) # => Result.Ok(true)
bytes
Show source codeHide source code
fn pub bytes(index: Int) -> Result[ByteArray, Error] {
try check_bounds(index)
let col = index as Int32
let stm = @statement.handle
let ptr = sqlite3_column_blob(stm, col)
try check_allocation(ptr)
let len = sqlite3_column_bytes(stm, col) as Int
Result.Ok(ByteArray.from_pointer(ptr, len))
}fn pub bytes(index: Int) -> Result[ByteArray, Error]Reads a column value as a ByteArray.
If the type of the column is not TEXT or BLOB, a conversion takes place
according to the SQLite type conversion
rules.
This method allocates a new ByteArray on each call.
Errors
This method returns an Error.InvalidColumn if index is out of bounds or
if the statement this Row belongs to is reset.
If SQLite fails to allocate the necessary memory to read the column value,
an Error.NoMemory error is returned.
Examples
import sqlite (Database)
let db = Database.new(':memory:').or_panic
let st = db.prepare('SELECT "hello"').or_panic
let row = st.rows.next.get.or_panic
row.bytes(0) # => Result.Ok('hello'.to_byte_array)
float
Show source codeHide source code
fn pub float(index: Int) -> Result[Float, Error] {
try check_bounds(index)
let col = index as Int32
let stm = @statement.handle
Result.Ok(sqlite3_column_double(stm, col))
}fn pub float(index: Int) -> Result[Float, Error]Reads a column value as a Float.
If the type of the column is not REAL a conversion takes place according
to the SQLite type conversion
rules.
Errors
This method returns an Error.InvalidColumn if index is out of bounds or
if the statement this Row belongs to is reset.
Examples
import sqlite (Database)
let db = Database.new(':memory:').or_panic
let st = db.prepare('SELECT 1.5').or_panic
let row = st.rows.next.get.or_panic
row.float(0) # => Result.Ok(1.5)
int
Show source codeHide source code
fn pub int(index: Int) -> Result[Int, Error] {
try check_bounds(index)
let col = index as Int32
let stm = @statement.handle
Result.Ok(sqlite3_column_int64(stm, col))
}fn pub int(index: Int) -> Result[Int, Error]Reads a column value as an Int.
If the type of the column is not INTEGER a conversion takes place
according to the SQLite type conversion
rules.
Errors
This method returns an Error.InvalidColumn if index is out of bounds or
if the statement this Row belongs to is reset.
Examples
import sqlite (Database)
let db = Database.new(':memory:').or_panic
let st = db.prepare('SELECT 1').or_panic
let row = st.rows.next.get.or_panic
row.int(0) # => Result.Ok(1)
number_of_columns
Show source codeHide source code
fn pub inline number_of_columns -> Int {
@statement.number_of_columns
}fn pub inline number_of_columns -> IntReturns the number of columns in this row.
string
Show source codeHide source code
fn pub string(index: Int) -> Result[String, Error] {
try check_bounds(index)
let col = index as Int32
let stm = @statement.handle
let ptr = sqlite3_column_blob(stm, col)
try check_allocation(ptr)
let len = sqlite3_column_bytes(stm, col) as Int
Result.Ok(String.from_pointer_and_size(ptr, len))
}fn pub string(index: Int) -> Result[String, Error]Reads a column value as a String.
If the type of the column is not TEXT or BLOB, a conversion takes place
according to the SQLite type conversion
rules.
This method allocates a new String on each call.
Errors
This method returns an Error.InvalidColumn if index is out of bounds or
if the statement this Row belongs to is reset.
If SQLite fails to allocate the necessary memory to read the column value,
an Error.NoMemory error is returned.
Examples
import sqlite (Database)
let db = Database.new(':memory:').or_panic
let st = db.prepare('SELECT "hello"').or_panic
let row = st.rows.next.get.or_panic
row.string(0) # => Result.Ok('hello')