Professional Documents
Culture Documents
Cursors
EXEC SQL DECLARE cursorName CURSOR FOR
SELECT . FROM . WHERE . ;
EXEC SQL OPEN cursorName;
while (true) {
EXEC SQL FETCH FROM cursorName INTO :variables;
if (NO_MORE_TUPLES) break;
/* do something with values */
}
EXEC SQL CLOSE cursorName;
Two Approaches to OO
1. Build object-oriented database systems:
ODMG standard: --> Object Query Language.
Products are mainly object storage systems.
Only O2 supports OQL (and is not doing that well).
2. Object-relational systems:
Add OO features to SQL (in SQL3)
Row types and abstract data types.
Various subsets are supported my most relational vendors.
The difference:
How important is a relation to you?
How important is SQL to you?
Example Interface
Interface Movie {
attribute string title;
relationship Set <Star> stars
inverse Star::starredIn;
float lengthInHours raises(noLengthFound);
starNames (out Set <String>);
otherMovies (in Star, out Set<Movie>
raises (noSuchStar));
}
Note: defining signature, not implementation. Overloading allowed.
Type System
Declaring types for objects
Basic types:
Atomic types (e.g., string, integer, )
Enumeration types (Monday, Tuesday, Wednesday.)
Constructors: can be applied without limitations.
Set: (1, 5, 6)
Bag: (1, 1, 5, 6, 6 )
List: (1, 5, 6, 1, 6 )
Collection types
Array: Integer[17]
Struct: (name: string, address: string)
struct( name: John, childrenAges: bag (1,1,2,2))
Path Expressions
Path expressions are needed in order to access components
of objects.
Attributes:
a.p is the value of the attribute a of p.
Relationships:
a.p is the object or collection of objects related to a by p.
Methods:
a.p is the result of applying p to a (perhaps with a parameter).
Also possible to have longer expressions:
a.father.wife.child.father.wife.
Select-From-Where in OQL
(simple) Example:
SELECT s.name
FROM Movies m, m.stars s
WHERE m.title = Sleepless in Seattle
Person
References
We can define attributes of a row type to reference objects of other
row types:
CREATE ROW TYPE Company(
name char(30),
address addressType,
president REF(PersonType)
);
Following references:
SELECT president->name
FROM Company
WHERE president->address..city=Seattle
Address ADT
CREATE TYPE AddressADT (
street CHAR(50),
city
CHAR(20),
EQUALS addrEq,
LESS THAN addrLT
FUNCTION fullAddr (a: AddressADT) RETURNS CHAR(100);
:z CHAR(10);
BEGIN
:z = findZip(:a.street, :a.city);
RETURN (.)
END;
DECLARE EXTERNAL findZip
CHAR(50) CHAR(20) RETURNS CHAR(10)
LANGUAGE C; );
Encapsulation is obtained by making methods public/private