contentSelect
The contentSelect function can be used to output data records from the Content Store and can be used for further processing.
The function offers the opportunity to filter and/or sort data records.
The result (return value) of the function is a list which contains all data records matching the filter criteria. This list can be output for example using the instruction $CMS_FOR(...)$ (see section Output).
Syntax of the contentSelect function
The basic structure of the contentSelect function is as follows:
<CMS_FUNCTION name="contentSelect" resultname="IDENTIFIER">
<CMS_PARAM name="schema" value="IDENTIFIER" />
<CMS_VALUE_PARAM name="IDENTIFIER" value="VALUE" />
...
<QUERY entityType="IDENTIFIER">
<FILTERPARAM parameter="IDENTIFIER" datatype="DATATYPE" value="DEFAULT SELECTION" />
<FETCHMODE attribute="ATTRIBUTE" lazy="NUMERICAL_BOOLEAN_VALUE" />
<ORDERCRITERIA attribute="ATTRIBUTE" descending="NUMERICAL_BOOLEAN_VALUE" />
...
<EQ attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<NEQ attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<GT attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<GTE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<LT attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<LTE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<IS_NULL attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<NOTNULL attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<LIKE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<AND>
<EQ attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
...
<LIKE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<OR>
...
</OR>
...
</AND>
<OR>
<EQ attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
...
<LIKE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<AND>
...
</AND>
...
</OR>
...
</QUERY>
</CMS_FUNCTION>
Parameters of the contentSelect function
The contentSelect function can be divided into a definition and a query part.
Definition part
Attribute | possible values | Mandatory parameters |
---|---|---|
schema | yes | |
any parameter | no | |
The definition part consists of the following parameters:
schema
The schema parameter is used to specify the database schema which is to be used for the query.
The value of the constant is the reference name of the database schema in the Content Store:
<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_PARAM name="schema" value="CONSTANT" />
...
</CMS_FUNCTION>
any parameter
By defining a freely selectable identifier, any number of expressions can be made available to the query as parameters.
The following characters may be used for the identifier:
A to Z, a to z, 0 to 9 and _.
Definition using expressions:
<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_VALUE_PARAM name="IDENTIFIER" value="EXPRESSION" />
...
</CMS_FUNCTION>
Example of the definition of the parameters from and to:
<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_VALUE_PARAM name="from" value="st_startDate" />
<CMS_VALUE_PARAM name="to" value="#global.now" />
...
</CMS_FUNCTION>
Note: st_startDate is a date input component (CMS_INPUT_DATE). #global.now is the starting point of the deployment.
See also page Database queries.
Query part
The query part of a contentSelect function is started with a QUERY tag. The QUERY tag is simultaneously the root element of the query.
All tags which are given between the opening and closing QUERY tag are taken into account in the query.
The entityType parameter is used to give the symbolic table name in the database schema so that the query can be applied to the data records of the corresponding database table.
The limit parameter can be used for limiting the result of the query to a certain number of data sets.
Example:
<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_PARAM name="schema" value="CONSTANT" />
<QUERY entityType="IDENTIFIER" limit="10">
<.../>
</QUERY>
</CMS_FUNCTION>
Output
The result of a contentSelect function can be output as follows:
$CMS_IF(!IDENTIFIER.isEmpty)$
$CMS_FOR(VARIABLE, IDENTIFIER)$
$CMS_VALUE(VARIABLE.fs_id)$: $CMS_VALUE(VARIABLE.COLUMNNAME)$
$CMS_END_FOR$
$CMS_END_IF$
In this example
- IDENTIFIER is the identifier which is defined by the parameter resultname,
- VARIABLE is the name of a variable and
- COLUMNNAME is the name of a table column.