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 |
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.
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
This function is free to use.
Created 11st March 2020, last changed 11st March 2020