Download Lecture slides

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

C Sharp (programming language) wikipedia , lookup

Team Foundation Server wikipedia , lookup

Microsoft Access wikipedia , lookup

Relational model wikipedia , lookup

SQL wikipedia , lookup

Object-relational impedance mismatch wikipedia , lookup

Transcript
Week 9 (COIT 13143)

Objectives:
– Technologies used to develop database
applications over the past 20 years
– Embedded SQL
– 4GLs and RAD
– Internet and Intranet
– NCs and Java
Module 2
Development Technologies used over the
past 20 years

There have been three main database applications
architecture over the past two decades – each
associated with a particular style of development
technology:
– Centralized (mainframe and minicomputer) -3GL with
embedded DML (e.g. COBOL + SQL)
– PC/LAN (file sharing) – 4GLs (e.g. Microsoft Access)
– Client/Server – RAD tools (e.g. Delphi)
What is Embedded SQL?
“The standard SQL embedded in general
purpose programming languages such as
Pascal, Fortran, Cobol, C and C++”.
 A language in which SQL queries are
embedded is referred to as a host language,
and the SQL structures permitted in the host
language constitute embedded SQL.

Why Embedded SQL?
There exist queries that can be expressed in
a language such as C, Cobol, or Fortran that
can not be expressed in SQL.
 Non-declarative actions-such as printing a
report, interacting with a user, or sending
the results of a query to a graphical user
interface-cannot be done from within SQL.
 SQL is said to be a non procedural language

How does embedded SQL work?

An embedded SQL program must be
processed by a special preprocessor prior to
compilation. Embedded SQL requests are
replaced with host-language declarations
and procedure calls that allow run-time
execution of the database accesses. Then,
the resulting program is compiled by the
host-language compiler.
Embedded SQL Syntax




Building SQL statements into your host program by
beginning them with the keywords EXEC SQL and end
them with a semicolon.
– EXEC SQL …… ;
Within embedded SQL statement, host language variables
must be preceded by a colon(:) to distinguish them from
SQL variables.
Error handling: SQL Communication Area (SQLCA) and
WHENEVER statement.
Transaction: undo or submit the changes made since the
last data definition statement.
Examples of Embedded SQL

EXEC SQL WHENEVER SQLERROR DO func
– perform func when there is a SQL error

EXEC SQL CONNECT :user IDENTIFIED BY
:password
– connect to a database using the specified login

EXEC SQL SELECT … INTO …
– run a SQL select statement

EXEC SQL DELETE FROM ...
– run a SQL delete statement

EXEC SQL INSERT INTO …
– run a SQL insert statement

Embedded SQL – The Basic
– Lets look at some examples of embedded SQL statements.
– Each of the statements below can be placed into a COBOL
program.
EXEC SQL
insert into SP (SNO,PNO,QTY) values (:SUPP-NBR, :NBR-PARTS)
END-EXEC
EXEC SQL
select sum(qty) into :NBR-PARTS from SP where sno= :SUPP-NBR
END-EXEC
EXEC SQL
update S set status=60 where sno = :SUPP-NBR
END-EXEC
EXEC SQL
delete from SP where QTY = 0
END-EXEC

Notes:
– SUPP-NBR, PART-NBR and NBR-PARTS are
host variable declared in the host language
– These variables are used to provide input values
to SQL statements and also receive values
returned by SQL statements
Compiling an Embedded SQL Program
Because an embedded SQL program contains a
mix of SQL and host language statements, it
cannot be submitted directly to a compiler for the
host language. Instead, it is compiled through a
multi-step process. Although this process differs
from product to product, the steps are roughly the
same for all products.
 The illustration on the next page shows the steps
necessary to compile an embedded SQL
program.


Five steps are involved in compiling an embedded SQL
program:
– The embedded SQL program is submitted to the SQL precompiler,
a programming tool. The precompiler scans the program, finds the
embedded SQL statements, and processes them. A different
precompiler is required for each programming language supported
by the DBMS. DBMS products typically offer precompilers for
one or more languages, including C, Pascal, COBOL, Fortran,
Ada, PL/I, and various assembly languages.
– The precompiler produces two output files. The first file is the
source file, stripped of its embedded SQL statements. In their
place, the precompiler substitutes calls to proprietary DBMS
routines that provide the run-time link between the program and
the DBMS. Typically, the names and the calling sequences of these
routines are known only to the precompiler and the DBMS; they
are not a public interface to the DBMS. The second file is a copy
of all the embedded SQL statements used in the program. This file
is sometimes called a database request module, or DBRM.
– The source file output from the precompiler is submitted to the
standard compiler for the host programming language (such as a C
or COBOL compiler). The compiler processes the source code and
produces object code as its output. Note that this step has nothing
to do with the DBMS or with SQL.
– The linker accepts the object modules generated by the compiler,
links them with various library routines, and produces an
executable program. The library routines linked into the executable
program include the proprietary DBMS routines described in step
2.
– The database request module generated by the precompiler is
submitted to a special binding utility. This utility examines the
SQL statements, parses, validates, and optimizes them, and then
produces an access plan for each statement. The result is a
combined access plan for the entire program, representing an
executable version of the embedded SQL statements. The binding
utility stores the plan in the database, usually assigning it the name
of the application program that will use it. Whether this step takes
place at compile time or run time depends on the DBMS.
Example
EXEC
select sum(qty) into :NBR-PARTS from SP where sno = :SUPP-NBR
END-EXEC
 The precompiler replaces this statement with a call to a
