CSE202 Database Management Systems

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

XML: Extensible Markup Language
XML DOCUMENTS AND DATABASES
XML: Extensible Markup Language. Slide Chapter Outline Introduction Structured, Semi structured, and Unstructured Data. XML Hierarchical (Tree)
CSC343 – Introduction to databases – A. Vaisman1 Database Application Development.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Visual Web Information Extraction With Lixto Robert Baumgartner Sergio Flesca Georg Gottlob.
1 COS 425: Database and Information Management Systems XML and information exchange.
4/17/2017.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
4/20/2017.
XML – Data Model, DTD and Schema
JSP Standard Tag Library
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
Chapter 26 XML and Internet Databases Copyright © 2004 Pearson Education, Inc.
Announcements Read JDBC Project Step 5, due Monday.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 1 DATADABASE PROGRAMMING 2Chapter 13 from our text.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 27 XML: Extensible Markup Language.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 26-2 Introduction Although.
Chapter 6 MORE SQL: Assertions, Views, and Programming Techniques Copyright © 2004 Pearson Education, Inc.
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Unit 3 — Advanced Internet Technologies Lesson 11 — Introduction to XSL.
XML CSC1310 Fall HTML (TIM BERNERS-LEE) HyperText Markup Language  HTML (HyperText Markup Language): December  Markup  Markup is a symbol.
Martin Kruliš by Martin Kruliš (v1.1)1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
2) Database System Concepts and Architecture. Slide 2- 2 Outline Data Models and Their Categories Schemas, Instances, and States Three-Schema Architecture.
CHAPTER NINE Accessing Data Using XML. McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Introduction The eXtensible.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6.
XML: Extensible Markup Language Abeiku Duncan Leslie Salami Anthony Mensah-Kumah Michelle Amarteifio Joseph Owusu-Badu.
10/3/2017.
Web Database Programming Using PHP
Databases (CS507) CHAPTER 2.
Databases and DBMSs Todd S. Bacastow January 2005.
DEPTT. OF COMP. SC & APPLICATIONS
XML: Extensible Markup Language
Introduction to SQL Programming Techniques
Unit 4 Representing Web Data: XML
Web Database Programming Using PHP
XML QUESTIONS AND ANSWERS
XML: Extensible Markup Language
XML in Web Technologies
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Database Processing with XML
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Chapter 7 Representing Web Data: XML
Chapter 2 Database Environment Pearson Education © 2009.
CPSC-310 Database Systems
Data, Databases, and DBMSs
Database Application Development
DB Programming: SQL Programming Techniques
Introduction to SQL Programming Techniques
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Chapter 8 Advanced SQL.
CSE591: Data Mining by H. Liu
Chapter 2 Database Environment Pearson Education © 2009.
Chapter 2 Database Environment Pearson Education © 2009.
Presentation transcript:

CSE202 Database Management Systems Lecture #7 Prepared & Presented by Asst. Prof. Dr. Samsun M. BAŞARICI

Learning Objectives Differentiate between structured, semistructured, and unstructured data Understand the XML hierarchical (tree) data model Understand XML documents, DTD, and XML schema Store and extract XML documents from databases Understand and use XML languages Extract XML documents from relational databases Understand database programming techniques and related issues Differentiate between embedded SQL, dynamic SQL, and SQLJ Apply database programming with function calls: SQL/CLI and JDBC Implement database stored procedures and SQL/PSM Compare the three approaches

Outline Structured, Semistructured, and Unstructured Data XML Hierarchical (Tree) Data Model XML Documents, DTD, and XML Schema Storing and Extracting XML Documents from Databases XML Languages Extracting XML Documents from Relational Databases Database Programming: Techniques and Issues Embedded SQL, Dynamic SQL, and SQLJ Database Programming with Function Calls: SQL/CLI and JDBC Database Stored Procedures and SQL/PSM Comparing the Three Approaches

Part 1 XML: Extensible Markup Language

XML: Extensible Markup Language Data sources Database storing data for Internet applications Hypertext documents Common method of specifying contents and formatting of Web pages XML data model

Structured, Semistructured, and Unstructured Data Represented in a strict format Example: information stored in databases Semistructured data Has a certain structure Not all information collected will have identical structure

