Log In    |    Knowledge Base    |    4D Home
Tech Tip: Use Placeholder to avoid issue with special characters in ORDA query() method
Published On: February 14, 2019
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Query strings of dataClass.query( ) method in ORDA can be constructed into one single parameter containing attributePath, comparator and values. Query values can also be marked using placeholders (:1, :2, etc) in query string where actual values are provided as value parameters. For example, both queries below are equivalent and will get the same result:


Typically, both forms can be used interchangeably without issues. However, placeholders can help avoid errors related to special characters. For example, if the user searches for a company named “Tiffany & Co.”, the query string that has values inline would be:

//This query will generate an syntax error
$result:=ds.Company.query("Name=Tiffany & Co.")
//This query works fine
$result:=ds.Company.query("Name=:1";"Tiffany & Co.")

The first query will generate a syntax error in 4D as “&” is “AND” logical operator. Values between “&” and next “=” will be regarded as an attribute. The query above will be seen as incomplete as 4D can not find an attribute named “Co.”:

Using placeholder and passing in values in parameter can avoid such issues, because special characters in value parameter will be parsed as query value and will never be treated as part of attributePath or comparator. It is a recommended practice to utilize placeholders as it less likely to have formatting or character issues.