Subsections


Comparison Expressions

The expression syntax, semantics, associativity and precedence are quite identical to the corresponding C and C++ expressions except that the equal operator could be either == or =.


Equal and NotEqual Expressions

Operands may have any type at all. If the type of the operands differ (modulo the type promotion mechanisms for numbers), the result of the expression operand1 == operand2 is always false while the result of operand1 != operand2 is always true.
General Information
Operators ==
  !=
Type binary
Syntaxes expr == expr
  expr != expr
Commutative yes
Operand Types any type
Result Type boolean
Functions equal
  not equal
When operands are number of different types, an automatic promotion is done to the more precise type.
Expression Examples
expression result
1 == 1 true
1 == 1.0 true
1 != 2 true
1 == 2 false
1 == "hello" false
"hello" == "hello" true
list(1, 2, 3) == list(1, 2, 3) true
set(1, 3, 2) == set(1, 2, 3) true


Less and Greater Expressions

The comparison operators <, <=, > and >= are multi-purpose operators: they are used for integer, floating point number and character comparison, but also for list or array term-to-term comparison and for set or bag inclusion. Their functionality depends on the type of its operands: they are polymorphic operators. Note that the choice of the functionality is done at evaluation time, not at compile time. That means that the functionality of an expression such as x < y is unknown until the evaluation time. Depending on the dynamic type of the operands x and y, it can be an arithmetic comparison (if x and y are numbers), a alpha-numeric comparison (if x and y are strings), a term-to-term ordered collection comparison (if x and y are lists or arrays) or a set or bag inclusion comparison (if x and y are sets or bags).

While arithmetic and alpha-numeric comparisons are trivial and do not need any suplementary explanations, the term-to-term ordered collection comparisons needs to be detailed.

The general algorithm for this functionnality is as follows:
  1. let l1 and l2 two OQL ordered collections, containing respectively l1_cnt and l1_cnt atoms.
  2. let op one of the following polymorphic comparison operators: < <= > >=,
  3. l1 op l2 is true if and only if all the following conditions are realized:
    1. l1 and l2 must be of the same collection type,
    2. l1_cnt op l2_cnt or l1_cnt equals l2_cnt
    3. for each atom l1[i] with i in [i,l1_cnt], l1[i] op l2[i]
For instance:
list(1, 2) <= list(0, 2) is true
list(1, 2) <= list(3) is false
list(1, 2) <= list(3) is false
list("aaa", 4) < list("bbbb", 8) is true
list("aaa", 4, list(1, 2)) < list("b", 8, list(2, 3)) is true
list(set(2, 4), 3) < list(set(4, 2, 3), 4) is true
list(2, 3) < list("hello", 2) raises an error
list(2, 3) < array(2, 4) raises an error

Note that the fact that l1 <= l2 is false does not implie that l1 > l2 is true. Indeed, list(2, 3) < list(1, 3, 2) and list(1, 3, 2) >= list(2, 3) are false.
General Information
Operators <
  <=
  >
  >=
Type binary
Syntaxes expr < expr
  expr <= expr
  expr > expr
  expr >= expr
Commutative no
Operand Types integer, float, char, string, list, array, set, bag
Result Type boolean
Functions the function depends on the operands:
  < : less than or is included in
  <= : less than or equal or is included in or equal
  > : greater than or contains
  >= : greater than or equal or contains or equal

Possible Operand Combinations
first operand type second operand type result type comments
integer, char, float integer, char, float boolean performs an arithmetic comparison
string string boolean performs an alpha-numeric comparison
set set boolean performs an inclusion comparison
bag bag boolean performs an inclusion comparison
set bag boolean performs an inclusion comparison: the set operand is converted to a bag
bag set boolean performs an inclusion comparison: the set operand is converted to a bag
list list boolean performs a term-to-term polymorphic (i.e. numeric, alpha-numeric or inclusion) comparison
array array boolean performs a term-to-term polymorphic comparison
Note that in case of different operand types, an automatic promotion is done to the more precise type.
Expression Examples
expression result
1 < 2 true
1 >= 2 false
2. <= 2 true
"hello" < "world" true
"hello" >= "world" false
list(1, 2) < list(2, 3) true
list(1, 2) < list(0, 3) false
list(1, 2) < list(0, 3, 2) false
list(0, 3, 2) >= list(1, 2) false
list(1, 2) < list(2, 3, 3) true
list(1, 2) < list(0) false
set(1, 2) < set(2, 4, 44) false
set(1, 2) < set(2, 1, 44) true
"hello" >= 3 raises an error
list(1, 2) < array(2, 4, 44) raises an error
set(1, 2) < bag(2, 1, 44) raises an error


Regular Expression Operators

OQL provides the ODMG OQL regular expression operator like plus four other ones. These four extra operators are based on the regular expression UNIX library. So, the syntax of the regular expression are the same as that used by the well known UNIX tools grep, sed, and so on. All the regular expression operators takes two string operands: the first one is the string to compare, the second one is the regular expression. So, these operators are not commutative. These operators provide the following functionalities:

like 		 : ODMG OQL operator. Returns true if the firstoperand matches the regular expression.

Otherwise false is returned. The regular expression is am SQL regular expression where,
for instance, % and _ are wilcard characters.
~ : This operator hasthe same functionnality as the like operator but theregular expression
has the UNIX syntax.
  : Returns true if the firstoperand matches the regular expression in a case insensitive way.
Otherwise false is returned.
!~ : Returns true if the firstoperand does not match the regular expression.
Otherwise false is returned.
!~~ : Returns true if the firstoperand does not match the regular expression in a case insensitive
way. Otherwise false is returned.
Note that the operator like uses currently the UNIX form of regular expressions instead of the SQL form. It will become ODMG/SQL compliant in a next version.
General Information
Operators ~
  ~~
  !~
  !~~
  like
Type binary
Syntaxes expr ~ expr
  expr ~~ expr
  expr !~ expr
  expr !~~ expr
  expr like expr
Commutative no
Operand Types string
Result Type boolean
Functions
~ : matches the regular expression
  : matches the regular expression, case insensitive
!~ : does not match the regular expression
!~~ : does not match the regular expression, case insensitive
like : matches the regular expression

Expression Examples
expression result
"hello" ~ "LL" false
"hello" ~~ "LL" true
"hello" ~ "^LL" false
"hello" ~ "^h" true
"hello" !~ "^h" false
"hello" ~ ".*ll.*" true
".*ll.*" ~ "hello" false because regular expression should be on the right

EyeDB manual