Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
COS 346
Day 25
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-1
Agenda
• Questions?
• Quiz 4 is on May 4
– DP Chap 12 13 & 15
– Skipping chapter 14
• Capstone Progress reports Due
• Assignment 9 being corrected
– Only did first pass---most of them look real good
• Assignment 10 is posted due May 1
• Assignment 11 is posted due May 4
• Capstones projects and presentations are due May
12 at 10AM
• Today we will be discussing XML and ADO.NET
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-2
David M. Kroenke’s
Database Processing:
Fundamentals, Design, and Implementation
Chapter Thirteen:
XML and ADO.NET
Part Three
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-3
Global Elements
• To eliminate the definition duplication,
elements can be declared globally, i.e.,
reside at the top level of the schema, and
then reused.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-4
Global Elements :
XML Schema with Global PhoneType
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-5
Global Elements :
PhoneType Global Element
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-6
Global Elements :
Graphical Representation of Schema
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-7
Creating XML Documents from
Database Data
• Both Oracle and SQL Server can generate XML
documents from database data.
• For Oracle — Use http://www.oracle.com
• For SQL Server:
– SELECT . . . FOR XML
• SELECT … FOR XML RAW — Places the values of columns
as attributes in the XML document.
• SELECT … FOR XML AUTO, ELEMENTS — Places the
values of columns as elements in the XML document.
• SELECT … FOR XML EXPLICIT — Allows the designation
of which values of columns become attributes and elements.
• XML Spy can generate schemas from such
output.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-8
Using SQL Query Analyzer,
Dreamweaver and XML SPY
• http://www.topxml.com/sql/
• In SQL Query Analyzer Tools/options
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-9
Using SQL Query Analyzer,
Dreamweaver and XML SPY
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-10
Dreamweaver
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-11
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-12
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-13
XML Schema with Multivalue Paths
• Some views cannot be created in a single
SQL statement because the construct
requires two or more multivalued paths.
• XML does not have this limitation.
• An XML document can have as many
multivalued paths as necessary.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-14
Multivalue
Paths:
XML
Schema
with Two
Multivalued
Paths
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-15
Multivalue Paths:
Graphical View of the Schema
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-16
Industries with XML Industry Standards
http://www.xml.org/
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-17
Industries with XML Industry Standards
(Continued)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-18
XML Standards
• XML: Extensible Markup Language.
• XSL: XSLT Stylesheet. The document that provides the
{match, action} pairs and other data for XSLT to use
when transforming an XML document.
• XSLT: A program or process that applies XSLT
Stylesheets to an XML document to produce a
transformed XML document.
• XML schema: An XML-compliant language for
constraining the structure of an XML document.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-19
Additional XML Standards
• Xpath
– A sublanguage within XSLT used to identify parts of an XML
document to be transformed
– Can also be used for calculations and string manipulation
• Xpointer
– A standard for linking one document to another
• SAX: Simple API (application program interface) for
XML.
– An event-based parser that notifies a program when the
elements of an XML document have been encountered during
document parsing
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-20
Additional XML Standards
(Continued)
• DOM: Document Object Model.
– An API that represents an XML document as a tree
– Each node of the tree represents a piece of the XML document.
– A program can directly access and manipulate a node of the
DOM representation.
• XQuery
– A standard for expressing database queries as XML documents
– The structure of the query uses XPath facilities, and the result of
the query is represented in an XML format.
• XML Namespaces: A standard for allocating terminology
to defined collections
– X:Name is interpreted as the element Name as defined in
namespace X.
– Useful for disambiguating terms
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-21
David M. Kroenke’s
Database Processing
Fundamentals, Design, and Implementation
(10th Edition)
End of Presentation:
Chapter Thirteen Part Three
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-22
David M. Kroenke’s
Database Processing:
Fundamentals, Design, and Implementation
Chapter Thirteen:
XML and ADO.NET
Part Four
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-23
ADO.NET
• ADO.NET is a new, improved, and greatly
expanded version of ADO that was developed
for the Microsoft .NET initiative.
• It incorporates all of the functionality of ADO and
OLE DB facilitates the transformation of XML
documents to and from database constructs.
• It uses datasets, which are in-memory, fullyfunctioned, independent databases.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-24
Role of ADO.NET
• ADO.NET serves as an intermediary between
all types of .NET applications and the DBMS
and database:
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-25
Data Provider
• A .NET data provider is a library of classes that
provides ADO.NET services.
• Microsoft’s provides three data providers:
– OLE DB data provider can be used to process any
OLE DB-compliant data source.
– SQLClient data provider is purpose-built for use with
SQL Server.
– OracleClient data provider is purpose-built for use
with Oracle.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-26
Data Provider Components
• A connection object is similar to the OBDC’s
connection object.
• A command object is created on an established
connection.
• A data reader provides read-only, forward-only, fast
access to database data.
• An application can get and put data to and from the
database using the command object.
• A dataset is an in-memory database that is
disconnected from any regular database.
– It distinguishes ADO.NET from the previous data access
technology.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-27
Data Provider Components
(Continued)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-28
The ADO.NET Dataset
• A dataset is an in-memory database that is
disconnected from any regular database.
• Datasets can have:
– Multiple tables, views, and relationships
• Tables may have surrogate key (auto increment columns),
primary keys, and be declared as unique.
– Referential integrity rules and actions
– The equivalent of triggers
• Datasets may be constructed from several
different databases and managed by different
DBMS products.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-29
Dataset Advantages
• Dataset contents and its XML schema can be easily
formatted as an XML document.
• Also, XML schema documents can be read to create the
structure of the dataset, and XML documents can be
read to fill the dataset.
• Datasets are needed to provide a standardized, nonproprietary means to process database views.
– This is important for the processing of views with multiple multivalue paths.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-30
Dataset Disadvantages
• Because dataset data are disconnected from regular
database, only optimistic locking can be used when
updating the regular database with the dataset.
• In the case of conflict, either the dataset must be
reprocessed or the data change must be forced onto the
database, causing the lost update problem.
• Thus, datasets cannot be used for applications in which
optimistic locking is problematical.
– Instead, the ADO.NET command object should be used.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-31
ADO.NET:
Creating the Dataset, Connection, and Data Adapter
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-32
ADO.NET:
Using the Data
Adapter to Fill the
Dataset Tables
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-33
ADO.NET:
Building Relationships
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-34
ADO.NET:
Creating
Referential
Integrity
Constraints
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-35
ADO.NET:
Adding a Computed Column to a Data Table
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-36
ADO.NET:
Using Data Grids
– Filling the Grids
with Dataset
Tables
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-37
ADO.NET:
Using Data Grids — Grid Display in Brower
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-38
David M. Kroenke’s
Database Processing:
Fundamentals, Design, and
Implementation
Chapter Thirteen:
XML and ADO.NET
Part Five
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-39
ADO.NET:
Code to Generate an XML Document from the Dataset
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-40
ADO.NET:
Portion of XML Document Generated from the Dataset
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-41
ADO.NET:
Code to Generate an XML Schema from the Dataset
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-42
ADO.NET:
Portion of XML Schema Generated from the Dataset
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-43
ADO.NET:
Updating a Dataset and Database — Update Code
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-44
ADO.NET:
Updating a Dataset and Database — Trigger-Like Event
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-45
ADO.NET:
Updating a Dataset and Database
Display RowVersion Code
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-46
ADO.NET:
Updating a Dataset and Database
Creating the Update Command
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-47
ADO.NET:
Updating a Dataset and Database
Log Showing Dataset Updates
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-48
ADO.NET:
Updating a Dataset and Database
Dataset Tables after Update
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-49
David M. Kroenke’s
Database Processing
Fundamentals, Design, and Implementation
(10th Edition)
End of Presentation:
Chapter Thirteen Part Five
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
13-50