
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to database systems, focusing on database architecture, programming, and interfaces. It covers centralized, two-tier, and three-tier client-server architectures, database programming concepts, and interfacing sql with other programming languages. Examples using c, perl, php, and java.
Typology: Lab Reports
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























2/25/
Luke Huan Univ. of Kansas
Sample codes of embedded SQL programming andAPIs with {C, Perl, JAVA, PHP} are available at classwebpage
Next Monday (March 9
th^ ), we will have class at 1005C
for a lab session
2/25/
Luke Huan Univ. of Kansas
Centralized Architectures
Centralized DBMS: combines everything into singlesystem including- DBMS software, hardware,application programs and user interface processingsoftware.
2/25/
Luke Huan Univ. of Kansas
Two Tier Client-Server Architectures
zServer: provides databasequery and transactionservices to client machines zClient: provideappropriate interfaces toserver.
2/25/
Luke Huan Univ. of Kansas
Three (n) Tier Client-Server Architecture
WAN
Clients Webserver ApplicationserversDatabaseservers
z^
The intermediate layer iscalled Application Serveror Web Server, or both: z^
Stores the webconnectivity software andbusiness logic forapplications z^
Acts like a conduit forsending partiallyprocessed data betweenthe database server andthe client. z^
Additional Features z^
2/25/
Luke Huan Univ. of Kansas
Pros and cons of SQL z^
Very high-level, possible to optimize z^
Specifically designed for databases and is called
data
sublanguage z^
Not intended for general-purpose computation, which isusually done by a
host language
Solutions z^
Augment SQL with constructs from general-purposeprogramming languages (SQL/PSM) z^
Use SQL together with general-purpose programminglanguages z^
Database APIs, embedded SQL, JDBC, etc.
2/25/
Luke Huan Univ. of Kansas
John went to his office. He has a JAVA program, whichconnects to a SqlServer database in his company’sintranet. He use the program to retrieve data and printout reports for his business partner. z^
Client-server model z^
Use APIs provided by SqlServer to access the database z^
Java supports SqlServer API using JDBC
2/25/
Luke Huan Univ. of Kansas
After job, John went to youtube.com, searched for avideo of Thomas train for his children, and downloadedone z^
Client-mediate level-sever model z^
“SQL experience a plus” from a job ad linked from youtube’s web site.
WAN
2/25/
Luke Huan Univ. of Kansas
A client (user interface, web server, application server)opens a connection to a database server
A client interact with the database server to performquery, update, or other operations.
A client terminate the connection
2/25/
Luke Huan Univ. of Kansas
z^
PSM = Persistent Stored Modules z^
CREATE PROCEDURE
proc_name
(
parameter_declarations
) local_declarationsprocedure_body
;
z^
CREATE FUNCTION
func_name
(
parameter_declarations
) RETURNS
return_type
local_declarationsprocedure_body
;
z^
CALL
proc_name
(
parameters
);
z^
Inside procedure body: SET
variable
= CALL
func_name
(
parameters
);
2/25/
Luke Huan Univ. of Kansas
Fetch the first result row: OPEN studentCursor;FETCH FROM studentCursor INTO thisGPA;--
Loop over all result rows: WHILE noMoreRows <> 1 DO
IF thisGPA > newMaxGPA THEN
Enforce
newMaxGPA
UPDATE Student SET Student.GPA = newMaxGPAWHERE CURRENT OF studentCursor;--
Update count: SET rowsUpdated = rowsUpdated + 1; END IF;--
Fetch the next result row: FETCH FROM studentCursor INTO thisGPA; END WHILE;CLOSE studentCursor;
2/25/
Luke Huan Univ. of Kansas
Assignment using scalar query results z^
SELECT INTO
Other loop constructs z^
FOR
,^ REPEAT
UNTIL
,^ LOOP
Flow control z^
GOTO
Exceptions z^
SIGNAL
,^ RESIGNAL
… z^
For more pgSQL-specific information, check out itsmanual athttp://www.postgresql.org/docs/8.2/interactive/plpgsql.html
2/25/
Luke Huan Univ. of Kansas
z^
// Connect to the database $dbconn = pg_connect("host= wozniak.eecs.ku.edu port=5432dbname=jhuan user=jhuan password=zzzzz") ordie('Could not connect: '. pg_last_error()); z^//create a table $query = "CREATE TABLE regiusers ( name varchar(50),passwd
varchar(50) )";
z^
// Execute the Query $query = pg_query($query);… (see next page) z^
// Closing connection pg_close($dbconn); z^
2/25/
Luke Huan Univ. of Kansas
z^
//performing update $ldata['name'] = 'a2';
$ldata['passwd'] = 'b2';
$res = pg_insert($dbconn, "regiusers", $ldata); z^
// Performing SQL query $query = 'SELECT * FROM regiusers';$result = pg_query($query) or die('Query failed: ' .pg_last_error()); z^
// analyzing results while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)){
foreach ($line as $col_value) {
statement; } z^
// Free resultset pg_free_result($result);