Previous Document Next Document

Including queries in macros : Understanding the query syntax


Understanding the query syntax

Each query expression yields a result object that belongs to one of the supported types (see Understanding CQL).

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 which the data type is determined automatically. In addition, each object has its own set of members (that is, properties and methods). You can use the following syntax to call an object member:

object.member(parameters)

Members that do not require any parameters can be called without the parenthetical content, so both of the following expressions are valid:

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

The preceding expression evaluates to a numeric value of 5, the length of the string 'world'.

Reducing repetition in expressions

In many cases, various properties of the same object must be inspected in an expression. To reduce repetition, a special construct involving square brackets ( [] ) can be used:

object[.method1 + .method2 * .method3]

For example, if you want to evaluate multiple fill-related properties for the current shape, you can use an expression such as the following:

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

The preceding expression is equivalent to the following expression:

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

Similarly, the following example returns TESTtest:

'Test'[.toUpper + .toLower]
Understanding the supported query operators

You can include the following operators in your queries:

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

For example, the expression 2 * 2 + 3 performs the multiplication first and the addition second because the multiplication operator ( * ) has a higher precedence than the addition operator ( + ). To modify the precedence and perform the addition first, you must use parentheses ( () ) to modify the expression as follows: 2 * (2 + 3).

Searching for objects

You can use queries to search for shapes, fills, outlines, colors, and global objects. For more information, please see the following topics:

 
 
 
 
 

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.