SqliteRows
Inherits from: Object
A cursor over rows returned by a SqliteDatabase query.
SqliteRows provides row-by-row iteration over SQL query results.
Call next to advance to the next row, then use asDict,
columnAt:, or columnNamed: to read values. Always close the
cursor when done.
Example
| rows <SqliteRows> |
rows := db query: 'SELECT id, name FROM users ORDER BY id'.
[rows next] whileTrue: [
| row <Dictionary> |
row := rows asDict.
row at: 'name'
].
rows close
Instance Methods
primitives
primAsDict
primClose
primColumnAt:
primColumnCount
primColumnNamed:
primColumns
primNext
uncategorized
asDict
Get the current row as a Dictionary with column names as keys.
Example
| row <Dictionary> |
rows next.
row := rows asDict.
row at: 'name'
close
Close the cursor and release resources.
columnAt:
Get a column value by zero-based index for the current row.
Example
rows next.
rows columnAt: 0
columnCount
Get the number of columns in the result set.
columnNamed:
Get a column value by name for the current row.
Example
rows next.
rows columnNamed: 'name'
columns
Get the column names as an Array of Strings.
next
Advance to the next row. Returns true if a row is available, false if all rows have been consumed.
Example
| rows <SqliteRows> |
rows := db query: 'SELECT * FROM users'.
[rows next] whileTrue: [rows asDict]
printString
toArray
Collect all remaining rows as an Array of Dictionaries. Closes the cursor when done.
Example
| rows <SqliteRows> allRows <Array> |
rows := db query: 'SELECT * FROM users'.
allRows := rows toArray