Kroenke-DBP-e10-PPT-Chapter12

Download Report

Transcript Kroenke-DBP-e10-PPT-Chapter12

David M. Kroenke’s
Database Processing:
Fundamentals, Design, and Implementation
Chapter Twelve:
ODBC, OLE DB, ADO,
and ASP
Part Two
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-1
OLE DB
• OLE DB is an implementation of the Microsoft
OLE object standard.
– OLE DB objects are COM objects and support all required
interfaces for such objects.
• OLE DB breaks the features and functions of a DBMS
into COM objects, making it easier for vendors to
implement portions of functionality.
– This characteristic overcomes a major disadvantage of ODBC.
– With ODBC, a vendor must create an ODBC driver for almost all
DBMS features and functions in order to participate in ODBC at
all.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-2
Object-Oriented Concepts
• An object-oriented programming object is an
abstraction that is defined by its properties and
methods.
– An abstraction is a generalization of something.
– A property specifies set of characteristics of an
object.
– A method refers to actions that an object can
perform.
– A collection is an object that contains a group of
other objects.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-3
OLE DB Goals
• Create object interfaces for DBMS functionality pieces:
– Query, update, transaction management, etc.
• Increase flexibility:
–
–
–
–
Allow data consumers to use only the objects they need.
Allow data providers to expose pieces of DBMS functionality.
Providers can deliver functionality in multiple interfaces.
Interfaces are standardized and extensible.
• Provide object interfaces over any type of data:
– Relational and non-relational database, ODBC or native, VSAM
and other files, Email, etc.
• Do not force data to be converted or moved from where
it is.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-4
OLE DB Basic Constructs
• There are data consumers and data providers:
– Data consumers - Users of OLE DB functionality.
– Data providers - Sources of OLE DB functionality.
• An interface is a set of objects and the properties and
methods they expose in that interface:
– Objects may expose different properties and methods in different
interfaces.
• An implementation is how an object accomplishes its
tasks:
– Implementations are hidden from the outside world and may be
changed without impacting the users of the objects.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-5
OLE DB Terminology:
Data Providers
• A rowset is equivalent to a cursor.
• OLE DB has two types of data providers:
– Tabular data provider — exposes data via rowsets.
• Examples: DBMS, spreadsheets, ISAMs, email.
– Service provider — a transformer of data through
OLE DB interfaces.
• It is both a consumer and a provider of transformed data.
• Examples: query processors, XML document creator.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-6
Rowset Interfaces
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-7
Active Data Objects (ADO)
• Active Data Objects (ADO) characteristics:
– A simple object model for OLE DB data consumers
– It can be used from VBScript, JScript, Visual Basic,
Java, C#, C++
– It is a single Microsoft data access standard
– Data access objects are the same for all types of OLE
DB data
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-8
Invoking ADO from Active Server Pages
• In Microsoft’s Active Server Pages (ASP)
are Web pages where:
– Statements are enclosed within the
characters <% . . .%>.
– ASP statements are processed on the Web
server.
– Other (HTML) statements are processed by
the client Web browser.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-9
The ADO Object Model
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-10
Connection Object
• A connection object establishes a connection
to a data provider and data source.
– Connections have an isolation mode.
• Once a connection is created, it can be used to
create RecordSet and Command objects.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-11
RecordSet Objects
• RecordSet objects represent cursors:
– They have both CursorType and LockType properties.
– RecordSets can be created with SQL statements.
– The Fields collection of a RecordSet can be
processed to individually manipulate fields.
– The Errors collection contains one or more error
messages that result from an ADO operation.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-12
Command Object
• The command object is used to execute
stored parameterized queries or stored
procedures:
– Input data can be sent to the correct ASP
using the HTML FORM tag.
– Table updates are made using the RecordSet
Update method.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-13
ADO Constants:
Isolation Levels
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-14
ADO Constants:
Cursor Levels
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-15
ADO Constants:
Lock Types
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-16
Connection Object:
ASP Code
<%
Dim objConn
Set objConn = Server.CreateObject (“ADODB.connection”)
objConn.IsolationLevel = adXactReadCommitted
‘ use ADOVBS
objConn.Open “ViewRidgeSS”,
%>
<!--#include virtual =“ADOExamples/ADOVBS.inc -->
<%
objConn.Open “DSN=ViewRidgeOracle2;UID=DK1;PWD=Sesame”
%>
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-17
RecordSet Object:
ASP Code
<%
Dim objRecordSet, varSql
varSQL = “SELECT * FROM ARTIST”
Set objRecordSet = Server.CreateObject(“ADODB.Recordset”)
objRecordSet.CursorTye = adOpenStatic
objRecordSet.LockType = adLockReadOnly
objRecordSet.Open varSQL, objConn
%>
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-18
Fields Collection:
ASP Code
<%
Dim varI, varNumCols, objField
varNumCols = objRecordSet.Fields.Count
For varI = 0 to varNumCols - 1
Set objField = objRecordSet.Fields(varI)
‘ objField.Name now has the name of the field
‘ objField.Value now has the value of the field
‘ can do something with them here
Next
>%
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-19
Errors Collection:
ASP Code
<%
Dim varI, varErrorCount, objError
On Error Resume Next
varErrorCount = objConn.Errors.Count
If varErrorCount > 0 Then
For varI = 0 to varErrorCount - 1
Set objError = objConn.Errors(varI)
‘ objError.Description contains
‘ a description of the error
Next
End If
>%
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-20
Command Object:
ASP Code
<%
Dim
objCommand, objParam, objRs
‘Create the Command object, connect it to objConn and
set its format
Set objCommand = Server.CreateObject(“ADODB.command”)
Set objCommand.ActiveConnection = objConn
objCommand.CommandText=“{call FindArtist (?)}”
‘Set up the parameter with the necessary value
Set objParam = objCommand.CreateParameter (“Nationality”,
adChar, adParamInput, 25)
objCommand.Parameters.Append objParam
objParam.Value = “Spanish”
‘Fire the Stored Proc
Set objRs = objCommand.Execute
>%
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-21
ADO
Example:
Reading a
Table
Artist.asp
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-22
ADO Example: Reading a Table
The Artist.asp Results
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-23
David M. Kroenke’s
Database Processing
Fundamentals, Design, and Implementation
(10th Edition)
End of Presentation:
Chapter Twelve Part Two
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition
© 2006 Pearson Prentice Hall
12-24