MoneyWorks Manual
Sqlite3_Exec (sqlite3_handle, query, [bindArgs...])
Result Type: text
Definition: Executes a SQL query on the database. Any SQL supported by Sqlite3 may be used (CREATE TABLE
, SELECT
, INSERT
, UPDATE
, PRAGMA
, etc). A SELECT
query will return the entire result of the query as delimited tabular text.
The Sqlite3_Exec
function allows parameter binding, binding the values passed in as additional parameters into the query wherever it contains a ?
. This removes the need to deal with escaping special characters in the data to avoid accidental SQL injection from user-supplied data.
Example
on Load let s = sqlite3_open("") // temporary in-memory DB let r = sqlite3_exec(s, "CREATE TABLE cars ( make TEXT, model TEXT, colour TEXT, registration TEXT, mileage REAL);") let sql = "INSERT INTO cars VALUES ( 'Subaru', 'Outback', 'Gold', 'XYZ999', 36000); INSERT INTO cars VALUES ( 'Toyota', 'Corolla', 'White', 'ABC123', 46899); INSERT INTO cars VALUES ( 'BYD', 'Shark', 'Grey', 'ZZZ000', 1);" let r = sqlite3_exec(s, sql) let r = sqlite3_exec(s, "SELECT * FROM cars ORDER BY mileage DESC;") syslog(r) sqlite3_close(s) end
Output format
By default, the output format is the same as the Sqlite default format: tab separated column values and newline terminated rows. You can modify the output format mode using a query consisting of a .separator
directive in the form .separator colsep opt_rowsep
. Either separator may be enclosed in single quotes.
Example
Sqlite3_Exec(s, ".separator | ''")
— set the column separator to | and the row separator to nothing
For more information see Using Sqlite3 with MoneyWorks and https://www.sqlite.org/