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: 10.5   11.0   11.1   11.2   11.3   11.4   11.5   12.0   12.1   12.2    Statistic    FMM    Blog  

FM.ExecuteFileSQLOnIdle

Executes a SQL command at idle time.

Component Version macOS Windows Linux Server iOS SDK License
FM FMSQL 6.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes Paid
MBS( "FM.ExecuteFileSQLOnIdle"; SQL Statement; FileName { ; Column Delimiter; Record Delimiter; Params... } )   More

Parameters

Parameter Description Example Flags
SQL Statement the SQL statement
FileName The file name of the database. Get(FileName)
Column Delimiter Columns Separator, only used with SELECT statement.
Default is tab character, which has unicode code point 9.
You can pass delimiter as text (one character only) or as unicode code point (as number).
9 Optional
Record Delimiter Record Separator, only used with SELECT statement.
Default is return character, which has unicode code point 13.
You can pass delimiter as text (one character only) or as unicode code point (as number).
13 Optional
Params... Optional, pass here parameters. One parameter to this function for each parameter you want to pass to the SQL statement. 123 Optional

Result

Returns OK or error.

Description

Executes a SQL command at idle time.
This is similar to FM.ExecuteFileSQL, except that it waits until idle to execute..
You run a script pause after using this function to give it time to execute.
See the other function for more info.

Seems like on FileMaker 11 you get LastError 8310 if you use fields with underscore in the name. You avoid that by placing the field names in quotes.
Use FM.ExecuteSQL.LastErrorMessage and FM.ExecuteSQL.LastError to see error message.

You can do more schema changes via ODATA interface on FileMaker Server including changing or renaming fields.

Please notice that FM.ExecuteFileSQLOnIdle and FM.ExecuteFileSQL have the filename parameter on different positions.

This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.
Please repeat Params parameter as often as you need.

Examples

Create a new text field in a table:

MBS("FM.ExecuteSQLOnIdle";"ALTER TABLE TestTable ADD MyField varchar")

Create in a script and check error:

# set command to run
Set Variable [ $r ; Value: MBS("FM.ExecuteFileSQLOnIdle"; "ALTER TABLE Kontakte ADD MyField varchar"; "Kontakte.fmp12") ]
# Make pause to run it
Pause/Resume Script [ Duration (seconds): ,1 ]
# Check error status
Set Variable [ $errorNumber ; Value: MBS( "FM.ExecuteSQL.LastError" ) ]
Set Variable [ $errorMessage ; Value: MBS( "FM.ExecuteSQL.LastErrorMessage" ) ]

Create a field:

Set Variable [ $r ; Value: MBS("FM.ExecuteFileSQLOnIdle";"ALTER TABLE TestTable ADD MyField varchar"; Get(FileName)) ]
Pause/Resume Script [ Duration (seconds): ,1 ]
If [ MBS("FM.ExecuteSQL.LastError") ≠ 0 ]
    Show Custom Dialog [ "Error adding column" ; MBS("FM.ExecuteSQL.LastError") & ": " & MBS("FM.ExecuteSQL.LastErrorMessage") ]
Else
    Show Custom Dialog [ "Removed Column" ; "OK" ]
End If

Create a new text field in a table with variables for the names:

Set Variable [ $TableName ; Value: "TestTable" ]
Set Variable [ $FieldName ; Value: "MyField" ]
Set Variable [ $FieldType ; Value: "VARCHAR" ]

Set Variable [ $r ; Value: MBS("FM.ExecuteFileSQLOnIdle";"ALTER TABLE \"" & $TableName & "\" ADD \"" & $FieldName & "\" " & $FieldType & " " ; Get(FileName)) ]
Pause/Resume Script [ Duration (seconds): ,1 ]
If [ MBS("FM.ExecuteSQL.LastError") ≠ 0 ]
    Show Custom Dialog [ "Error adding column" ; MBS("FM.ExecuteSQL.LastError") & ": " & MBS("FM.ExecuteSQL.LastErrorMessage") ]
Else
    Show Custom Dialog [ "Removed Column" ; "OK" ]
End If

Create a table:

Set Variable [ $r ; Value: MBS("FM.ExecuteFileSQLOnIdle";"CREATE TABLE \"TestTable\" (ID INT PRIMARY KEY, MyTextField VARCHAR, MyNumberField DECIMAL)"; Get(FileName)) ]
// for details see fm16_sql_reference.pdf (or newer) from Claris Inc.

Create container field by making BLOB:

Set Variable [ $r ; Value: MBS("FM.ExecuteSQLOnIdle";"ALTER TABLE TestTable ADD MyField blob") ]
Pause/Resume Script [ Duration (seconds): ,1 ]
If [ MBS("FM.ExecuteSQL.LastError") ≠ 0 ]
    Show Custom Dialog [ "Error adding column" ; MBS("FM.ExecuteSQL.LastError") & ": " & MBS("FM.ExecuteSQL.LastErrorMessage") ]
Else
    Show Custom Dialog [ "Removed Column" ; "OK" ]
End If

Create numeric field with default value:

MBS("FM.ExecuteSQLOnIdle";"ALTER TABLE TestTable ADD MyField decimal DEFAUlT 123“)

See also

Release notes

Blog Entries

Created 16th October 2016, last changed 7th March 2022


FM.ExecuteFileSQL - FM.ExecuteFileSQLValue

Feedback: Report problem or ask question.


Start Chat