procedure to process the SQL statement:
CALL EXECSQL <DBRM#> SQLCODE SUPP-NBR NBR-PARTS

The first parameter in the call to EXECSQL is the
number of the DBRM to execute
– It is an integer generated by the precompiler as it constructs the
DBRMs


The EXECSQL call has one input host variable (SUPPNBR) and one for output (NBR-PARTS)
A variable called SQLCODE provides feedback on the
execution of the SQL statement
Embedded SQL – Cursors

How can I retrieve data one row at a time?
– To retrieve data with SQL one row at a time you need
to use cursor processing.
– Cursor processing is done in several steps:
» Define the row you want to retrieve. This is called declaring
the cursor.
» Open the cursor. This activates the cursor and loads the data.
» Fetch the data into host variable
» Close the cursor.

There are two types of cursors: serial and
scrollable
– A serial cursor allows you to fetch each row once, and
only once. If you want to retrieve a row more than
once, you must close the cursor and re-open it.
– A scrollable cursor allows for moving back and forth
throughout the rows of data.
File Sharing Architecture


Access can be used to develop an application that can be shared by
a small number of users
With shared application developed in access, it is normal to split
the application into two files:
– The database file containing tables, indexes, and relationships – places on
file server
– The application file containing forms, queries, reports, macros and modules
– places on user’s PC
– Application files are associated with the database file through linked tables.
– A database application implemented in this way is said to have a filesharing architecture.

Problems:
– The Jet database engine runs on each user’s PC – this requires a powerful
PC to run the application
– The local database engine treats the remote database file as if it were a local
file
– Every disk page read from the database file must be transferred across the
network, and this places a heavy load on the network and may reduce the
performance of the application.



A file-server application is what we get when we simply
move database to a network server’s hard drive.
The jet database engine that runs on the client
workstation does all data processing.
It is inefficient due to the amount of data that must move
across the network to satisfy queries. For e.g. suppose
you need to retrieve all the customers in Australia. In
this case assuming the State field of the customer table
was indexed, the Jet engine would read the entire index
for this field from the server. It would then retrieve the
records it required.
Client
Access
Jet
Server
Jet Database
Client/Server Architecture






In this architecture, there is one, shared database engine
running in the system.
This database engine runs on the server – the application
server
The application(forms, reports, macros and modules) run
on the user’s PC – the application client.
When the application needs to access the database, an SQL
statement is sent from client to server
This statement is processed on the server, and the results
returned to the client.
Advantage:
– The client can run on a small computer – thin client
– The application places less load on the network, and
consequently, may perform better.
th
4
4GLs and the
Generation
Environment



In the Mid-80’s, the term 4GL was very popular
As the name suggests, 4GLs represent a generational
change from the embedded SQL approach to application
development
4GLs – Context
– Technology that underpins 4GLs appeared in a world of
centralised systems in late-70s/early 80s
– Mini computers, which were a lot cheaper than mainframes,
were on the scene
– Unfortunately, development could not match demand, there
was a growing application backlog
– At that time, one technology that promised to help solve this
problem was relational database.
4GLs and Relational Database



E.F.Codd first proposed the relational model in 1970
RDBMS did not appear until several years later.
Relational database brought three features to help with
the application backlog:
– Simple data structure
– Non-procedural programming
– System Catalog



The first tool to exploit the features mentioned above
were interactive query languages.
Shortly after, report writers were developed to format
data extracted by a query.
Most of the early tools claiming to be 4GLs were report
writer.





In parallel with the development of report writers, other
productivity tools started to emerge for the developer e.g.
screen generators and menu generators.
These tools plus relational database gave rise to the
concept of the 4th Generation Environment
Access provides a development environment – VBA and
macros, both performs the role described for the 4GL.
SQL Server provides Transact-SQL or T-SQL
When you expand a database using SQL Server’s
Enterprise Manager, you will find the system tables
already visible.
RAD tools Vs 4GLs



