Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old


Sets parameters based on values in JSON.

Component Version macOS Windows Linux Server iOS SDK
SQL 10.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "SQL.SetParamsWithJSON"; Command; JSON )   More


Parameter Description Example
Command The command reference number gained with SQL.NewCommand. $Command
JSON The JSON object with values for the items. "{ \"Index\": 123 }"


Returns OK or error.


Sets parameters based on values in JSON.
If a parameter has a known type, we convert JSON to that type: Null, Double, Integer, String, Boolean.
If type of parameter is not known, we check JSON type and pass boolean, numbers or texts through.
Setting BLOB may not work with this function.
If JSON value is array or object, we encode as text and set field to text value.
Parameters not present in JSON are skipped.


Run insert with JSON:

# Create insert command with setting values
Set Variable [ $Command ; Value: MBS("SQL.NewCommand"; $Connection; "INSERT INTO 'Test' (FirstName, LastName, Birthday, NumberOfOrders, TotalSales) VALUES (:FirstName,:LastName,:Birthday,:NumberOfOrders,:TotalSales)") ]

# build some JSON
Set Variable [ $json ; Value: "{}" ]
Set Variable [ $json ; Value: MBS( "JSON.AddStringToObject"; $json; "FirstName"; SQLite fun::FirstName ) ]
Set Variable [ $json ; Value: MBS( "JSON.AddStringToObject"; $json; "LastName"; SQLite fun::LastName ) ]
Set Variable [ $json ; Value: MBS( "JSON.AddStringToObject"; $json; "Birthday"; SQLite fun::Birthday ) ]
Set Variable [ $json ; Value: MBS( "JSON.AddNumberToObject"; $json; "NumberOfOrders"; SQLite fun::NumberOfOrders ) ]
Set Variable [ $json ; Value: MBS( "JSON.AddNumberToObject"; $json; "TotalSales"; SQLite fun::TotalSales ) ]
Set Variable [ $result ; Value: MBS("SQL.SetParamsWithJSON"; $Command; $json) ]

# Run it
Show Custom Dialog [ "JSON" ; MBS( "SQL.GetParamsAsJSON"; $Command ) ]
Set Variable [ $result ; Value: MBS("SQL.Execute"; $Command) ]

# Cleanup
Set Variable [ $result2 ; Value: MBS("SQL.Commit"; $Connection) ]
Set Variable [ $result2 ; Value: MBS("SQL.FreeCommand"; $Command) ]
If [ $result ≠ "OK" ]
    Show Custom Dialog [ "Error: " & $result ]
    Show Custom Dialog [ "Record exported." ]
End If

See also

Release notes

Example Databases

Blog Entries

This function is free to use.

Created 11st March 2020, last changed 11st March 2020

SQL.SetParamValues - SQL.isAlive