Converts a alphanumeric string in a ''sql'' operator. The string format to convert is identical to what a user enters when making a selection in an input field of an object, or on a variable of construct type.
So, in the expression to convert there is wildcars characters, such as those used in an input field of an object. Convertion rules to be considered:
- The character | separing two strings or two numbers is converted to an operator IN. For example "alb" is converted IN ('a', 'b').
- The character : separing two strings or two numbers is converted in a operator BETWEEN. For example "A:Z" sis converted BETWEEN 'A' AND 'Z'.
- The tag <null /> is converted in the operator IS NULL.
- The character % inside of a string is converted in an operator LIKE. For example "PREFIX%" is replaced by LIKE "PREFIX%".
- The character _ inside of a string is converted in an operator LIKE.
- A string without wildcar or a number is converted in an operator =. For example "580", will be converted to = 580.
1 sql.getQueryOperator
<sql.getQueryOperator type='string|integer'>
<value /> !
</sql.getQueryOperator>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Atype | string | Indicate the data type on which the operator is established. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Evalue | string | String to convert in operator SQL. |
Returns | |
---|---|
Type | Description |
string | Returns the operator SQL which corresponds to the string parameter. |
Example
Example with several operators.
Copy
<xsql-script name='test_getQueryOperator'> <body> <println><string.ht />1|2<string.ht />==><string.ht /><sql.getQueryOperator type='number'>1|2</sql.getQueryOperator></println> <println><string.ht />a|b|c<string.ht />==><string.ht /><sql.getQueryOperator type='string'>a|b|c</sql.getQueryOperator></println> <println><string.ht />a:b<string.ht />==><string.ht /><sql.getQueryOperator type='string'>a:b</sql.getQueryOperator></println> <println><string.ht />a<string.ht />==><string.ht /><sql.getQueryOperator type='string'>a</sql.getQueryOperator></println> <println><string.ht />A%<string.ht />==><string.ht /><sql.getQueryOperator type='string'>A%</sql.getQueryOperator></println> <println><string.ht />A_<string.ht />==><string.ht /><sql.getQueryOperator type='string'>A_</sql.getQueryOperator></println> <println><string.ht /><null /><string.ht />==><string.ht /><sql.getQueryOperator type='string'><null /></sql.getQueryOperator></println> </body> </xsql-script>
Result of the execution:
Copy
1|2 ==> IN (1,2) a|b|c ==> IN ('a','b','c') a:b ==> BETWEEN 'a' AND 'b' a ==> = 'a' A% ==> LIKE 'A%' A_ ==> LIKE 'A_' null ==> IS NULL