Object-Orientation in Query Languages By: Toan Nguyen Class: CS 157A.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Why Object-Oriented DBMS? Abstract data types Interface with host programming language (the impedance mismatch). Object identity: (peter, 40, {(john, 15,
SQL Introduction Standard language for querying and manipulating data Structured Query Language Many standards out there: SQL92, SQL2, SQL3. Vendors support.
Programming Languages and Paradigms The C Programming Language.
SQL CSET 3300.
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
Subqueries Example Find the name of the producer of ‘Star Wars’.
True or false A variable of type char can hold the value 301. ( F )
Fall 2001Arthur Keller – CS 18016–1 Schedule Nov. 20 (T) More OQL. u Read Sections Assignment 7 due (late ones by ). Nov. 22 (TH) Thanksgiving.
SQL. 1.SQL is a high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
Nov 24, 2003Murali Mani SQL B term 2004: lecture 12.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
SQL SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation details that would be necessary in.
XQuery – The W3C XML Query Language Jonathan Robie, Software AG Don Chamberlin, IBM Research Daniela Florescu, INRIA.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
© 2007 by Prentice Hall 1 Chapter 15 (Web): Object-Oriented Database Development Modern Database Management 8 th Edition Jeffrey A. Hoffer, Mary B. Prescott,
Joins Natural join is obtained by: R NATURAL JOIN S; Example SELECT * FROM MovieStar NATURAL JOIN MovieExec; Theta join is obtained by: R JOIN S ON Example.
Programs with SQL Host language + Embedded SQL Preprocessor Host Language + function calls Host language compiler Host language program Preprocessor Host.
Other Data Models. Text New edition (DBS the complete book): Chapter 4 Old edition (First course in DBS): –Section 2.1 –Section –Section 2.4.1,
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Object and Object- Relational Databases.
SQL By: Toan Nguyen. Download Download the software at During the installation –Skip sign up for fast installation.
1 Announcements Research Paper due Monday November 22.
Databases Illuminated Chapter 7 The Object-Oriented Model.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Object and object-relational databases 1. Object databases vs. Object-relational databases Object databases Stores complex objects – Data + functions.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
CIS 671OODBs1 Lecture 3 Object database standards, languages and design.
Object Query Language (OQL) and Language Binding
Chapter 3 Single-Table Queries
ORDBS1 Object Relational Database Systems: 1. Introduction 2. Objects in SQL3 3. Comparison of ODL/OQL and SQL3 Approaches CIS 671.
Why Object-Oriented DBMS? Abstract data types (relational data model is too simple). Interface with host programming language Managing large number of.
1 Object-Relational Databases User-Defined Types Nested Tables.
ADVANCED DATABASE SYSTEMS DR. FATEMEH AHMADI- ABKENARI SEPTEMBER Object Databases.
SQL: Data Manipulation Presented by Mary Choi For CS157B Dr. Sin Min Lee.
8 October, 2001DBIS4 - RLC108 Object Query Language The need for ad hoc querying What SQL does What OQL must do OQL syntax and examples.
Database Management COP4540, SCS, FIU Database Modeling A Introduction to object definition language (ODL)
Chapter 21 C OQL Copyright © 2004 Pearson Education, Inc.
1 Advanced Databases (CM036) – Lecture # 12: The ODMG Standard for Object Databases Object Query Language (OQL) & Language Binding Advanced Database Technologies.
Object Definition Language
OOPSLA LAB. 1 Chapter 4 Object Query Languages Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University.
Databases Illuminated
CSE 6331 © Leonidas Fegaras OODB1 Object-Oriented Databases and the ODMG Standard.
Database Design Why do we need it? – Agree on structure of the database before deciding on a particular implementation. Consider issues such as: –What.
Winter 2006Keller Cushing Ullman17–1 Subqueries Used mainly in FROM clauses and with quantifiers EXISTS and FORALL. Example: Subquery in FROM Find the.
Object Relational Features
1 Algebra of Queries Classical Relational Algebra It is a collection of operations on relations. Each operation takes one or two relations as its operand(s)
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
© D. Wong Security and User Authorization in SQL 8.7 pp. 410  Authorization ID = user name  Special authorization ID: PUBLIC  Privileges for:
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
Himanshu GuptaCSE 532-SQL-1 SQL. Himanshu GuptaCSE 532-SQL-2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database.
1 Chapter 8 Object-oriented Query Languages. 2 Object-oriented query language OQL (Object Query Language) –ODMG (Object Database Management Group) –ODMG-93.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Subqueries CIS 4301 Lecture Notes Lecture /23/2006.
Why Object-Oriented DBMS?
Object-Oriented Databases and the ODMG Standard
Slides are reused by the approval of Jeffrey Ullman’s
Introduction to Structured Query Language (SQL)
Chapter 12 Outline Overview of Object Database Concepts
SQL Structured Query Language 11/9/2018 Introduction to Databases.
11. שפות ODL ו-OQL ותכנון מכוון עצמים
Lecture 12: SQL Friday, October 20, 2000.
Chapter 15: Object-Oriented Database Development
Shelly Cashman: Microsoft Access 2016
Instructor: Zhe He Department of Computer Science
Presentation transcript:

Object-Orientation in Query Languages By: Toan Nguyen Class: CS 157A

OQL OQL, the Object Query Language, gives us an SQL like notation for expressing queries. OQL, the Object Query Language, gives us an SQL like notation for expressing queries. It is intended that OQL will be used as an extension to some object-oriented host languages, such as C++, Smalltalk, or Java. It is intended that OQL will be used as an extension to some object-oriented host languages, such as C++, Smalltalk, or Java.

Path Expressions We can access component of object and structures using a dot notation that is similar to the dot used in C and also related to the dot used in SQL. The general rule is as follows. We can access component of object and structures using a dot notation that is similar to the dot used in C and also related to the dot used in SQL. The general rule is as follows. 1. If p is an attribute, then a.p is the value of that attribute in object a. 2. If p is a relationship, then a.p is the object or collection of object related to a by relationship b. 3. If p is a method, then a.p(…) is the result of applying p to a.

Select-From-Where Expressions in OQL OQL permits us to write expressions using a select-from-where syntax similar to SQL’s OQL permits us to write expressions using a select-from-where syntax similar to SQL’s 1) The keyword SELECT followed by a list of expressions. 2) The keyword FROM followed by a list of one or more variable declarations. 3) The keyword WHERE and Boolean-value expressions

