KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Use placeholder to escape single quote when using dataClass.query() in ORDA
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: November 8, 2018

Nowadays people often use closing single quote "'" as right curly apostrophe "’" while typing. Many programs like Word and Search engines like google can recognize “Levi’s” and “Levi's” are the same string.

In V17, the documentation of ORDA’s dataClass.query() stipulates that when quotes are used in query string, it must use single quotes inside query and double quotes to enclose the whole query string. For example:

ds.Employee.query("employee.lastName = 'smith' AND employee.firstName = 'john'")

However, if the query string uses single quote as apostrophe is enclosed with single quotes, this will cause a error in 4D. For example:

ds.Employee.query("companyName = 'Levi's'")

Will get a “Wrong comparison operator”.


This is due to right curly apostrophe "’" and closing single quote "'" are treated as different punctuations in 4D. The single quote used as apostrophe is recognized as extra closing quote which causes an error.

ORDA does not support escaping single quote with "\" in query(). The best way to avoid running into this error is to use place holder. For example, this code below works without any error:

ds.Employee.query("companyName = :1"; "Levi's")

Single quote passed in placeholder will be parsed and escaped safely by query() method.