qv(X)

Returns a properly quoted and escaped string for insertion in Macro Language code.

Syntax

qv(X)

Input

Argument Type Description
X any The string on which to apply the function

Can be a scalar or list-value

Return Value

Returns X as a properly quoted and escaped string for insertion in Macro Language code.

If X is a list-value, qv(X) creates a string of quoted values from the items in the list-value. This is particularly useful when specifying the items in the list-value in a selection expression.

qv(X) also properly escapes any characters in X.

Example: Escape a string used in a selection expression

In the following example, the qv(X) function is used to properly escape a string used in a selection expression. To search for items in the description column of pub.doc.retail.product that contain the string 9", the qv(X) function must be used to properly escape it.

<base table="pub.doc.retail.product"/>
<let search_string="9&quot;">
  <sel value="(contains(description;{qv(@search_string)}))"/>
</let>

If the qv(X) function was not specified, the query would have resulted in an error stating that the " was a bad character.

Example: Create a string of quoted values from a comma-separated list

The following example illustrates how to use the str_to_lst(S;D) and qv(X) functions to turn a comma-separated list into a string of quoted values that can be used in a selection expression.

<base table="pub.doc.retail.store"/>
<set divs="West,North"/>
<let divs_quoted="{qv(str_to_lst(@divs;','))}">
  <sel value="divisiondesc={@divs_quoted}"/>
</let>

The variable divs is a comma-separated string consisting of two elements: West and North. The string is first turned into a list-value using the function str_to_lst(S;D), which is then passed to the qv(X) function. The qv(X) function converts a list-value into a string of quoted values, which can be used in a <sel> operation. The string of quoted values is assigned to the variable divs_quoted, which is declared in a <let> statement. Inside the <let>, the <sel> operation then references the value of the divs_quoted variable.

The code, after expansion, is:

<base table="pub.doc.retail.store"/>
<sel value="divisiondesc='West''North'"/>

The result is shown below:

Example: Specifying a selection expression from a list-value in a QuickApp

The following example is a QuickApp that demonstrates how the qv(X) function can be used to take items in a list-value and use them in a selection expression.

<dynamic stations="{pkg(;)}">
  <layout arrange_="v">
    <layout arrange_="h">
      <widget class_="dropdownlist" serverfilter_="0" casesensitive_="0" 
       filter_="beginswith" numhints_="50" rowvalue_="@stations" 
       label_="stations" base_="pub.demo.weather.stations">
        <tabu breaks="id,name">
          <tcol name="count" source="name" fun="cnt"/>
        </tabu>
        <colord cols="id,name"/>
      </widget>
      <widget class_="grid" type_="scroll" base_="pub.demo.weather.stations">
        <if test="{@stations.id._defined}">
          <sel value="id={qv(@stations.id)}"/>
        </if>
      </widget>
    </layout>
    <layout arrange_="v">
      <layout arrange_="h">
        <widget class_="text" text_="list-value:" width_="75" 
         require_="{@stations.id._defined}" invmode_="hide"/>
        <widget class_="text" text_="{@stations.id}" 
         require_="{@stations.id._defined}" invmode_="hide"/>
      </layout>
      <layout arrange_="h">
        <widget class_="text" text_="qv result:" width_="75" 
         require_="{@stations.id._defined}" invmode_="hide"/>
        <widget class_="text" text_="{qv(@stations.id)}" 
         require_="{@stations.id._defined}" invmode_="hide"/>
      </layout>
    </layout>
  </layout>
</dynamic>

The values selected in the dropdownlist widget are stored as a package in the dynamic variable stations (as specified by the rowvalue_ attribute). The package consists of list-values of the IDs (stations.id) and names (stations.name). The query associated with the grid widget passes the stations.id list-value to the qv(X) function, the results of which are used in the selection expression to display only those rows whose IDs are selected.

For illustrative purposes, text widgets display the list-value associated with stations.id and the result of the qv(X) function.