Modifying the Result To make the result a set, use the keyword DISTINCT after SELECT, as in SQL. To make the result a set, use the keyword DISTINCT after SELECT, as in SQL. To make the result a list, add ORDER BY clause at the end of the query again as in SQL. To make the result a list, add ORDER BY clause at the end of the query again as in SQL.

Example SELECT m FROM Movies m WHERE m.ownedBy.name = “Disney” ORDER BY m.length, m.title This query finding the set of Disney movies, and let the result be a list of movies, order by length. If there are ties, let the movies of equal length be order alphabetically.

Complex Output Types The elements in the SELECT clause need not be simple variables. They can be any expression, including expressions built using type constructors. For example, we can apply the Struct type constructor to several expressions and get a select-from- where query that produces a set or bag of structures. The elements in the SELECT clause need not be simple variables. They can be any expression, including expressions built using type constructors. For example, we can apply the Struct type constructor to several expressions and get a select-from- where query that produces a set or bag of structures.

Example SELECT DISTINCT Struct(start1: s1, start2: s2) FROM Star s1, Star s2 WHERE s1.address = s2.address AND s1.name<s2.name We want the set of pairs of stars living at the same address.

Quantifier Expressions Test whether all members of a collection satisfy some condition, and we can test whether at least one member of a collection satisfies a condition. Test whether all members of a collection satisfy some condition, and we can test whether at least one member of a collection satisfies a condition. FOR ALL x IN S: C (x) FOR ALL x IN S: C (x) The result of this expression is TRUE if every x in S satisfies C(x) EXISTS x IN S: C (x) EXISTS x IN S: C (x) The result of the expression is TRUE if there is at least one x in such that C(x) is TRUE and it has value FALSE otherwise. The result of the expression is TRUE if there is at least one x in such that C(x) is TRUE and it has value FALSE otherwise.

