Python.AddExecuteSQLFunction
----------------------------

Adds an execute SQL function.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Python](component_Python.md) | [14.3](newinversion143.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Python.AddExecuteSQLFunction"; PythonRef { ; FunctionName } ) 

**MBS**( **"Python.AddExecuteSQLFunction";** /\* Adds an execute SQL function. \*/  
**$PythonRef**; /\* The Python reference number.e.g. $python \*/   
**$FunctionName**) /\* Optional; The function name to use.  
Default is "FMExecuteSQL".e.g. "FMExecuteSQL" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| PythonRef | The Python reference number. | $python |  |
| FunctionName | The function name to use.   Default is "FMExecuteSQL". | "FMExecuteSQL" | Optional |

### Result

Returns value or error.

### Description

Adds an execute SQL function.  
You can register a function to execute SQL in FileMaker if you like to have that. You can pick the name to use, but we default to FMExecuteSQL.   
The Python function is then added locally and can be called.   
  
It takes several parameters:  
- SQL expression.
- Optionally the file name for the database.
- Optionally parameters as needed for the question marks in the SQL.

### Examples

Query SQL from Python:

 Set Variable \[ $p ; Value: MBS ("[Python.New](PythonNew.md)") \]  
Set Variable \[ $r ; Value: MBS ("Python.AddExecuteSQLFunction"; $p ; "FMExecuteSQL") \]  
Set Variable \[ $r ; Value: MBS ("[Python.Evaluate](PythonEvaluate.md)"; $p ; "FMExecuteSQL('SELECT PrimaryKey FROM Python')") \]  
Show Custom Dialog \[ "SQL Result:" ; $r \]  
Set Variable \[ $r ; Value: MBS ("[Python.Release](PythonRelease.md)"; $p ) \]  
Use parameters for SQL:

 Set Variable \[ $p ; Value: MBS ("[Python.New](PythonNew.md)") \]  
Set Variable \[ $r ; Value: MBS ("Python.AddExecuteSQLFunction"; $p ; "FMExecuteSQL") \]  
Set Variable \[ $r ; Value: MBS ("[Python.Evaluate](PythonEvaluate.md)"; $p ; "FMExecuteSQL('SELECT PrimaryKey FROM Python WHERE Result = ? OR Result = ?', '', 1, 2)") \]  
Show Custom Dialog \[ "SQL Result:" ; $r \]  
Set Variable \[ $r ; Value: MBS ("[Python.Release](PythonRelease.md)"; $p ) \]  
### See also

- [Python.AddEvaluateFunction](PythonAddEvaluateFunction.md)
- [Python.Evaluate](PythonEvaluate.md)
- [Python.New](PythonNew.md)
- [Python.Release](PythonRelease.md)

### Example Databases

- [Python](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Python.shtml#2ScriptAnchor_)

This function is free to use.

Created 31st May 2024 , last changed 31st May 2024

  
[Python.AddEvaluateFunction](PythonAddEvaluateFunction.md) - [Python.AddSysPath](PythonAddSysPath.md)

[HTML Version](PythonAddExecuteSQLFunction.shtml)