We first describe the design principles of the language in Section 2, then in Section 3 we present the main differences between EyeDBOQL and ODMG OQL. In this chapter, OQL denotes the EyeDBO Object Query Language, while the standard ODMG 3 Object Query Language will be denoted as ODMG OQL. Extensions to ODMG OQL relate to function definitions, selection statements, iteration statements, assignment operator (see section 3).
Terminal Atom Syntax
We will first present the syntax of atoms that can be expressed as terminals, and then a way to construct non-terminal atoms. Note that oidatoms are not entered directly by the user, but are produced by the database through an OQL interpreter. Note that object atoms are not entered directly by the user, but are generated by the OQL interpreter.
Non Terminal Atom Production
Keywords
Comments
Statements
Expression Statements
This table is skipped if the operand type combination is unique or trivial. The examples that manipulate database objects use the schema that can be found in the guide.
Atomic Literal Expressions
Arithmetic Expressions
Multiplicative, division, and minus expression syntax, semantics, associativity, and precedence are quite identical to the corresponding C and C++ expressions. Syntax expr<
Assignment Expressions
Operand types left values on the left side and any type on the right side Result Type the type of the right operand Functions perform an operation and.
Auto Increment & Decrement Expressions
Comparison Expressions
So the syntax of the regular expression is the same as that used by the well-known UNIX toolsgrep, sed, and so on. The regular expression is a regular SQL expression, where for example %and are arbitrary characters. This operator has the same functionality as the like operator, but the regular expression uses UNIX syntax.
Logical Expressions
Conditional Expression
Conditional function evaluation: evaluates and returns the second operand if the first operand is true; otherwise evaluates and returns the second operand.
Expression Sequences
Array Deferencing
If expr is greater than or equal to the size of the collection, an out of bounds error is raised. If expr is greater than or equal to the size of the array, an out of bounds error occurs. Result Write char if the first operand is a string, otherwise write the returned item in the indexed collection or non-collection array.
Identifier Expressions
The operator*(identical tovalof) is used to get the value of the identifier pointed to by the reference. The range operator returns a "global" or "local" string depending on whether the identifier is global or local. The result type identifier, or any type in the case of an assignment function, pushes the identifier onto the symbol table stack.
Path Expressions
Functions return the value of the attribute denoted by the second operand of the object denoted by the first operand. The first operand must indicate an EyeDB instance (object or literal) of the aggregate, including the attribute indicated by the second operand.
Function Call
Method Invocation
Note: contrary to the ODMG 3 specifications, one must currently use parentheses to call a method, even if the method has no arguments. Result Type type atom returned by the method call Functions calls the method indicated by the second. The first operand must indicate an EyeDB instance (object or literal) of an aggregate, including the method whose name is the second operand.
The number of arguments and the type of arguments must match one of the methods included in the class of the object specified by the first operand. As in C++, method calls use a combination of the scope operator and the function call operator. The overloading and late binding mechanisms are the same as for instance method invocations.
The first operand must indicate an EyeDB class of an aggregate, including the class method whose name is the second operand. The number of arguments and the type of arguments must match one of the class methods included in the class indicated by the first operand.
Eval/Unval Operators
Set Expressions
Functions coll1 < coll2: Returns where if and only if coll1 is included in coll2 but is not equal to coll2.
Object Creation
Object Deletion
Collection Expressions
In all of the following examples, the OQL variable sp0 indicates the firstPersoninstance in the database: p0 := first(select Person). Functions return if the first operand belongs to the collection pointed to by the second operand; otherwise false. Functions add the first operand to the non-indexed collection (i.e., bag or set) pointed to by the second operand; returns the first operand.
Functions get the element in the collection pointed to by the first operand at the position pointed to by the second operand. Functions get the elements in the collection pointed to by the first operand at the position range pointed to by the second and third operands. Functions get all the elements in the collection pointed to by the first operand If used against a left value, get references to those elements.
Functions suppress the first operand from the unindexed collection (i.e. bag or set) pointed to by the second operand; Functions returns true if it exists in the set referenced by the second operand, an element for which the third operand evaluates to true. Functions returns true if for all items in the collection referenced by the second operand, the third operand evaluates to true.
Functions return true if the number of items in the collection pointed to by the third operand for which the third operand evaluates to the range [first operand, second operand].
Exception Expressions
Function Definition Expressions
Because the last operand of the define/as operator is an arbitrary OQL expression, it can be an array of expressions using the comma string operator.
Conversion Expressions
If the operand is a string of length one, it returns the character of that string.
Type Information Expressions
Query Expressions
The projection expression is evaluated for each object in the collection, and the results of these evaluations are collected in abag. For example, assuming that each attribute in our schema is indexed, the query select Person.name = "john" uses the index on the attribute name as a terminal index. The query select Person.spouse.age < 23 uses the index on the attribute age as a terminal index, and the index on the indirect attribute spouseas a nonterminal index, while the query select Person.spouse oid uses the index on thespouseattribute as a terminal index.
The query select Person.children[?].spouse.name = "mary" uses the index of the attributes name, spouse, and the attributes of the literal collection children. Queries with a where clause containing logic and constructs are optimized to take advantage of the index. For example, assuming there is an index on thename attribute and no index on theageattribute, the query select x from person x where x.age = 100 and x.name = "john" will query the thename attribute first and then will filter the result according to the given predicate on the attribute attribute.
If the two expressions around the logicaland operator have an index, or if neither of the two expressions has an index, the interpreter executes the left part first and then the second part. Finally, the select Person.name query directly reads the index of the name attribute, rather than reading the name of each person instance. This construct will not make use of the index of the spouse attribute (but it will use the index of the name attribute).
In some specific cases the OQL interpreter knows how to optimize the data, but in most cases it does not.
Miscellenaous Expressions
Its operand is a string indicating the absolute path (ie, starting with a/) or the relative path (ie, not starting with a/) of the file to import. When the path is relative, the OQL interpreter will look in all directories pointed to by the EyeDB oqlpath configuration variable. If the filename has a no.oqlex extension, the OQL interpreter will automatically append it.
Selection Statements
Iteration Statements
While the boolean expression cond expr evaluates to true, the statement is executed and the expressionexpr2 is evaluated. Semantics: For each element in the collection defined by expr. is indicated, the variable var is assigned to this element and the statement is executed.
Jump Statements
Function Definition Statements
As in C and C++, the arguments with a default value must not be followed by any argument with default values. So, one needs a way to tell the interpreter that we don't want to evaluate the second and third arguments. Note that the function defined in the body of the function calculator has a global scope, this means that the function is available at the global level of the OQL session after one execution of calculation.
It is possible that in a future version the functions defined in the body of a function definition will have a local scope. The oql$functionsvalue is a list whose elements are the names of all the OQL functions defined in the current OQL session. This OQL Quick Reference Manual provides comprehensive information about the built-in and library functions and methods, the special variables, and theeyedboqltool.
The standard library source code is presented and it provides a quick reference map containing all the language constructs.
Builtin and Library Functions and Methods
Using the class object's own methods, we can perform a few actions, such as retrieving the oid of an instancegetOid(), retrieving the database of an instancegetDatabase(), or converting the instance's string representation toString(). The following methods are the instance methods of the class database: They can be applied to a database object that can be either oql$d or an object obtained using the new operator, for example: new <> database(name: "foo").
Special Variables
The eyedboql Tool
Although the statement is not complete, eyedboql provides the “second prompt” (“>> ” by default) after each new line. By default, an eyedboql session opens the EYEDBDBM database in read-only mode. Please note that a transaction will automatically start before the first full statement of the session or before the full statement immediately following it.
The Standard Library Package
OQL Quick Reference Card