QueryExecute
Execute an SQL query and returns the results.
Method Signature
Arguments
sql
String
true
The SQL to execute
params
any
false
An array of binding parameters or a struct of named binding parameters
[]
options
struct
false
A struct of query options
Examples
Simple Example
SQL only example. Assumes that a default datasource has been specified (by setting the variable this.datasource
in Application.bx).
Using Named Placeholders
Use :structKeyName
in your sql along with a struct of key/value pairs:
Using Positional Placeholders
You can pass placeholders by position using an array of parameters and the question mark ?
symbol:
Query of Queries
Query a local database variable without going through your database
Return Query as an Array of Structs - Boxlang5+
Return a query object converted into an array of structs.
Result: [ { firstname: "Han" } ]
Return Query as an Array of Structs - Boxlang 4.5
Return a query object converted into an array of structs.
Result: [ { firstname: "Han" } ]
Return Query as a Struct of Structs
Return a query object converted into a struct of structs. (Struct key is based on the "columnkey" parameter)
Result: { 1: { id: 1, firstname: "Han" } }
Additional Examples
Related
Last updated
Was this helpful?