KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Avoid Directly Using Parameters in SQL Statements
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: May 16, 2022

When writing an SQL statement in 4D, avoid directly referencing any of the method parameters in the statement. References to parameters in an SQL statement is not supported in compiled mode. Doing so may cause a compiler error during compilation or a runtime error during execution. This is true for both sequential and named parameters.

It is necessary to assign the parameter to a variable.

In the example below, the parameters $param_1 or $1 is assigned to the variable $name. Then $name is used in the SQL statement.

#DECLARE($param_1 : Text)
var $name : Text

$name:=$param_1

//OR
//var $1 ; $name : Text
//$name:=$1

Begin SQL
  SELECT *
  FROM customer
  WHERE first_name = :$name
End SQL