Skip to content

bBox_ExecuteSQL

Simon Brown edited this page Sep 19, 2025 · 3 revisions

bBox_ExecuteSQL( filename; sqlQuery {; columnSeparator; rowSeparator; arguments...} )

Parameters:
   filename: name of the database file, or "" for current file
   sqlQuery: a valid SQL expression
   columnSeparator: delimiter to use for columns in output (defaults to tab character)
   rowSeparator: delimiter to use for rows (defaults to newline)
   arguments: zero or more SQL parameters

Result:
   text result of the SQL expression, or "?" if there was an error

Error:
   bBox_LastError ("sql")

Script Step:
   bBox Execute SQL [ Expression; Field Separator; Row Separator; Parameter 1; Parameter 2; Parameter 3; Parameter 4 ]

First appeared in: 0.3

Examples in demo file: 6

Compatibility: WPE, WebDirect, Ubuntu, Server, macOS, Client


UPDATE, INSERT, and TRUNCATE operations are supported. However, CREATE, DROP, or ALTER statements should also work. There is a known issue where if a record is open on the same table as being queried by SQL the query will take longer than usual.

Note that this can be run from any layout, and even target another (previously opened) file.

An example of a simple expression is below. Since only a single SQL expression is expected, we don’t add a semicolon to the end of statement.

Set Variable [ $result; "bBox_ExecuteSQL (""; "SELECT category,name from EXAMPLE") ]

If you'd like the the result as a JSON array, you could do the same thing above as:

Set Variable [ $result; bBox_JavaScript ("fm.executesql ('SELECT category,name from EXAMPLE')"; "JSON") ]

Clone this wiki locally