Subsections


Builtin and Library Functions and Methods

OQL provides a few builtin and library functions. The builtin functions are written in C++ and cannot be overriden while the library functions are written in OQL and may be redefined by the user. The code for the library functions can be found in the section The Standard Library Package. The EYEDB system classes object, database, connection and EyeDB contains builtin class and instance methods that can be accessed from OQL. Some of these methods are briefly introduced in this section.


Type Predicat Functions


is_int(x)		: returns true if x is an int

is_double(x) : returns true if x isa double; otherwise, returns false
is_string(x) : returns true if x isa string; otherwise, returns false
is_oid(x) : returns true if x isan oid; otherwise, returns false
is_num(x) : returns true if x isan number (int, float or char);otherwise, returns false
is_bool(x) : returns true if x isa bool; otherwise, returns false
is_bag(x) : returns true if x isa bag; otherwise, returns false
is_set(x) : returns true if x isa set; otherwise, returns false
is_array(x) : returns true if x isa array; otherwise, returns false
is_list(x) : returns true if x isa list; otherwise, returns false
is_coll(x) : returns true if x isa collection; otherwise, returns false
is_struct(x) : returns true if x isa struct; otherwise, returns false
is_empty(x) : returns true if x isnil; otherwise, returns false

Collection Conversion Functions

The collection conversion functions take one collection argument and convert this collection to another collection type and returns the converted collection.


toset(coll)		: converts coll to a set

tolist(coll) : converts coll to a list
tobag(coll) : converts coll to a bag
toarray(coll) : converts coll to a array
listtoset(coll) : checks that coll is a list then converts coll to a set
bagtoset(coll) : checks that coll is a bag then converts coll to a set
arraytoset(coll) : checks that coll is a array then converts coll to a set
listtobag(coll) : checks that coll is a list then converts coll to a bag
settobag(coll) : checks that coll is a set then converts coll to a bag
arraytobag(coll) : checks that coll is a array then converts coll to a bag
bagtolist(coll) : checks that coll is a bag then converts coll to a list
settolist(coll) : checks that coll is a set then converts coll to a list
arraytolist(coll) : checks that coll is a array then converts coll to a list
bagtoarray(coll) : checks that coll is a bag then converts coll to a array
settoarray(coll) : checks that coll is a set then converts coll to a array
listtoarray(coll) : checks that coll is a set then converts coll to a array

Sort Functions

These functions are used to sort collection of sortable atom of homogeneous types: int, char, float or string.


sort(coll)		: coll must a be a collection of homogeneoussortable atoms;

sorts and returns this collection
rsort(coll) : coll must a be a collection of homogeneoussortable atoms;
reverse sorts and returns this collection
isort(coll, idx) : coll must a be a collection of listor array
of homogeneous sortable atoms;
idx must be of int type;
sorts the collection of collections according to the
#idx elementof the inner collection
risort(coll, idx) : same as previous function, but perform a reverse sort

Collection Miscelleanous Functions


first(coll)		: returns the first element of coll

car(coll) : returns the first element of coll
last(coll) : returns the last element of coll
cdr(coll) : returns all elements of coll but the first
getn(coll, n) : returns at most n elements of coll
count(coll) : returns the count of elements of coll
identical to coll[!], but less efficient
sum(coll) : returns the sum of the numbers of coll
avg(coll) : returns the float average of the numbers coll
distinct(coll) : eliminates duplicates of coll
flatten(coll) : recursive flattening of coll
flatten1(coll) : one level flattening of coll
min(coll) : returns the minimal number of coll
max(coll) : returns the maximal number of coll
forone(coll, f, data) : if f(e, data) for one elemente
of coll, returns true;
otherwise returns false;
forall(coll, f, data) : if f(e, data) for all elemente
of coll, returns true;
otherwiser returns false;

String Function Functions


tolower(str)		: converts (and returns) string str into lowercase

toupper(str) : converts (and returns) string str into uppercase
tocap(str) : converts the first character and each characterfollowing
a _ of str into an uppercase
strlen(str) : returns the length of str;
same as str[!], but less efficient
substring(str, from, len) : returns the sub-string of str
from the #from to the
from+len characters;
same as str[from:from+len] but less efficient

Query Functions


delete_from(class)		: deletes all the instances of a given class

get_from(class) : gets all the instances of a given class

Useful Functions


assert(cond)		: throws an exception is cond is not true

assert_msg(cond, msg) : throws the exception message msg if cond is not true
interval(from, to) : returns a list composed of the numberfrom from to to

Native Methods of the Class object

The native methods of the class object allows us to perform a few action such as getting the oid of an instance getOid(), getting the database of an instance getDatabase() or converts the instance to its string representation toString(). For instance, to apply this last method to the first Person instance: first(select Person).toString().

All the native methods of the class object are instance methods.

oid getOid()		 : returns the oid of the object

string toString() : returns the string representation of the object
database *getDatabase() : returns the database instance ofthe object
void setDatabase(in database *) : changes the database of the object
void store() : stores the object in the database
object *clone() : clones the object; returns the clone
int getCTime() : returns the creation time of the object (seconds from 1/1/1970)
int getMTime() : returns the last modification time of the object
string getStringCTime() : returns the string representation ofthe creation time of the object
string getStringMTime() : returns the string representation ofthe creation time of the object
bool isRemoved() : returns true if the object is removed;false otherwise
bool isModify() : returns true if the object is modified;false otherwise

Native Methods of the Class connection

All the native methods of the class connection are instance methods. an object obtained using the new operator, They can be applied on a database object that can be either the current connection oql$db->getConnection() either an object obtained using the new operator, for instance: new <> connection().

void open()		 : opens a new connection with default host and port

void open(in string host, in string port) : opens a new connectionusing host and port
void close() : closes the connection

Native Methods of the Class database

The following methods are the instance methods of the class database: They can be applied on a database object that can be either oql$db either an object obtained using the new operator, for instance: new <> database(name : "foo").

void open(		in connection *conn,

in int mode) : opens a new database using the connection
conn and the open flag mode mode
void open( in connection *conn,
in int mode,
in string userauth,
in string passwdauth) : opens a new database using the connection conn,
the open flag mode mode and the authentication
userauth/passwdauth
void close() : closes the database
connection *getConnection() : returns the connection tied tothe database
int getOpenMode() : returns the open flag mode of the database
int getVersionNumber() : returns the version number of the database
string getVersion() : returns the string version of the database

void removeObject(in oid) : removes the object whose oid is given

void transactionBegin() : begins a new transaction
void transactionBegin(in string mode) : begins a new transactionin mode mode
void transactionCommit() : commits the current transaction
void transactionAbort() : abort the current transaction

bool isInTransaction() : returns true ifa transaction is in progress;
false otherwiser

Native Methods of the Class EyeDB

All the native methods of the class EyeDB are class methods.


string getConfigValue(in string s)		 : returns thestring value of the configuration variable s

int getVersionNumber() : returns the EYEDB current version number
string getVersion() : returns the EYEDB current stringversion
string getArchitecture() : returns the architecture of the current server
string getDefaultCompiler() : returns the C++ compiler used tocompile the current server

EyeDB manual