Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
SQL.InsertRecords
Creates records in FileMaker database for current recordset.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
SQL | 5.2 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
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. |
"Model" | |
IgnoreDuplicates | Available in MBS FileMaker Plugin 7.3 or newer. If 1, ignores duplicates or with 0 or by default reports error for duplicates. If duplicates are found, the function returns number of duplicates instead of OK. |
0 | Optional |
Result
Returns number of duplicates, OK or error.
Description
Creates 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.
Please don't overload the function, so better work in blocks of e.g. 1000 rows at a time.
Examples
Insert records to FileMaker from SQL database:
#Create select command and run it
Set Variable [$Command; Value:MBS("SQL.NewCommand"; $Connection; "SELECT FirstName, LastName, Birthday, NumberOfOrders, TotalSales FROM Test")]
#Run it
Set Variable [$result; Value:MBS("SQL.Execute"; $Command)]
If [$result ≠ "OK"]
Show Custom Dialog ["Error: " & $result]
Else
Set Variable [$result; Value:MBS("SQL.InsertRecords"; $Command; Get(FileName) ;"SQLite fun"; "FirstName¶LastName¶Birthday¶NumberOfOrders¶TotalSales")]
Show Custom Dialog ["Records imported."; $result]
End If
#Cleanup
Set Variable [$result2; Value:MBS("SQL.FreeCommand"; $Command)]
See also
- FM.ExecuteSQL.LastErrorMessage
- FM.InsertOrUpdateRecordQuery
- FM.InsertRecord
- FM.InsertRecordQuery
- FM.InsertRecordQueryIgnoreDuplicates
- JSON.InsertRecord
- JSON.InsertRecords
- SQL.Execute
- SQL.NewCommand
- XML.InsertRecords
Release notes
- Version 14.2
- Fixed a bug in FM.SQL.InsertRecords that prevented containers from being transferred.
- Version 13.2
- Changed field quoting for FM.SQL.InsertRecordsToSQL and Matrix.InsertRecordsToSQL to handle non ANSI quotes for MySQL/MariaDB.
- Version 13.1
- Fixed FM.SQL.InsertRecords, FM.SQL.InsertRecordsToSQL, Matrix.InsertRecordsToSQL and Matrix.InsertRecords to quote the table name for the SQL used internally.
- Version 7.3
- Added IgnoreDuplicates parameter to SQL.InsertRecords functions to ignore duplicate error on insert.
- Version 7.2
- Changed FM.SQL.InsertRecordsToSQL to no longer quote by default.
- Fixed SQL.InsertRecords to handle floating point numbers better.
Example Databases
Blog Entries
- Moving data from ODBC to FileMaker via script
- Can FileMaker connect to a Microsoft Access database?
- MBS FileMaker Plugin, version 7.3pr1
- MBS FileMaker Plugin, version 7.2pr3
- MBS FileMaker Plugin, version 5.2pr9
FileMaker Magazin
This function checks for a license.
Created 29th July 2015, last changed 15th October 2021
SQL.InsertOrUpdateRecords - SQL.InternalSQLiteLibrary.Activate