Aggregation Expressions OQL uses the same five aggregation operators that SQL does: AVG, COUNT, SUM, MIN, and MAX. OQL uses the same five aggregation operators that SQL does: AVG, COUNT, SUM, MIN, and MAX. Example: Example: AVG(SELECT m.length FROM Movies m) AVG(SELECT m.length FROM Movies m)

Union, Intersection, and Difference We may apply the union, intersection, and difference operators to two objects of set or bag type. These three operators are represented, as in SQL, by the keywords UNION, INTERSECT, and EXCEPT, respectively. EXCEPT, respectively. (SELECT DISTINCT m (SELECT DISTINCT m FROM Movies m, m.stars s FROM Movies m, m.stars s WHERE s.name = “Harrison Ford”) WHERE s.name = “Harrison Ford”) EXCEPT EXCEPT (SELECT DISTINCT m (SELECT DISTINCT m FROM Movies m FROM Movies m WHERE m.ownedBy.name = “Disney” WHERE m.ownedBy.name = “Disney”

Assigning Values to Host-Language Variables The expressions of OQL that we have learned, such as select-from-where, produce object as values. It is possible to assign to any host-language variable of the proper type The expressions of OQL that we have learned, such as select-from-where, produce object as values. It is possible to assign to any host-language variable of the proper type Example: Example: oldMovies = SELECT DISTINCT m oldMovies = SELECT DISTINCT m FROM Movies m FROM Movies m WHERE m.year<1920; WHERE m.year<1920; The following query produces the set of all those movies made before If oldMovies is a host-language variable of the same type, then the values of oldMovies will become the set of these Movie object.

Obtaining Each Member of a Collection To obtaining each member of a set or bag we need to turn our set or bag into a list. We do so with a select-from-where expressions that uses ORDER BY.

Example 1) movieList = SELECT m FROM Movies m FROM Movies m ORDER BY m.title, m.year ORDER BY m.title, m.year 2) numberOfMovies = COUNT(Movies); 3) for(i=0; i<numberOfMovies; i++){ 4) movie = movieList[i]; 5) count<<movie.title<<“ “<<movie.year<<“ “ 6) <<movie.length<<“\n”; Line 1 sort the movie class. Line 2 computes the number of movies, using the OQL operator COUNT. Line 3 and 4 use for loop in which integer variable i ranges over each position of the list. After that the i element of the list assigned to variable movie. Line 5 and 6 are for print.

Constants in OQL Basic values a) Atomic values: integers, floats, characters, a) Atomic values: integers, floats, characters, strings, and booleans. strings, and booleans. b) Enumerations: The values in an enumeration are b) Enumerations: The values in an enumeration are actually declared in ODL. Any one of these values actually declared in ODL. Any one of these values may be used as a constant. may be used as a constant. Complex values built using the following type constructors: a) Set (…). a) Set (…). b) Bag (…). b) Bag (…). c) List (…). c) List (…). d) Array (…). d) Array (…). e) Struct (…). e) Struct (…).

Defining Types in SQL A simple form of UDT definition is: A simple form of UDT definition is: 1. The keywords CREATE TYPE 2. The name for the type 3. The keyword AS 4. A parenthesized, comma-separated list of attributes and their types. 5. A comma-separated list of methods, including their argument type(s), and return type

Example CREATE TYPE AddressType AS { street CHAR(50), street CHAR(50), city CHAR(20) city CHAR(20)}; CREATE TYPE StarType AS { name CHAR (30), name CHAR (30), address AddressType address AddressType};

Generator and Mutator Functions In order to create data that conforms to a UDT, or to change components of object with UDT, we can use two kinds of methods. In order to create data that conforms to a UDT, or to change components of object with UDT, we can use two kinds of methods. 1. A generator method. 1. A generator method. This method has the name of the type and no argument. It also has the unusual property that it make be invoked without being applied to any object Mutator method. For each attribute x of UDT T, there is a mutator method x(v). When applied to an object of type T, it changes the x attribute of that object to have value v.

References A First Course In Database Systems A First Course In Database Systems Jefferey D. Ullman and Jennifer Widom Jefferey D. Ullman and Jennifer Widom