Programs with SQL Host language + Embedded SQL Preprocessor Host Language + function calls Host language compiler Host language program Preprocessor Host.

Slides:



Advertisements
Similar presentations
Why Object-Oriented DBMS? Abstract data types Interface with host programming language (the impedance mismatch). Object identity: (peter, 40, {(john, 15,
Advertisements

SQL Introduction Standard language for querying and manipulating data Structured Query Language Many standards out there: SQL92, SQL2, SQL3. Vendors support.
Object Databases Baochuan Lu. outline Concepts for Object Databases Object Database Standards, Languages, and Design Object-Relational and Extended-Relational.
CSC343 – Introduction to databases – A. Vaisman1 Database Application Development.
ODMG Standard: Object Model1 OBJECT-ORIENTED DATABASE SYSTEMS ODMG Standard: Object Model Susan D. Urban and Suzanne W. Dietrich Department of Computer.
1 Lecture 12: SQL Friday, October 26, Outline Simple Queries in SQL (5.1) Queries with more than one relation (5.2) Subqueries (5.3) Duplicates.
Fall 2001Arthur Keller – CS 18011–1 Schedule Oct. 30 (T) Embedded SQL. u Read Section 8.1. u Assignment 5 due. Not accepted late. u Project Part 4 due.
Lecture #2 October 5 th, 2000 Conceptual Modeling Administration: –HW1 available –Details on projects –Exam date –XML comment.
Winter 2002Arthur Keller – CS 18015–1 Schedule Today: Feb. 28 (TH) u Datalog and SQL Recursion, ODL. u Read Sections , Project Part 6.
Object-Orientation in Query Languages By: Toan Nguyen Class: CS 157A.
Fall 2001Arthur Keller – CS 18015–1 Schedule Nov. 15 (TH) Object Queries (OQL). u Read Sections 9.1. Project Part 6 due on Sunday night. Nov. 20 (T) More.
End of SQL: Triggers, Impedance Mismatch and Transactions February 6 th, 2004.
Remaining Topics in SQL to be covered… NULL values in SQL Outer joins in SQL Constraints and Triggers in SQL Embedded SQL.
Object-Oriented Standards OMG OMDG. Overview Object Management Group (OMG) International non profit-making consortium founded in 1989 to address object.
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,
Embedded SQL Direct SQL is rarely used: usually, SQL is embedded in some application code. We need some method to reference SQL statements. But: there.
Object Oriented Databases - Overview
Remaining Topics in SQL to be covered… NULL values in SQL Outer joins in SQL Constraints and Triggers in SQL Embedded SQL.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Object and Object- Relational Databases.
1 Announcements Research Paper due Monday November 22.
Databases Illuminated Chapter 7 The Object-Oriented Model.
EER vs. UML Terminology EER Diagram Entity Type Entity Attribute
Database Design April 3, Projects, More Details Goal: build a DB application. (almost) anything goes. Groups of 3-4. End of week 2: groups formed.
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
DBMS Lecture 9  Object Database Management Group –12 Rules for an OODBMS –Components of the ODMG standard  OODBMS Object Model Schema  OO Data Model.
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.
Chapter 21 A Object Data Model - Intro Copyright © 2004 Pearson Education, Inc.
ADVANCED DATABASE SYSTEMS DR. FATEMEH AHMADI- ABKENARI SEPTEMBER Object Databases.
Database Management COP4540, SCS, FIU Database Modeling A Introduction to object definition language (ODL)
Chapter 21 C OQL Copyright © 2004 Pearson Education, Inc.
Chapter 21 Object Database Standards, Languages, and Design Copyright © 2004 Pearson Education, Inc.
Object Definition Language
1 Advanced Databases (CM036) – Lecture # 12: The ODMG Standard for Object Databases Object Query Language (OQL) & Language Binding Advanced Database Technologies.
SQL in a Programming Environment CIS 4301 Lecture Notes Lecture /11/2006.
Object Definition Language
OOPSLA LAB. 1 Chapter 4 Object Query Languages Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University.
1 SQL Constraints and Programming. 2 Agenda Constraints in SQL Systems aspects of SQL.
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.
Object Relational Features
11-1 CHAPTER 11 Concepts for Object-Oriented Databases.
Different Constraint Types Type Where Declared When activated Guaranteed to hold? Attribute with attribute on insertion not if CHECK or update subquery.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
© D. Wong Security and User Authorization in SQL 8.7 pp. 410  Authorization ID = user name  Special authorization ID: PUBLIC  Privileges for:
AND OBJECT-ORIENTED DATABASES OBJECT-RELATIONAL DATABASES.
The ODMG Standard for Object Databases
Constraining Attribute Values Constrain invalid values –NOT NULL –gender CHAR(1) CHECK (gender IN (‘F’, ‘M’)) –MovieName CHAR(30) CHECK (MovieName IN (SELECT.
1 Lecture 8: SQL Programming and Transactions Friday, January 24, 2003.
1 Advanced Databases – Lecture # 12: The ODMG Standard for Object Databases Advanced Databases The ODMG Standard for Object Databases.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database.
1 ODMG: ODL and OQL This lecture is a short version of: Lecture 11 (on ODL) & Lecture 12 (on OQL) M. Akhtar Ali School of Informatics.
1 Chapter 8 Object-oriented Query Languages. 2 Object-oriented query language OQL (Object Query Language) –ODMG (Object Database Management Group) –ODMG-93.
OOPSLA Lab1 Chapter 7 Java Binding Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University.
Why Object-Oriented DBMS?
Object-Oriented Databases and the ODMG Standard
Database Design Oct. 3, 2001.
Database Design Why do we need it? Consider issues such as:
OBJECTS & DATABASES Arnaud Sahuguet – CIS-550.
Chapter 12 Outline Overview of Object Database Concepts
Remaining Topics in SQL to be covered…
CPSC-310 Database Systems
11. שפות ODL ו-OQL ותכנון מכוון עצמים
SQL Introduction Standard language for querying and manipulating data
Object Definition Language
Lecture 17: Systems Aspects of SQL
Lecture 05: SQL Systems Aspects
Embedded SQL Chapter 8.
Presentation transcript:

Programs with SQL Host language + Embedded SQL Preprocessor Host Language + function calls Host language compiler Host language program Preprocessor Host language compiler

The Impedance Mismatch Problem The host language manipulates variables, values, pointers SQL manipulates relations. There is no construct in the host language for manipulating relations. Why not use only one language? Forgetting SQL: definitely not a good idea! SQL cannot do everything that the host language can do.

Using Shared Variables Void simpleInsert() { EXEC SQL BEGIN DECLARE SECTION; char productName[20], company[30]; char SQLSTATE[6]; EXEC SQL END DECLARE SECTION; /* get values for productName and company somehow */ EXEC SQL INSERT INTO Product(name, company) VALUES (:productName, :company); }

Single-Row Select Statements Void getPrice() { EXEC SQL BEGIN DECLARE SECTION; char productName[20], company[30]; integer price; char SQLSTATE[6]; EXEC SQL END DECLARE SECTION; /* read value of product name */ EXEC SQL SELECT price INTO :price FROM Product WHERE Product.name = :productName; /* print out value of price */ }

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;

Motivations for OODB’s (golden rules of OODB’s) Complex objects (sets, lists, bags, arrays, tuples, constructors) (IM) Object identity: (peter, 40, {(john, 15, {})}) (susan, 41, {(john, 15, {})}) Same son? Maybe, maybe not. Encapsulation: (modularity, protection, less distinction between program and data). (IM) Types and classes. Hierarchies (of classes and types) Overloading and late binding of method names. Computational completeness. (IM) Type extensibility. (IM)

Object Definition Language Is part of ODMG, which also gives us OQL. Resembles C++ (and Smalltalk). Main concepts: –objects, literals –state of objects: values of its properties: attributes, relationships, methods –behavior: defined by methods –types –classes, extents, keys.

ODL Class Declarations Interface { attributes: ; relationships ; methods } Method example: float gpa(in: Student) raises (noGrades) Arbitrary function can compute the value of gpa, based on a student object given as input.

Types in ODL Basic types: Atomic types (e.g., string, integer, …) Interface types (e.g., Person, Product, Company) Constructors: Set: (1, 5, 6) Bag: (1, 1, 5, 6, 6 ) List: (1, 5, 6, 1, 6 ) Array: Integer[17] Struct: {string street, string city, integer zipcode}

ODL Declarations Interface Product { attribute string name; attribute float price; attribute enum Categories {electronics, communications, sports …} category } Interface Company { attribute string name; attribute float stockprice; } Interface Person { attribute integer ssn; attribute string name; attribute Struct Address {string street, string city} address; }

ODL Declarations Interface Product { attribute string name; attribute float price; attribute enum Categories {electronics, communications, sports …} category; relationship madeBy; } Interface Person { attribute integer ssn; attribute string name; attribute Struct Address {string street, string city} address; relationship set buys; relationship set worksFor;}

ODL Declarations Interface Company { (key name); attribute string name; attribute float stockprice; relationship set makes inverse Product::madeBy; relationship set employs inverse Person::worksFor; }

Example Method Interface Movie { (extent Movies) attribute string title; relationship Set stars inverse Star::starredIn; float lengthInHours raises(noLengthFound); starNames (out Set ); otherMovies (in Star, out Set ) raises (noSuchStar); } Note: defining signature, not implementation. Overloading allowed.

OQL: Object Query Language SELECT can construct new objects, arbitrary structures FROM tuple variables can range over any collection; may have subqueries. WHERE pretty much the same as in SQL

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” Note: this looks a lot more procedural than SQL.

Complications in the FROM Clause SELECT a.phoneNumber FROM Movies m, (SELECT m.address FROM m.stars WHERE m.city=“Los Angeles”) AS a WHERE m.title = “Sleepless in Seattle” The FROM clause can contain arbitrary subqueries that return collections.

Complex Output Types The SELECT clause can create complex structures: SELECT Struct: (address: a, phoneNumber: a.phoneNumber) FROM Movies m, (SELECT m.address FROM m.stars WHERE m.city=“Los Angeles”) AS a WHERE m.title = “Sleepless in Seattle”

Other Features of OQL Ordering of the results ORDER BY m.title, m.year. Subqueries wherever a collection is appropriate. Quantifier expressions: FOR ALL x IN S : C(x) EXISTS x IN S:C(x) Aggregation, grouping and HAVING clauses. Set operators: UNION, INTERSECT, EXCEPT (different if operating on bags or sets. Remove duplicates: SELECT DISTINCT.

Interface with Host Language OQL is much more tightly integrated with the host language. OQL produces objects (of various types). One can simply assign the objects as values to variables with the appropriate types. No need for special interface. ELEMENT: turns a bag of one element into the single element: var1 = ELEMENT (SELECT m FROM Movies m WHERE title=“sleepless in Seattle”);

Handling Sets or Bags First: turn them into lists (using ORDER BY). Then: use host language operations to go through them. Example: movieList = select m FROM Movies m WHERE m.year > 1990 ORDER BY m.title, m.year; numberOfMovies = COUNT (movieList); for (I=0; I < numberOfMovies; I++) { movie = movieList[I]; do something with it. }