Subsections


Eval/Unval Operators

eval Operator

One major feature of OQL is that one can invoke its evaluator using the eval operator. This allows us to build OQL constructs at runtime and perform their evaluation. This is very useful, for instance, when we want to build a query expression where the projection or the from reference sets are is unknown. For instance, the following function allows us to retrieve the values of the attribute attrname in the class classname:
function getValues(classname, attrname) {
  cmd := "select x." + attrname + " from " + classname + " x";
  return (eval cmd);
}

General Information
Operator eval
Syntaxe eval string
Type unary
Operand Types string
Functions calls the OQL evaluator on the string operand. The string operand can contain any OQL valid construct: an expression, a statement or a sequence of statements.

Expression Examples
expression result
eval "10" 10
eval "a := 100" result is 100; the variable a is set to 100
eval "a := \"hello\"; b := a + \"world\"" result is "hello world"; the variable a is set to "hello"; the variable b is set to "hello world"

unval Operator

The unval is the inverse of the unval in the sense that it takes any valid OQL expression and returns the string representation; the comments and, when not necessary, the spaces and tabulations are skipped. For instance, the construct unval a := 10 returns "(a:=10)".
General Information
Operator unval
Syntax unval expr
Type unary
Operand Types any type
Functions returns the string expression

Expression Examples
expression result
unval 10 "10"
unval alpha += 10 - beta + 1 "(alpha:=(alpha+((10-beta)+1)))"
eval unval alpha := "hello" returns "hello"; alpha is set to "hello"

EyeDB manual