SQL
sql {open|close|exec|query|row|save|load|delete} [arguments...]- Sets
#SqlRes,#SqlCnt,#SqlChanges,#SqlLastID
Also searchable as: SQL · sqlite · database
SQL lets a script keep data in an SQLite database file: anything from a few
variables that survive a restart to real tables you can query. Nothing is installed: EasyUO Reforged uses
the SQLite that ships with Windows.
sql open mychar.dbsql exec CREATE TABLE IF NOT EXISTS pets(id TEXT PRIMARY KEY, name TEXT, hp INTEGER)set %petid ABCDEFGset %petname Buttercupset %pethp 45sql exec INSERT OR REPLACE INTO pets VALUES(%petid, %petname, %pethp)set %limit 50sql query SELECT name, hp FROM pets WHERE hp < %limit ORDER BY hpfor %i 1 #SqlCnt{ sql row %i ; sets %name and %hp display ok %name has %hp hp}if #SqlRes <> OK display ok SQL error: #SqlRes
sql load %runs ; restore last session's valueset %runs %runs + 1display ok Run number %runssql save %runs ; and keep it for the next onehaltSub-commands
Section titled “Sub-commands”| Command | What it does |
|---|---|
sql open |
Opens (or creates) the database file. |
sql close |
Closes it. |
sql exec |
Runs one statement and discards any rows it returns. |
sql query |
Runs one statement and keeps its rows; row 1 is loaded into variables. |
sql row |
Loads another row of the last query into variables. |
sql save |
Stores variables in the database. |
sql load |
Restores them. |
sql delete |
Removes saved variables. |
An sql line never stops the script. When something goes wrong, #SqlRes says
what, and the script goes on with the next line.
Each script tab has one database connection, shared with scripts started by call. It is closed when
you press Play on a stopped script, when a script is loaded into the tab, when the tab is closed, and by
sql open / sql close.
See Using SQL for how statements are written and how variables go in and out, and
SQL or * variables? for when to use SQL instead of * variables.
Reforged notes
Section titled “Reforged notes”SQL and the #Sql… variables are new in EasyUO Reforged. SQL is the only new command word; nothing
else in the language changes because of it, and the SQLite library is only loaded when a script runs its
first sql line.