Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 9.2   9.3   9.4   9.5   10.0   10.1   10.2   10.3   10.4   10.5    Statistic    FMM    Blog  

SQL.SetParamsWithJSON

Sets parameters based on values in JSON.

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

Parameters

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

Result

Returns OK or error.

Description

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.

Examples

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 ]
Else
    Show Custom Dialog [ "Record exported." ]
End If

See also

Example Databases

Blog Entries

Release notes

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


SQL.SetParamValues   -   SQL.isAlive

Feedback: Report problem or ask question.




Links
MBS FileMaker tutorial videos