Structured, Semistructured, and Unstructured Data (cont.) Schema information mixed in with data values Self-describing data May be displayed as a directed graph Labels or tags on directed edges represent: Schema names Names of attributes Object types (or entity types or classes) Relationships

Structured, Semistructured, and Unstructured Data (cont.)

Structured, Semistructured, and Unstructured Data (cont.) Limited indication of the of data document that contains information embedded within it HTML tag Text that appears between angled brackets: <...> End tag Tag with a slash: </...>

Structured, Semistructured, and Unstructured Data (cont.) HTML uses a large number of predefined tags HTML documents Do not include schema information about type of data Static HTML page All information to be displayed explicitly spelled out as fixed text in HTML file

XML Hierarchical (Tree) Data Model Elements and attributes Main structuring concepts used to construct an XML document Complex elements Constructed from other elements hierarchically Simple elements Contain data values XML tag names Describe the meaning of the data elements in the document

XML Hierarchical (Tree) Data Model (cont.) Tree model or hierarchical model Main types of XML documents Data-centric XML documents Document-centric XML documents Hybrid XML documents Schemaless XML documents Do not follow a predefined schema of element names and corresponding tree structure

XML Hierarchical (Tree) Data Model (cont.) XML attributes Describe properties and characteristics of the elements (tags) within which they appear May reference another element in another part of the XML document Common to use attribute values in one element as the references

XML Documents, DTD, and XML Schema Well formed Has XML declaration Indicates version of XML being used as well as any other relevant attributes Every element must matching pair of start and end tags Within start and end tags of parent element DOM (Document Object Model) Manipulate resulting tree representation corresponding to a well-formed XML document

XML Documents, DTD, and XML Schema (cont.) SAX (Simple API for XML) Processing of XML documents on the fly Notifies processing program through callbacks whenever a start or end tag is encountered Makes it easier to process large documents Allows for streaming

XML Documents, DTD, and XML Schema (cont.) Valid Document must be well formed Document must follow a particular schema Start and end tag pairs must follow structure specified in separate XML DTD (Document Type Definition) file or XML schema file

XML Documents, DTD, and XML Schema (cont.) Notation for specifying elements XML DTD Data types in DTD are not very general Special syntax Requires specialized processors All DTD elements always forced to follow the specified ordering of the document Unordered elements not permitted

XML Schema XML schema language Standard for specifying the structure of XML documents Uses same syntax rules as regular XML documents Same processors can be used on both

XML Schema (cont.) Identify specific set of XML schema language elements (tags) being used Specify a file stored at a Web site location XML namespace Defines the set of commands (names) that can be used

XML Schema (cont.) XML schema concepts: Description and XML namespace Annotations, documentation, language Elements and types First level element Element types, minOccurs, and maxOccurs Keys Structures of complex elements Composite attributes

Storing and Extracting XML Documents from Databases Most common approaches Using a DBMS to store the documents as text Can be used if DBMS has a special module for document processing Using a DBMS to store document contents as data elements Require mapping algorithms to design a database schema that is compatible with XML document structure

Storing and Extracting XML Documents from Databases (cont.) Designing a specialized system for storing native XML data Called Native XML DBMSs Creating or publishing customized XML documents from preexisting relational databases Use a separate middleware software layer to handle conversions

XML Languages Two query language standards XPath XQuery Specify path expressions to identify certain nodes (elements) or attributes within an XML document that match specific patterns XQuery Uses XPath expressions but has additional constructs

