Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 8.0   8.1   8.2   8.3   8.4   8.5   9.0   9.1   9.2   9.3    Statistic  


Creates a new command.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
SQL 2.6 Yes Yes Yes Yes Yes
MBS( "SQL.NewCommand"; Connection { ; Command; CommandType; ID } )   More


Parameter Description Example value
Connection The command reference number gained with SQL.NewConnection. $Connection
Command Optional
This represents command text string (an SQL statement or a stored procedure name). If it is empty string, no command text is associated with the command, and you have to call SQL.SetCommandText method later.
CommandType Optional
Type of a command. Can be CmdSQLStmt, CmdSQLStmtRaw or CmdStoredProc.
ID Optional
The ID to use instead of default one.
Must be unique. If none is provided, the plugin will create one.


Returns command reference number or error message.


Creates a new command.
Don't forget to free command with SQL.FreeCommand.
SQL command reference numbers are starting at 23000 and counting up for each new command.


Creates a new command to create table:

MBS("SQL.NewCommand"; $Connection; "CREATE TABLE Test(FirstName VARCHAR, LastName VARCHAR, Birthday date, NumberOfOrders integer, TotalSales double)")

Run a stored procedure:

# new command for calling our test procedure on a Microsoft SQL Server
Set Variable [$command; MBS( "SQL.NewCommand"; $Connection; "dbo.Test" ) ]
# set a parameter
Set Variable [$r; MBS( "SQL.SetParamAsNumber"; $Command; "Param1"; 7 ) ]
# execute query
Set Variable [$r; MBS( "SQL.Execute"; $Command ) ]
# fetch first record
Set Variable [$r; MBS( "SQL.FetchNext"; $Command ) ]
# get result field
Set Variable [$result; MBS( "SQL.GetFieldAsText"; $Command; 1 ) ]

New command with named parameters:

MBS("SQL.NewCommand"; $Connection; "update Documents set ProductNumber=:ProductNumber, PubOptionNo=:PubOptionNo, DueInStock=:DueInStock, ProductTypeID=:ProductTypeID where DocID=:DocID“ )

See also

Example Databases

Blog Entries

Created 18th August 2014, last changed 19th November 2018

SQL.MySQL.InsertID   -   SQL.NewConnection

Feedback: Report problem or ask question.

MBS FileMaker Plugins