sql Query
sql query runs one statement and keeps the rows it returns. #SqlCnt is the
number of rows, and row 1 is loaded straight away: each column goes into a % variable named after it.
Load the other rows with sql row.
SELECT name, hp FROM petssets%nameand%hp. UseASto choose the variable name:SELECT count(*) AS n …sets%n.- SQL
NULLreads back asN/A, like an unset variable. - All rows stay in memory until the next
sql query. Add aLIMITwhen a table can be large.
Example
Section titled “Example”sql open :memory:sql exec CREATE TABLE pets(name TEXT, hp INTEGER)sql exec INSERT INTO pets VALUES('Rex', 80), ('Buttercup', 45), ('Fluffy', 20)set %limit 50sql query SELECT name, hp FROM pets WHERE hp < %limit ORDER BY hpfor %i 1 #SqlCnt{ sql row %i display ok %name has %hp hp}haltSee Using SQL for how statements are written and how variables go in and out.