2002.10.31- slide 1is 257 - fall 2002 fourth generation languages and or extensions to sql...
Post on 19-Dec-2015
214 views
TRANSCRIPT
IS 257 - Fall 2002 2002.10.31- SLIDE 1
Fourth Generation Languages and OR extensions to SQL
University of California, Berkeley
School of Information Management and Systems
SIMS 257: Database Management
IS 257 - Fall 2002 2002.10.31- SLIDE 2
Lecture Outline
• Review– PHP (a bit more is working now)…
• Fourth Generation Languages
• Object-Relational Extensions to SQL
IS 257 - Fall 2002 2002.10.31- SLIDE 3
PHP
• PHP is an Open Source Software project with many programmers working on the code.– Commonly paired with MySQL, another OSS
project– Free– Both Windows and Unix support
• Estimated that more than 250,000 web sites use PHP as an Apache Module.
IS 257 - Fall 2002 2002.10.31- SLIDE 4
PHP Syntax
• Similar to ASP
• Includes most programming structures (Loops, functions, Arrays, etc.)
• Loads HTML form variables so that they are addressable by name
<HTML><BODY>
<?php
$myvar = “Hello World”;
echo $myvar ;
?>
</BODY></HTML>
IS 257 - Fall 2002 2002.10.31- SLIDE 5
Combined with MySQL
• DBMS interface appears as a set of functions:
<HTML><BODY><?php$db = mysql_connect(“localhost”, “root”);mysql_select_db(“mydb”,$db);$result = mysql_query(“SELECT * FROM employees”, $db);printf(“First Name: %s <br>\n”, mysql_result($result, 0 “first”);printf(“Last Name: %s <br>\n”, mysql_result($result, 0 “last”);?></BODY></HTML>
IS 257 - Fall 2002 2002.10.31- SLIDE 6
Examples with Diveshop
IS 257 - Fall 2002 2002.10.31- SLIDE 7
Fourth Generation Languages
• 1st Generation -- Machine Language
• 2nd Generation -- Assembly Languages
• 3rd Generation -- High-Level Languages
• 4th Generation -- Non-Procedural Languages
• 5th Generation -- ?? Knowledge-based ?? Natural Language ??
• Where do Object-Oriented Languages fit??
IS 257 - Fall 2002 2002.10.31- SLIDE 8
Chauffeurs
• In the early days of the US car industry, production volumes were growing fast, and a well-known sociologist was asked to predict the total number of automobiles that would ever be manufactured. After a great deal of study, the sociologist reported that no more than 2 million would be manufactured in the life cycle of the car. If the car lasted ten years on average, the maximum annual production would never exceed 200,000. This conclusion was based on the much-researched figure that no more than 2 million people would be willing to serve as chauffeurs.
From James Martin - Fourth Generation Languages
IS 257 - Fall 2002 2002.10.31- SLIDE 9
Fourth Generation Languages
• In the database environment these are used for creation of database applications
• To speed up the application building process• To make applications easy and quick to change• To minimize debugging problems• To generate bug-free code from high-level
expressions of requirement• To make languages user-friendly so that “end-
users” can solve their own problems and put computers to work.
IS 257 - Fall 2002 2002.10.31- SLIDE 10
Basic Principles of 4GLs
• The Principle of Minimum Work
• The Principle of Minimum Skill
• The Principle of avoiding alien syntax and mnemonics
• The Principle of Minimum Time
• The Principle of Minimum errors
• The Principle of Minumum Maintenance
• The Principle of Maximum Results
From James Martin - Fourth Generation Languages
IS 257 - Fall 2002 2002.10.31- SLIDE 11
Properties of 4GLs
• User Friendly
• A nonprofessional programmer can obtain results with it
• It employs the database management system directly
• Programs for most applications can be created with 10 times fewer instructions than in a Third Generation Language
IS 257 - Fall 2002 2002.10.31- SLIDE 12
More Properties of 4GLs
• Non procedural code is used wherever possible
• It make intelligent default assumptions about what the user wants wherever possible
• It is designed for online operation
• It enforces or encourages structured code
• It makes it easy to understand and maintain another person’s code
IS 257 - Fall 2002 2002.10.31- SLIDE 13
More Properties of 4GLs
• Non-DP users can learn a subset of the language in a short course
• It is designed for easy debugging
• Prototypes can be created and modified quickly
• Results can be obtained in an order of magnitude less time than with a 3GL for most applications
IS 257 - Fall 2002 2002.10.31- SLIDE 14
Selection Criteria for 4GLs
• Is it intended for routine computing of ad hoc decision making
• Is it intended for end users or DP professionals? (many 4GLs are appropriate for both)
• Does it require the skills of a programmer, or can an analyst who does not program in a 3GL use it.
IS 257 - Fall 2002 2002.10.31- SLIDE 15
Selection Criteria for 4GLs
• Which of the following features does it provide?– Simple queries– Simple queries and updates– Complex queries– Complex queries and updates– The ability to create a database quickly– Intelligent database operations, where the change of
one value in the database causes other operations to occur automatically, such as validity checks, cross references, and the updating of related values.
IS 257 - Fall 2002 2002.10.31- SLIDE 16
Selection Criteria for 4GLs
• Which of the following features does it provide?(cont)– Generation of data-entry screens for key-entry
operators (with validity checks)– Generation of data-update screens for key-entry
operators (with validity checks)– A procedural language giving full programming
capability– Graphics techniques for application design– Spreadsheet manipulation– Multidimensional matrix manipulation– Report generation– Graphics generation
IS 257 - Fall 2002 2002.10.31- SLIDE 17
Selection Criteria for 4GLs
• Which of the following features does it provide?(cont)– Graphics manipulation– Decision support for what-if questions– Mathematical analysis tools– Financial analysis tools– Other decision-support tools– Text manipulation– Electronic Mailbox
• Is it on-line or off-line?• Does it run on mainframes, minicomputers or personal
computers?• Can it access mainframe or remote databases• Is it genuinely easy to use• Can results be obtained with it very quickly?
IS 257 - Fall 2002 2002.10.31- SLIDE 18
Components of a 4GL
Application Parameters
Testingtools/debugger
InterpreterOptimizingcompiler
RulesSpecification
DataSpecification
ReportSpecification
ScreenSpecification
Proceduralfacility
Feedback
for building routine applications…
IS 257 - Fall 2002 2002.10.31- SLIDE 19
5GLs -- Natural Language
• Possibilities
• Problems
IS 257 - Fall 2002 2002.10.31- SLIDE 20
Natural Language
• Advantages of using NL– It encourages untrained users to start– It encourages upper-management use of
computers– It reduces the time taken learning complex
syntax – It lessens the frustration, bewilderment and
anger caused by BAD COMMAND responses– It is likely to extend greatly the usage of
computers James Martin, Fourth Generation Languages, 1985
IS 257 - Fall 2002 2002.10.31- SLIDE 21
Natural Language
• It lacks precision• It is not good for
expressing precise and complex logic
• It is not good for expressing neat structures
• It encourages semantic overshoot
• It should be combined with other dialogue contructs that aid in the representation of precise logic and structures
James Martin, Fourth Generation Languages, 1985
Disadvantages of using NL Appropriate response to the disadvantage
IS 257 - Fall 2002 2002.10.31- SLIDE 22
Natural Language
• It takes substantial time to key in sentences
• Ambiguities are possible
• Substantial processing is needed
• Sentences and words can be abbreviated
• Speech input as well as typed input will be used
• The computer should detect and resolve ambiguities
• The processing should be on PC workstations. Processing is dropping rapidly in cost.
James Martin, Fourth Generation Languages, 1985
Disadvantages of using NL Appropriate response to the disadvantage
IS 257 - Fall 2002 2002.10.31- SLIDE 23
Assumptions and Issues
• Why 4GLs?– Are they still appropriate?– Are they still useful?
• Is Cold Fusion a 4GL?
• What about PHP?
• Who needs them?
IS 257 - Fall 2002 2002.10.31- SLIDE 24
Object Relational Databases
• Background
• Object Definitions– inheritance
• User-defined datatypes
• User-defined functions
IS 257 - Fall 2002 2002.10.31- SLIDE 25
Object Relational Databases
• Began with UniSQL/X unified object-oriented and relational system
• Some systems (like OpenODB from HP) were Object systems built on top of Relational databases.
• Miro/Montage/Illustra built on Postgres.
• Informix Buys Illustra. (DataBlades)
• Oracle Hires away Informix Programmers. (Cartridges)
IS 257 - Fall 2002 2002.10.31- SLIDE 26
Object Relational Data Model
• Class, instance, attribute, method, and integrity constraints
• OID per instance• Encapsulation• Multiple inheritance hierarchy of classes• Class references via OID object
references• Set-Valued attributes• Abstract Data Types
IS 257 - Fall 2002 2002.10.31- SLIDE 27
Object Relational Extended SQL (Illustra)
• CREATE TABLE tablename {OF TYPE Typename}|{OF NEW TYPE typename} (attr1 type1, attr2 type2,…,attrn typen) {UNDER parent_table_name};
• CREATE TYPE typename (attribute_name type_desc, attribute2 type2, …, attrn typen);
• CREATE FUNCTION functionname (type_name, type_name) RETURNS type_name AS sql_statement
IS 257 - Fall 2002 2002.10.31- SLIDE 28
Object-Relational SQL in ORACLE
• CREATE (OR REPLACE) TYPE typename AS OBJECT (attr_name, attr_type, …);
• CREATE TABLE OF typename;
IS 257 - Fall 2002 2002.10.31- SLIDE 29
Example
• CREATE TYPE ANIMAL_TY AS OBJECT (Breed VARCHAR2(25), Name VARCHAR2(25), Birthdate DATE);
• Creates a new type
• CREATE TABLE Animal of Animal_ty;
• Creates “Object Table”
IS 257 - Fall 2002 2002.10.31- SLIDE 30
Constructor Functions
• INSERT INTO Animal values (ANIMAL_TY(‘Mule’, ‘Frances’, TO_DATE(‘01-APR-1997’, ‘DD-MM-YYYY’)));
• Insert a new ANIMAL_TY object into the table
IS 257 - Fall 2002 2002.10.31- SLIDE 31
Selecting from an Object Table
• Just use the columns in the object…
• SELECT Name from Animal;
IS 257 - Fall 2002 2002.10.31- SLIDE 32
More Complex Objects
• CREATE TYPE Address_TY as object (Street VARCHAR2(50), City VARCHAR2(25), State CHAR(2), zip NUMBER);
• CREATE TYPE Person_TY as object (Name VARCHAR2(25), Address ADDRESS_TY);
• CREATE TABLE CUSTOMER (Customer_ID NUMBER, Person PERSON_TY);
IS 257 - Fall 2002 2002.10.31- SLIDE 33
What Does the Table Look like?
• DESCRIBE CUSTOMER;
• NAME TYPE
• -----------------------------------------------------
• CUSTOMER_ID NUMBER
• PERSON NAMED TYPE
IS 257 - Fall 2002 2002.10.31- SLIDE 34
Inserting
• INSERT INTO CUSTOMER VALUES (1, PERSON_TY(‘John Smith’, ADDRESS_TY(‘57 Mt Pleasant St.’, ‘Finn’, ‘NH’, 111111)));
IS 257 - Fall 2002 2002.10.31- SLIDE 35
Selecting from Abstract Datatypes
• SELECT Customer_ID from CUSTOMER;
• SELECT * from CUSTOMER;
CUSTOMER_ID PERSON(NAME, ADDRESS(STREET, CITY, STATE ZIP))---------------------------------------------------------------------------------------------------1 PERSON_TY(‘JOHN SMITH’, ADDRESS_TY(‘57...
IS 257 - Fall 2002 2002.10.31- SLIDE 36
Selecting from Abstract Datatypes
• SELECT Customer_id, person.name from Customer;
• SELECT Customer_id, person.address.street from Customer;
IS 257 - Fall 2002 2002.10.31- SLIDE 37
Updating
• UPDATE Customer SET person.address.city = ‘HART’ where person.address.city = ‘Briant’;
IS 257 - Fall 2002 2002.10.31- SLIDE 38
Functions
• CREATE [OR REPLACE] FUNCTION funcname (argname [IN | OUT | IN OUT] datatype …) RETURN datatype (IS | AS) {block | external body}
IS 257 - Fall 2002 2002.10.31- SLIDE 39
Example
Create Function BALANCE_CHECK (Person_name IN Varchar2) RETURN NUMBER is BALANCE NUMBER(10,2) BEGIN
SELECT sum(decode(Action, ‘BOUGHT’, Amount, 0)) - sum(decode(Action, ‘SOLD’, amount, 0)) INTO BALANCE FROM LEDGER where Person = PERSON_NAME;
RETURN BALANCE;
END;
IS 257 - Fall 2002 2002.10.31- SLIDE 40
Example
• Select NAME, BALANCE_CHECK(NAME) from Worker;
IS 257 - Fall 2002 2002.10.31- SLIDE 41
TRIGGERS
• Create TRIGGER UPDATE_LODGING INSTEAD OF UPDATE on WORKER_LODGING for each row BEGIN
• if :old.name <> :new.name then update worker set name = :new.name where name = :old.name;
• end if;
• if :old.lodging <> … etc...
IS 257 - Fall 2002 2002.10.31- SLIDE 42
Next Week
• Database Administration
• More on Database Applications