Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5   8.0    Statistic  


Creates or updates records in FileMaker database for current recordset.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
SQL 7.3 Yes Yes Yes Yes Yes

MBS( "SQL.InsertOrUpdateRecords"; Command; InsertFileName; InsertTableName; FieldNames; PrimaryKeyDB; PrimaryKeyFM )


Parameter Description Example value
Command The command reference number gained with SQL.NewCommand. $Command
InsertFileName The file name of where the insert table is inside. Can be empty to look for the table in all files. Get(FileName)
InsertTableName The name of the table to insert record into. "Assets"
FieldNames A list of field names for the insert.
Empty entries in the list are ignored.
PrimaryKeyDB The name of the primary key in the record set.
Must be one of the columns in the record from SQL.
PrimaryKeyFM The name of the primary key for the update statements.
Must be one of the columns in the FileMaker table.


Returns list or error.


Creates or updates records in FileMaker database for current recordset.
This function allows to easily copy a lot of records from SQL database into FileMaker table.
Please provide field names in FileMaker. The order has to match those in the record set.
Due to passing in new field names, you can even rearrange values from one column to other while copying. In the SQL you can use functions for sums or join data from several tables together to fill a new table.
Use FM.ExecuteSQL.LastErrorMessage and FM.ExecuteSQL.LastError to see error message.
Reports an error if field name list doesn't match column count of the query result.
This will not work for BLOBs as they are stored currently as hex encoded text only.
Function will fail if data types in FileMaker and other SQL database do not match for assignment. e.g. date and time fields will not work, only timestamp fields.

For copying record within FileMaker, please use FM.InsertRecordQuery or FM.SQL.InsertRecords functions.

Returns list with three values: Number of records inserted, number of records updated and number of errors.
Primary key in FM must be defined as unique and validate always, so FileMaker properly reports a duplicate.


Insert or update records:

# get connection before.
# Create select and run it
Set Variable [ $Command ; Value: MBS("SQL.NewCommand"; $Connection; "SELECT RowID, FirstName, LastName, TotalSales, NumberOfOrders FROM Test") ]
# Run it
Set Variable [ $result ; Value: MBS("SQL.Execute"; $Command) ]
If [ $result ≠ "OK" ]
    Show Custom Dialog [ "Error: " & $result ]
    Set Variable [ $result ; Value: MBS("SQL.InsertOrUpdateRecords"; $Command; Get(FileName); "SQLite fun"; "PKey¶FirstName¶LastName¶TotalSales¶NumberOfOrders"; "RowID"; "PKey") ]
    Show Custom Dialog [ "Records imported." & ¶ & ¶ & $result ]
End If
# Cleanup
Set Variable [ $result2 ; Value: MBS("SQL.FreeCommand"; $Command) ]
Set Variable [ $result2 ; Value: MBS("SQL.Commit"; $Connection) ]
Set Variable [ $result2 ; Value: MBS("SQL.FreeConnection"; $Connection) ]

See also

SQL.GetRecordsAsText   -   SQL.InsertRecords

Feedback: Report problem or ask question.

MBS FileMaker Plugins