Client Server Databases
Client Server Databases
Literature
Tamer Özsu and Patrice Valduriez : Principles of distributed database systems. Second Edition,
Prentice Hall, Englewood Cliffs, New Jersey, 666 pages, 1999
ODBC - Tutorial : ADABAS ODBC Reference
PERL - Reference
Client machines:
o Run own copy of an operating system.
o Run one or more applications using the client machine's CPU, memory.
o Application communicates with DBMS server running on server machine through
a Database Driver
o Database driver (middleware) makes a connection to the DBMS server over a
network.
o Examples of clients: PCs with MS Windows operating system. Forms and reports
developed e.g. Oracle Developer/2000, etc.
Server Machines:
o Run own copy of an operating system.
o Run a Database Management System that manages a database.
o Provides a Listening daemon that accepts connections from client machines and
submits transactions to DBMS on behalf of the client machines.
o Examples: Sun Sparc server running UNIX operating system. RDBMS such as
Oracle Server, Sybase, Informix, DB2, etc.
Middleware:
o Small portion of software that sits between client and server.
o Establishes a connection from the client to the server and passes commands (e.g.,
SQL) between them.
o See ODBC below.
o Examples:
For Oracle: SQL*Net (or Net8) running on both client and server.
For Sybase: Sybase Open Client and Open Server.
For IBM DB2: Client Application Enablers
Mainframe Computing
Mainframe computing was the popular computing model before the client/server model became
the widespread standard. In mainframe computing, the mainframe performs all processing and
uses a "dumb" terminal (one with no processing power of its own) as a display unit. For
example, retrieving and displaying employee information on a terminal requires the following
steps:
1. Display a form on the terminal into which a user can enter an employee ID
2. Accept the employee ID information.
3. Validate the format of the information.
4. Check the availability of the employee information.
5. Get the employee information from the database.
6. Format the data for display on the users terminal.
7. Display the employee information on the terminal.
We can categorize these tasks as those related to data presentation (steps 1, 6, and 7),
those related to data validation (steps 2 and 3), and those related to data access (steps 4
and 5). The mainframe performs all of the steps because the terminal has no processing
capability.
In the mainframe processing model, the server is heavily loaded because it performs all
of the processing for every client (mainframes are computing monsters) In the
client/server model, however, clients can perform some portion of the application
processing, such as data presentation and some data validation. This off-loading of some
tasks to clients with processing power improves performance because the server has more
time for processing requests.
In just the last few years, the client/server model has gone from being the "new trend" in
distributed (networked) computing to the "traditional model" for implementing distributed
computing. It divides processing into client applications and server applications that cooperate
to accomplish tasks for the integrated application.
Here are a few of the many advantages that client/server computing offers over the
computing models that came before it:
Simplifies computer interactions for the user because smart clients implemented on
desktop workstations present graphical user interfaces (GUIs) and multimedia
applications. The cost of developing applications that use these types of interfaces for
desktop workstations is less expensive than it is for the servers in mainframe computing.
Reduces network traffic, which improves performance. Consider the example given
previously in the section ``Mainframe Computing''. The mainframe model requires three
network events: in step 1 when the host must display the form on the screen; in step 2
when the client sends the employee ID back to the host; and in step 6 when the host sends
the employee information back to the terminal and displays it. The same example using
the client/server model requires only two network events: for step 4 when the client sends
the employee ID to the server and in step 6 when the server sends the employee
information back to the client.
Allows an organization to use a variety of equipment to meet the needs of different
applications and users because it supports a heterogeneous environment. Programmers
can get the processing power they need from workstations, and managers can work with
computers that are best for creating schedules and other spreadsheets using desktop
computers. The organization can save money by giving each employee the right amount
of computing power needed to do their jobs.
Client and server applications can reside on the same computer, or node; however, in a
distributed computing environment, they usually reside on different nodes. Nodes are
distinguished as client nodes and server nodes depending on their role.
Client nodes tend to be generalized. Computers that run client applications may include many
types of clients, such as a directory client, a file client, and a print client. There are often many
nodes running the same client applications so that a single server node, such as a print server,
serves several client nodes. Although a single server node can accommodate more than one
server application, system designers often implement server applications on dedicated server
nodes because servers tend to be more specialized and require more processing and system
resources than clients.
A server application is typically a continuous process (for example, a daemon in UNIX) while a
client application is most often a standard application program. During the course of its normal
processing, a client application calls API routines to send the requests to a server. When the
client has finished its work, it stops execution. As a dedicated process, the server runs
continuously: it waits for requests, detects them, processes them, returns the results, and then
waits for the next request.
The terms "client" and "server" characterize relative roles rather than absolute roles. For
example, in executing a print request, the print server becomes a client if it has to ask a file
server to send it a copy of the file it is going to print.
Architecture is fully functional when it allows clients to act as servers and servers to act as
clients when necessary. For example, Sybase implements this capability with the Open Client
and Open Server products. Sybase applications that have both client and server functionality
incorporate both Open Client and Open Server libraries.
FigureClientServer shows an example in which an application acts as both a client and a server.
As a server, it responds to requests from and returns results to the Open Client application. As a
client, it makes requests of the SQL Server and processes the results of those requests.
In the Sybase client/server database environment, SQL Server runs all of the actual database
management system¯it does all the processing associated with database access. The database
server carries out the tasks initiated by client requests directed to the database. It is built on a
multithreaded architecture and ensures data integrity, concurrency control, and the ability to
recover from failures. The database server also maintains the data dictionary which defines the
structure and contents of the database. The database client performs all the processing not
associated with database access.
In a two-tier configuration, client applications connect directly to server applications and submit
requests using Open Server applications or remote procedure calls (RPCs). RPCs allow users to
open a connection to a single SQL Server, and that SQL Server can then access data from many
other servers. A SQL Server application programmer can write custom event handlers to process
client requests.
The first tier in a two-tier configuration consists of presentation and application logic. Examples
of applications at this layer are:
The second tier in a two-tier configuration offers direct service management and handles
connections. It can include database servers and general purpose servers such as e-mail and print
servers. Examples of these applications are:
SQL Server applications that do not require global distributed transaction support
Print, mail, or compute servers built with Open Server
Client messaging services built on event notification that use Open Server as a messaging
hub
FigureTwoTier shows SQL Server and Open Server applications in a two-tier configuration.
When developers design and implement software using a component model, they create self-
contained software blocks or components, each with a specific function. A component can be
replaced by another that has the same specifications without rewriting or changing surrounding
components. This component model for software design also results in the ability to reuse
components.
Three-tier architecture, based on the component model, is a popular design solution for large or
complex server applications that run under some type of middleware, such as a transaction
processing monitor or an object-oriented environment. The three-tier architecture allows the
flexibility and freedom to replace components without affecting the rest of the system.
Advertissment ????? Sybase is the only database company that makes it easy to implement an
independent application in the middle tier of a three-tier software architecture. FigureThreeTier
illustrates the three-tier topology using Sybase products.
The first tier supports presentation services on the client system. Minimally, it helps
windowing systems display and manipulate data. This tier might also validate user input.
This tier consists of Sybase products from the "tools" layer, such as PowerBuilder or
Optima++.
The second tier (or middle tier) can enforce business rules and referential integrity
across all components of the third tier, supports global distributed transaction
management, and supports service mapping similar to a gateway application. This tier is
implemented as an intermediate server. It consists of Sybase products from the
"middleware" layer, such as OmniCONNECT or Open Server.
The third tier is a back-end server that handles data integrity and local transaction
branches. It has local responsibility for controlled resources, which are often database
systems. This tier consists of Sybase products from the "database" layer, such as SQL
Server, Sybase MPP, Sybase IQ, and SQL Anywhere.
Three-tier architecture gives the application complete independence with respect to both the
front-end tool and the back-end datastore and makes it easy to extend database functionality.
Many MIS developers find the three-tier construct essential.
In environments that do not support a three-tier topology, developers must integrate business
rules either in the front-end tool or the back-end datastore. Business rules can be integrated with
the back-end datastore by programming them in stored procedures or a trigger, a special kind of
stored procedure that automatically executes whenever data is inserted, updated, or deleted in the
columns with which the trigger is associated. Programming business rules in triggers results in
dependence on the datastore, so if business rules change, the database might need to be
reoptimized.
Middleware has historically been proprietary. Note also subtle differences in SQL and
how it is implemented in various DBMS.
How can a single client access multiple DBMS servers with minimal changes ?
ODBC is middleware software that can connect a client to multiple servers from different
vendors.
ODBC has two main portions that reside on the client: A Driver Manager and one or
more DBMS drivers.
The Driver Manager presents a uniform interface to all clients. This consists of a set of
function calls to query, update and manipulate data on a server
A DBMS Driver is typically supplied by the individual DBMS vendor and contains
routines to convert requests from the Driver Manager into commands the specific DBMS
understands.
Try this: Visit several DBMS vendor's web sites and see if they offer an ODBC driver
that can be downloaded to your PC.
Example of the use of Open DataBase Connectivity (ODBC)
ODBC was designed to allow application developers to decide between using the least common
denominator of functionality across DBMSs or exploiting the individual capabilities of specific
DBMSs.
ODBC defines a standard SQL grammar and set of function calls that are based upon the SAG
CLI specification, called the core grammar and core functions, respectively. If an application
developer chooses only to use the core functionality, they need not write any additional code to
check for specific capabilities of a driver.
Establish a connection with a data source, execute SQL statements, and retrieve results.
Receive standard error messages.
Provide a standard logon interface to the end user.
Use a standard set of data types defined by ODBC.
Use a standard SQL grammar defined by ODBC.
ODBC also defines an extended SQL grammar and set of extended functions to provide
application developers with a standard way to exploit advanced capabilities of a DBMS. In
addition to the above features, ODBC includes a set of extensions that provide enhanced
performance and increased power through the following features:
Table 1: Sauces
Table 2: State
To get started, let's write a simple script that extracts all the data from the database and writes
them out in a table. The first thing to do, as when using any Perl module, is to tell the script that
we want to use the module.
Next, we write the SQL to extract the data (the capitalization is for stylistic reasons):
$db->Sql("SELECT * FROM Sauces");
and then the loop to fetch the data, one row at a time:
while ($db->FetchRow()) {
...
}
Inside the while loop we actually get the data. In Win32::ODBC, there are two actions, one to
fetch the row, and one to get the data that was fetched. There are also two ways to get the fetched
data, Data() and DataHash(). The former returns the data into an array, in the order it was
selected in the SQL statement. The latter returns the data into a hash, in the form
'$hash{FieldName} = DataValue'. If you select all fields using the "*" wildcard, as we did, then
the field order that the data comes back in is undefined, so using Data() might not make sense.
We'll use DataHash(). Finally, we close the ODBC handle before the end of the program.
Putting it all together, the script should look something like the following:
$db->Close();
Transactions
Some ODBC drivers support transactions, with commits and rollbacks (see Data Sources to find
out how to determine if your driver supports this). Sometime after connecting (usually
immediately after, but it depends on your logic flow) you can set the AutoCommit option off,
and then rollback or commit depending upon program flow:
$db->SetConnectOption('SQL_AUTOCOMMIT', 'SQL_AUTOCOMMIT_OFF');
...
if ($fatal_error) {
$db->Transact('SQL_ROLLBACK');
die "Error - rolling back\n";
}
...
$db->Transact('SQL_COMMIT');
Data Sources
Sometimes you don't know ahead of time which database you need to connect to. You can query
the ODBC Manager and get a list:
print HTML "<SELECT NAME="DataSources" SIZE=1>\n";
my(%dsn, $key) = Win32::ODBC::DataSources();
foreach $key (sort keys %dsn) {
print HTML "<OPTION>$key\n";
}
print HTML "</SELECT>\n";
This will produce a box with all of the data sources listed. But suppose you knew you only
wanted Oracle databases. The value of the returned hash contains the name of the driver, so you
could filter them:
my(%dsn, $key) = Win32::ODBC::DataSources();
foreach $key (sort keys %dsn) {
print HTML "<OPTION>$key\n" if $dsn{$key} =~ /Oracle/;
}
Once you have connected to a driver, you can query it to see if it can handle a specific ODBC
API function, such as transactions:
my(%data) = $db->GetFunctions($db->SQL_API_SQLTRANSACT);
my($transOK) = $data{$db->SQL_API_SQLTRANSAC};
$db->SetConnectOption('SQL_AUTOCOMMIT', 'SQL_AUTOCOMMIT_OFF')
if ($transOK);
or you could query the connection for things like the database name and version:
my($db_ver) = $db->GetInfo($db->SQL_DBMS_VER);
my($db_name) = $db->GetInfo($db->SQL_DBMS_NAME);
High-level ODBC
IBM DB2
Microsoft Access, MS Excel, MS Foxpro, MS Visual FoxPro
Borland dBase and Paradox
Text files
Oracle 8
MS SQL Server
Sybase System 11
To add more drivers, download or install the ODBC driver from the database
manufacturer. The ODBC driver will then appear on this list.
Clicking on the User DSN tab shows those data sources that have been defined for this
user.