XPath: Specifying Path Expressions in XML XPath expression Returns a sequence of items that satisfy a certain pattern as specified by the expression Either values (from leaf nodes) or elements or attributes Qualifier conditions Further restrict nodes that satisfy pattern Separators used when specifying a path: Single slash (/) and double slash (//)

XPath: Specifying Path Expressions in XML (cont.)

XPath: Specifying Path Expressions in XML (cont.) Attribute name prefixed by the @ symbol Wildcard symbol * Stands for any element Example: /company/*

XPath: Specifying Path Expressions in XML (cont.) Axes Move in multiple directions from current node in path expression Include self, child, descendent, attribute, parent, ancestor, previous sibling, and next sibling

XPath: Specifying Path Expressions in XML (cont.) Main restriction of XPath path expressions Path that specifies the pattern also specifies the items to be retrieved Difficult to specify certain conditions on the pattern while separately specifying which result items should be retrieved

XQuery: Specifying Queries in XML XQuery FLWR expression Four main clauses of XQuery Form: FOR <variable bindings to individual nodes (elements)> LET <variable bindings to collections of nodes (elements)> WHERE <qualifier conditions> RETURN <query result specification> Zero or more instances of FOR and LET clauses

XQuery: Specifying Queries in XML (cont.) XQuery contains powerful constructs to specify complex queries www.w3.org Contains documents describing the latest standards related to XML and XQuery

Other Languages and Protocols Related to XML Extensible Stylesheet Language (XSL) Define how a document should be rendered for display by a Web browser Extensible Stylesheet Language for Transformations (XSLT) Transform one structure into different structure Web Services Description Language (WSDL) Description of Web Services in XML

Other Languages and Protocols Related to XML (cont.) Simple Object Access Protocol (SOAP) Platform-independent and programming language-independent protocol for messaging and remote procedure calls Resource Description Framework (RDF) Languages and tools for exchanging and processing of meta-data (schema) descriptions and specifications over the Web

Extracting XML Documents from Relational Databases Creating hierarchical XML views over flat or graph-based data Representational issues arise when converting data from a database system into XML documents UNIVERSITY database example

Breaking Cycles to Convert Graphs into Trees Complex subset with one or more cycles Indicate multiple relationships among the entities Difficult to decide how to create the document hierarchies Can replicate the entity types involved to break the cycles

Other Steps for Extracting XML Documents from Databases Create correct query in SQL to extract desired information for XML document Restructure query result from flat relational form to XML tree structure Customize query to select either a single object or multiple objects into document

Part 2 SQL Programming

Introduction to SQL Programming Techniques Database applications Host language Java, C/C++/C#, COBOL, or some other programming language Data sublanguage SQL SQL standards Continually evolving Each DBMS vendor may have some variations from standard

Database Programming: Techniques and Issues Interactive interface SQL commands typed directly into a monitor Execute file of commands @<filename> Application programs or database applications Used as canned transactions by the end users access a database May have Web interface

Approaches to Database Programming Embedding database commands in a general-purpose programming language Database statements identified by a special prefix Precompiler or preprocessor scans the source program code Identify database statements and extract them for processing by the DBMS Called embedded SQL

Approaches to Database Programming (cont.) Using a library of database functions Library of functions available to the host programming language Application programming interface (API) Designing a brand-new language Database programming language designed from scratch First two approaches are more common

Impedance Mismatch Differences between database model and programming language model Binding for each host programming language Specifies for each attribute type the compatible programming language types Cursor or iterator variable Loop over the tuples in a query result

Typical Sequence of Interaction in Database Programming Open a connection to database server Interact with database by submitting queries, updates, and other database commands Terminate or close connection to database

Embedded SQL, Dynamic SQL, and SQLJ C language SQLJ Java language Programming language called host language

Retrieving Single Tuples with Embedded SQL EXEC SQL Prefix Preprocessor separates embedded SQL statements from host language code Terminated by a matching END-EXEC Or by a semicolon (;) Shared variables Used in both the C program and the embedded SQL statements Prefixed by a colon (:) in SQL statement

Retrieving Single Tuples with Embedded SQL (cont.)

Retrieving Single Tuples with Embedded SQL (cont.) Connecting to the database CONNECT TO <server name>AS <connection name> AUTHORIZATION <user account name and password> ; Change connection SET CONNECTION <connection name> ; Terminate connection DISCONNECT <connection name> ;

Retrieving Single Tuples with Embedded SQL (cont.) SQLCODE and SQLSTATE communication variables Used by DBMS to communicate exception or error conditions SQLCODE variable 0 = statement executed successfully 100 = no more data available in query result < 0 = indicates some error has occurred

Retrieving Single Tuples with Embedded SQL (cont.) SQLSTATE String of five characters ‘00000’ = no error or exception Other values indicate various errors or exceptions For example, ‘02000’ indicates ‘no more data’ when using SQLSTATE

Retrieving Single Tuples with Embedded SQL (cont.)

Retrieving Multiple Tuples with Embedded SQL Using Cursors Points to a single tuple (row) from result of query OPEN CURSOR command Fetches query result and sets cursor to a position before first row in result Becomes current row for cursor FETCH commands Moves cursor to next row in result of query

Retrieving Multiple Tuples with Embedded SQL Using Cursors (cont.) FOR UPDATE OF List the names of any attributes that will be updated by the program Fetch orientation Added using value: NEXT, PRIOR, FIRST, LAST, ABSOLUTE i, and RELATIVE i

Specifying Queries at Runtime Using Dynamic SQL Execute different SQL queries or updates dynamically at runtime Dynamic update Dynamic query

SQLJ: Embedding SQL Commands in Java Standard adopted by several vendors for embedding SQL in Java Import several class libraries Default context Uses exceptions for error handling SQLException is used to return errors or exception conditions

SQLJ: Embedding SQL Commands in Java (cont.)

Retrieving Multiple Tuples in SQLJ Using Iterators Object associated with a collection (set or multiset) of records in a query result Named iterator Associated with a query result by listing attribute names and types in query result Positional iterator Lists only attribute types in query result

Retrieving Multiple Tuples in SQLJ Using Iterators (cont.)

Database Programming with Function Calls: SQL/CLI & JDBC Use of function calls Dynamic approach for database programming Library of functions Also known as application programming interface (API) Used to access database SQL Call Level Interface (SQL/CLI) Part of SQL standard

SQL/CLI: Using C as the Host Language Environment record Track one or more database connections Set environment information Connection record Keeps track of information needed for a particular database connection Statement record Keeps track of the information needed for one SQL statement

SQL/CLI: Using C as the Host Language (cont.) Description record Keeps track of information about tuples or parameters Handle to the record C pointer variable makes record accessible to program

JDBC: SQL Function Calls for Java Programming Java function libraries Single Java program can connect to several different databases Called data sources accessed by the Java program Class.forName("oracle.jdbc.driver.OracleDriver") Load a JDBC driver explicitly

JDBC: SQL Function Calls for Java Programming Connection object Statement object has two subclasses: PreparedStatement and CallableStatement Question mark (?) symbol Represents a statement parameter Determined at runtime ResultSet object Holds results of query

Database Stored Procedures and SQL/PSM Program modules stored by the DBMS at the database server Can be functions or procedures SQL/PSM (SQL/Persistent Stored Modules) Extensions to SQL Include general-purpose programming constructs in SQL

Database Stored Procedures and Functions Persistent stored modules Stored persistently by the DBMS Useful: When database program is needed by several applications To reduce data transfer and communication cost between client and server in certain situations To enhance modeling power provided by views

Database Stored Procedures and Functions (cont.) Declaring stored procedures: CREATE PROCEDURE <procedure name> (<parameters>) <local declarations> <procedure body> ; declaring a function, a return type is necessary, so the declaration form is CREATE FUNCTION <function name> (<parameters>) RETURNS <return type> <function body> ;

Database Stored Procedures and Functions (cont.) Each parameter has parameter type Parameter type: one of the SQL data types Parameter mode: IN, OUT, or INOUT Calling a stored procedure: CALL <procedure or function name> (<argument list>) ;

SQL/PSM: Extending SQL for Specifying Persistent Stored Modules Conditional branching statement: IF <condition> THEN <statement list> ELSEIF <condition> THEN <statement list> ... ELSE <statement list> END IF ;

SQL/PSM (cont.) Constructs for looping

SQL/PSM (cont.)

Comparing the Three Approaches Embedded SQL Approach Query text checked for syntax errors and validated against database schema at compile time For complex applications where queries have to be generated at runtime Function call approach more suitable

Comparing the Three Approaches (cont.) Library of Function Calls Approach More flexibility More complex programming No checking of syntax done at compile time Database Programming Language Approach Does not suffer from the impedance mismatch problem Programmers must learn a new language

Dependencies, Normalization and Relational DB Design Next Lecture Dependencies, Normalization and Relational DB Design

References Ramez Elmasri, Shamkant Navathe; “Fundamentals of Database Systems”, 6th Ed., Pearson, 2014 Universität Hamburg, Fachbereich Informatik, Einführung in Datenbanksysteme, Lecture Notes, 1999