Previous Document Next Document

What is the query syntax?

Each query expression that is evaluated should yield a result object of any of the supported query items.

Here are some sample query expressions:

1 + 2 
2 * (2.3 + 1.2) 
'Hello' + ' world' 

Each operand in the expression is an object — even the constants such as 1 or 'Hello'. For constants, the data type is determined automatically. Each object can have its own set of methods and properties. To call a method of an object, the following syntax is used:

object.method(parameters) 

Methods that do not require any parameters can be called without using the parentheses. Both of the following expressions are valid:

'world'.length() 
'world'.length 

The preceding expressions evaluate to a numeric value of 5, the length of the string 'world'.

How can repetition in expressions be reduced?

In many cases, various properties of the same object must be inspected in an expression. To reduce expression repetition, a special expression can be used to reference methods of the same class repeatedly. A special construct with square brackets ( [] ) can be used for this:

object[.method1 + .method2 * .method3] 

For example, if the current object is a shape with the fill property, and you want to evaluate several fill properties of the current shape, the following expression can be used:

@fill[.type = 'uniform' and .color = 'red'] 

The preceding expression is equivalent to the following:

@fill.type = 'uniform' and @fill.color = 'red' 

The following example returns TESTtest:

'Test'[.toUpper + .toLower] 
What are the supported query operators?

You can include the following operators in your queries:

Operator
Data type
Action
Example
Result
+
numeric
addition
1 + 2 
3
+
string
string concatenation
'Lorem' + ' 
ipsum' 
'Lorem ipsum'
-
numeric
subtraction
10-4 
6
*
numeric
multiplication
2 * 5 
10
/
numeric
division
3 / 2 
1.5
\
numeric integer
division
3 \ 2 
1
^
numeric
power
2 ^ 3 
8
>
any
greater than
3 > 2 
True
<
any
less than
10 < 3 
False
>=
any
greater than or equal to
2 >= 2 
True
<=
any
less than or equal to
3 <= 10 
True
=, ==
any
equal to
2 = 3 
False
<>
any
not equal to
2 <> 3 
True
=
string
case-insensitive equality
'Lorem' = 
'lorem' 
True
==
string
case-sensitive equality
'Lorem'=='lor
em' 
False
<>
string
case-insensitive inequality
'Lorem'<>'lor
em' 
False
>, >=, =, <=, <
string
case-sensitive comparison
'Lorem' >= 
'lorem' 
False
&, and
Boolean
logical AND
2 = 2 and 1 = 
1 
True
|, or
Boolean
logical OR
2 = 1 or 1 = 1 
True
!, not
Boolean
logical NOT
not (2 = 2) 
False
.
object
object method call
(-1).abs() 
1

As in most programming languages, operators have certain precedence:

  • level 1 — . (object method call)
  • level 2 — ^
  • level 3 — *, /, \
  • level 4 — +, -
  • level 5 — >, <, =, ==, <=, >=, <>
  • level 6 — not, !
  • level 7 — and, or, &, |

Consider the following example:

2 * 2 + 3 

In the preceding example, multiplication is performed first and addition second (because the multiplication operator [ * ] has a higher precedence than the addition operator [ + ]).

Parentheses ( () ) can be used to modify the precedence, as in the following example:

2 * (2 + 3) 

Previous Document Next Document Back to Top

Copyright 2007 Corel Corporation. All rights reserved.