KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Use named placeholders to handle spaced field names in ORDA queries
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: December 20, 2022

When dealing with field names that contain spaces, doing the typical ORDA query may be a bit trickier. For example, given table field "Field 2", the query below would return a runtime error due to how ORDA query strings not treating spaces as part of a field name.

$es:=ds.Table_1.query("Field 2 = :1"; "Test@") // <-- Runtime error


Instead, named placeholders can be used to essentially nickname the field and placeholders using an object containing the properties attributes and parameters as shown below:

$queryParams:=New object
$queryParams.attributes:=New object("attr"; "Field 2")
$queryParams.parameters:=New object("param"; "Test@")
$es:=ds.Table_1.query(":attr = :param"; $queryParams)


In this example "attr" is treated as "Field 2" and "param" is treated as "Test@" which the ORDA query will accept. Be sure to use these named placeholders for any space field names to avoid runtime errors.