OQL vs. ODMG 3 OQL
OQL implements all the ODMG OQL functionalities with a few exceptions
concerning the select clause.
In order to accept the whole DML (Data Manipulation Language) query part of
SQL as a valid syntax for ODMG OQL, ad-hoc constructions have been
added to ODMG OQL each time SQL introduces a syntax that cannot be
considered in the category of true operators.
For instance, the following construct is a valid ODMG OQL construct:
select p.name, salary from Professors p
This construct is not currently a valid OQL construct. The alternate valid
OQL form is:
select struct(name: p.name, salary: p.salary) from Professors p
In the same way, ODMG OQL accepts SQL forms of the agregate operators
min, max, count, sum and avg, for instance:
select count(*) from Persons
select max(e.salary) from Employees e
These constructs are not currently valid OQL constructs. The alternate valid
OQL forms are:
count(select p from Persons p)
max(select e.salary from Employees e)
In the same way, the select * clause is not currently implemented
in OQL, neither the implicit select clause (i.e. without explicit
identifier). For instance, the following constructs are not OQL valid
constructs, although there are valid ODMG OQL constructs:
select * from Person
select name from Person
There is no alternate OQL valid form for the first construct.
The alternate OQL valid forms for the second construct is:
select Person.name
select p.name from Person p
select p.name from Person as p
select p.name from p in Person
On the other hand, OQL provides a few extensions to ODMG OQL:
- assignment operators,
- four regular expression operators,
- selection statements, if/else,
- iteration statements, while, do/while, two forms
of for,
- function definition statements, function,
- the eval and unval operators,
- identifier operators, isset, unset,
refof, valof, &, *, push,
pop,
- exception management operators, throw,
- type information operators, classof, typeof
- miscellaneous operators, structof, bodyof
- builtin and library functions.
For instance, the following constructs are valid OQL constructs:
for (x in l)
{
if (classof x != "Person")
throw "Person type expected";
if (x->name ~ "^john")
{
ok := true;
break;
}
}
function fib(n) {
if (n < 2)
return n;
return fib(n-1) + fib(n-2);
}
for (n := 0, v := 0; n < 15; n++)
v += fib(n);
function swap(x, y) {
v := *x;
*x := *y;
*y := v;
}
i := "ii"; j := "jj";
swap(&i, &j);
function get_from(classname, attrname) {
return eval "select x." + attrname + " from " + classname + " x";
}
names := get_from("Person", "name");
These extensions make OQL computationally complete.
Some of the ODMG OQL functionnalities or specificities are not yet implemented:
- the group by/having operator,
- the order by operator is more restrictive than in the
ODMG specifications,
- contrary to ODMG OQL, it is necessary to put parenthesis to call
a function or method with takes no arguments,
- contrary to ODMG OQL, the || operator does means string
concatenation. It is the logical or operator. This will be changed
in a future version.
EyeDB manual