There are many similarities between RAD tools and
4GLs
The approach to build applications in Access (a 4GL) is
very similar to the approach taken to build the same
application in Visual Basic (a RAD tool)
The main differences between RAD tools and 4GLs is
largely a consequence of two issues:
– The market to which the products are targeted, and
– The scope of applications that can be developed using the
tools

Access is targeted at the following markets:
– The power-user (for small database applications)
– The in-house developer – for small database applications






Visual basic is targeted at the following markets:
– The in-house developer – for applications of any size
– The in-house component developer – to develop distributed
components for large applications
– Development teams –support provided for version control and
distributed applications
– The independent software vendor – for royalty free distribution
of applications.
One market for RAD tools is large organizations looking to move
mainframe applications to PC/LANs (known as downsizing an
application)
RAD tools are also used to upsize file sharing applications to clientserver application
Together rightsizing covers both concept.
Most RAD tools are being extended to support Internet development
SQL Server is neither a RAD nor a 4GL. It is intended for more
heavy duty applications by professional developers.
The Internet


Internet is the 1st international computer network
Internet is likely to have a substantial impact on a
number of large industries including:
–
–
–
–


News – print and broadcast
Entertainment
Commerce : B2C, B2
Education and training
In database administration terms, eCommerce is having
the most immediate impact
Initially, B2C eCommerce application attracted most
interest. But because of the .com crash, followed by a
slowing US economy, then 11th September, have
terminated many endeavors
Concerns about security, viruses and
stability of the internet have also done
damage to the vision
 But recently, more interest has been shown
in B2B transactions on the internet.

Intranets





Prior to the arrival of the Internet, the database
development community focused on developments in
the client/server, rapid application development market
The client/server architecture offered a number of
potential advantages over the centralised
(mainframe/minicomputer) approach to application
development and delivery:
Many client/server applications were developed and
implemented.
Increasing use of PC/LANs exposed the main problem
with the architecture – support costs
When calculating total cost of ownership(TCO), we
need to add the cost of software installation on each PC,
and the time taken to fix problems on the PCs and the
LAN
NCs and Java






With the passage of time, tools to manage installation of
software on PCs, and to diagnose problems on LANs,
have matured but time taken to fix problems on PCs
continues to impose a substantial cost
With a growing awareness of the costs of supporting
PC/LANs, Java entered the scene
Java is a programming language originally designed for
embedded systems – e.g. data communication devices,
that can be re-programmed to perform new tasks
Java is similar to C++ but smaller – small enough to run
in a browser
So the vision of graphical cross platform application
written in Java, running in a browser, was born.
This vision was further developed with the concept of
the Network computer (NC)
NC

What is a Network Computer?
– Network Computers (NCs) are a new type of affordable computing
device which cost much less that traditional PCs to buy and
maintain, they are also strongly standards based to ensure that
numerous different hardware and software implementations will
interoperate properly.


Thin clients are simpler computers or programs which are
designed to work with a server, so that the client requires
less complexity, local storage, processing, or maintenance.
Network Computers are an example of thin clients.
Are they dump Terminals ?
– unlike dumb terminals which simply display the output of a
program running on a server elsewhere on the network, Network
Computers actually do local processing and are much closer to PCs
than to dumb terminals.





The NC is a small, cheap device capable of
running a browser, and thus, Java applications
The NC was marketed as a possible replacement
of PC
One of the main attractions of the NC is that the
cost of managing PCs is removed
Unfortunately, early java applications have not
delivered the rich capabilities and high
performance users are family with from their
windows application
Users have also been reluctant to give up their PCs
and return to a more centralised architecture.
Wireless and Smart Devices

Much of the support for NCs has now moved
behind the exciting area of wireless devices.
– For information on developing applications for wireless
devices using Java see http://wireless.java.sun.com

Microsoft uses the term smart devices to cover
wireless devices as well as laptops and PCs
– Microsoft latest development platform - .Net – has been
designed to support a wide range of devices
– For information on .Net support for small devices see :
http://www.microsoft.com/net/products/devices.asp
currently, a mix of technologies are being used to
development database applications
– new eCommerce applications are being developed for the
Internet
– organisations are experimenting with hosting in-house
applications on intranets
– client/server applications are still being supported and
developed
– departments continue to develop small database applications
using 4GLs
– COBOL applications with embedded SQL are still being
modified to deal with changing regulatory environments, such
as taxation changes
– New applications are being developed for smart and wireless
devices.