QUOTER function
- Last Updated: January 16, 2024
- 3 minute read
- OpenEdge
- Version 12.8
- Documentation
Converts the specified data type to CHARACTER and encloses the results in quotes when necessary.
The QUOTER function is intended for use in
QUERY-PREPARE where a character predicate must be created from a
concatenated list of string variables to form a WHERE clause. In order to
process variables, screen values, and input values so that they are suitable for a query
WHERE clause, it is often necessary to enclose them in quotes. For
example, European-format decimals and character variables must always be enclosed in quotes.
You can use the QUOTER function to meet that requirement.
Syntax
|
- expression
- An expression in the data type that you want to convert to character and enclose with quotes.
- quote-char
- Either a single or double quote, enclosed in the opposite:
"'"or'"'. The default is double quote. Passing?for this argument results in double quotes. - null-string
- The string you want for an unknown value: the word
NULLor""for example. The default is an unquoted question mark, which is the Unknown value (?).For example, the following code:DEFINE VARIABLE mychar As CHARACTER NO-UNDO INITIAL "Lift Line Skiing". ... qhandle:QUERY-PREPARE("FOR EACH Customer WHERE Customer.Name = " + QUOTER(mychar))Would produce this prepare-string:FOR EACH Customer WHERE Customer.Name = "Lift Line Skiing".
Notes
- To address the situation where an Unknown value (
?) in a list of concatenated strings could cause the entire string to be unknown and theQUERY-PREPAREto fail, theQUOTERfunction does not return the Unknown value (?) if the expression argument is unknown. Instead, it returns a known character value consisting of an unquoted question-mark, by default, or the third argument, if it is present. - Also, in this situation, a quoted question-mark is not used because it
is interpreted as string data in a
WHEREclause. After the concatenation is complete, the AVM supplies a normal question mark.For example, the following code:DEFINE VARIABLE mychar As CHARACTER NO-UNDO. ... mychar = ?. qhandle:QUERY-PREPARE("FOR EACH Customer WHERE Customer.Name = " + QUOTER(mychar)).Would produce this prepare-string:FOR EACH Customer WHERE Customer.Name = ?.However, giving the third parameter as
"NULL"producesNULLrather than?. - For noncharacter data types, if expression is of type DECIMAL, INT64, INTEGER, DATE, DATETIME, DATETIME-TZ,
and so on, the following occurs:
- The expression is converted to
character and enclosed in quotes. The conversion is similar to the
EXPORTformat. DATE types, however, always have the 4-digit year. - Data types with no
DISPLAYformat like MEMPTR and LVARBINARY return the Unknown value (?). - If a data type is of type RAW, it is converted to base 64.
For example, the following code:DEFINE VARIABLE mydec As DECIMAL NO-UNDO INITIAL 12.34. ... qhandle:QUERY-PREPARE("FOR EACH Customer WHERE Customer.Balance = " + QUOTER(mydec)).Would produce this prepare-string:FOR EACH Customer WHERE Customer.Balance = "12.34".This is especially important for European format decimals that look like
12,34and would not compile in the above statement unless they are enclosed in quotes. - The expression is converted to
character and enclosed in quotes. The conversion is similar to the
- If expression is of data type
CHARACTER, quotes that are part of the string are doubled. However, if the first and last
characters are already quotes, then it is assumed that the quoting has already been done,
and no further quotes are applied. Since
QUOTERallows you to define quote-char to either the single or the double quote character, you can specify quote-char so it does not match the quotes in the character expression.For example, if there is a record whoseNamefield is set to"Lift Line Skiing", including the quotes, the string in theWHEREclause must also contain quotes or the record is not returned by the query.VAR CHARACTER mychar. ... mychar = '"Lift Line Skiing"'. qhandle:QUERY-PREPARE("FOR EACH Customer WHERE Customer.Name = " + QUOTER(mychar)).The following is the resulting query string which would not include the desired record:FOR EACH Customer WHERE Customer.Name = "Lift Line Skiing".To avoid this issue, specify a single quote for the quote-char parameter:qhandle:QUERY-PREPARE("FOR EACH Customer WHERE Customer.Name = " + QUOTER(mychar, "'")).The resulting query string contains the proper value and matches the value in the record:FOR EACH Customer WHERE Customer.Name = '"Lift Line Skiing"'. - You can use the
QUOTERfunction with an object reference for a class instance to obtain a unique object identifier within the session as a quoted character string. - When applied to an enum instance,
QUOTERwill return the enumeration member name as a string. If the enum instance is a flag enum with multiple flags set, the string will be a comma-delimited list of the flags.