next up previous contents
Next: Type Information Expressions Up: Language Syntax Previous: Function Definition Expressions   Contents

Subsections


Conversion Expressions

The conversion unary operators string, int, char, float, oid and ident allows us to make the following conversions:
Operator From To Returned Atom
string any type string the string representation of the operand
int int int the int operand
  char int the operand casted to an int
  float int the operand casted to an int
  string int the operand converted to an int
char char char the char operand
  int char the operand casted to a char
  float textttchar the operand casted to a char
  string char the operand converted to a char
float float float the float operand
  char float the operand casted to a float
  int float the operand casted to a float
  string float the operand converted to a float
oid oid oid the oid operand
  string oid the string operand converted to an oid
ident ident ident the ident operand
  string ident the string operand converted to an ident
These operators are used to perform an explicit conversion such as convert the string "123" to the integer 123, or to perform an explicit cast for numbers such as casting the integer 10 to the float 10.0. These operators evaluate first their operand before performing the conversion. If the operand type is valid, no error is raised even if its format is not valid, for instance: int "alpha" returns 0, while oid "aoaoai" returns NULL. Note that because of the precedence of these operators, parenthesis are necessary to make a conversion of a non-primary operand. For instance, string 1+2 is not valid: you should use string (1+2).

string operator

The string operator evaluates its operand and returns its string representation.
General Information
Operator string
Syntax string expr
Type unary
Operand Type any type
Result Type string
Function returns the string representation of any atom

Expression Examples
string 123.3 "1203.300000"
string 'a' "a"
string first(select Person) "71211.13.1486847:oid"
string &alpha "::alpha"
string list(1, 2, 3+2) "list(1, 2, 5)"
string (list("hello", 30) + list(10)) "list("hello", 30, 10)"
string (1+3) "4"
string 1+3 raises an error

int operator

The int operator evaluates its operand and converts or casts it to an integer.
If the operand is the string, it converts it using the atoi C function. If the string is not a valid integer, it returns a 0.
If the operand is a char or float, it casts it to an integer.
If the operand is an integer, it returns it.
General Information
Operator int
Syntax int expr
Type unary
Operand Type int, char, float or string
Result Type int
Function returns the integer conversion or cast of the operand

Expression Examples
int 123.3 123
int 12 12
int 'a' 97
int "123" 123
int ("123" + "12") 12312
int alpha the value of alpha converted or casted to an integer
int list(1, 2, 3) raises an error

char operator

The char operator evaluates its operand and converts or casts it to a char.
If the operand is the string of length one, it returns the character of this string. If the string has several characters, it returns a '\000.
If the operand is a integer or float, it casts it to a character.
If the operand is a character integer, it returns it.
General Information
Operator char
Syntax char expr
Type unary
Operand Type int, char, float or string
Result Type char
Function returns the character conversion or cast of the operand

Expression Examples
char 123.3 {
char 'a' 'a'
char alpha the value of alpha converted or casted to a character
char "a" 'a'
char "hello" '^@'
char list(1, 2, 3) raises an error

float operator

The float operator evaluates its operand and converts or casts it to a float.
If the operand is the string, it converts it using the atof C function. If the string is not a valid float, it returns a 0.0.
If the operand is a integer or float, it casts it to a float.
If the operand is a float, it returns it.
General Information
Operator float
Syntax float expr
Type unary
Operand Type int, char, float or string
Result Type float
Function returns the float conversion or cast of the operand

Expression Examples
float 123.0 123.0
float 123.3 123.3
float 'a' 97.000
float "123.0000000" 123.0
float ("123." + "12") 123.12
float "hello" 0.0
float alpha the value of alpha converted or casted to a float
float list(1, 2, 3) raises an error

oid operator

The oid operator evaluates its string operand and returns the corresponding oid. If the string does not denote a valid oid, the NULL oid is returned.
If the operand is an oid, it returns it.
General Information
Operator oid
Syntax oid expr
Type unary
Operand Type oid or string
Result Type oid
Function returns the oid denoted by the string operand

Expression Examples
oid "234.34.33:oid" 234.34.33:oid
oid 234.34.33:oid 234.34.33:oid
oid first(select Person) returns the first person oid
oid 'a' raises an error

ident operator

The ident operator evaluates its string operand and returns the corresponding identifier. If the operand is an identifier, it returns it.
General Information
Operator ident
Syntax ident expr
Type unary
Operand Type ident or string
Result Type string
Function returns the identifier denoted by the string operand

Expression Examples
ident "alpha" alpha
ident "alpha#1x" alpha#1x
ident "alpha" := 123 123, alpha has been assigned to 123
valof &(ident "alpha") 123
ident 'a' raises an error


next up previous contents
Next: Type Information Expressions Up: Language Syntax Previous: Function Definition Expressions   Contents
EyeDB manual