riyadh philanthropic society for science prince sultan college for woman

9
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems (Chapter 9: Introduction to SQL Programming Techniques)

Upload: nanda

Post on 06-Jan-2016

16 views

Category:

Documents


0 download

DESCRIPTION

Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems (Chapter 9: Introduction to SQL Programming Techniques). Outline Database Programming Approaches to Database Programming. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Riyadh Philanthropic Society For Science

Prince Sultan College For WomanDept. of Computer & Information Sciences

CS 340Introduction to Database Systems

(Chapter 9: Introduction to SQL Programming Techniques)

Page 2: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Chapter 9: Introduction to SQL Programming Techniques 1

Outline

• Database Programming• Approaches to Database Programming

Page 3: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Chapter 9: Introduction to SQL Programming Techniques

Database Programming

• Objective: to access a database from an application program (as opposed to interactive interfaces).

• Why?

• An interactive interface is convenient but not sufficient. (e.g. SQLPLUS)

• A majority of database operations are made through application programs (nowadays through web applications).

2

Page 4: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Chapter 9: Introduction to SQL Programming Techniques

Approaches to Database Programming

Embedding Database Commands:

• Most SQL statements can be embedded in a general-purpose host programming language such as C and Java.

• An embedded SQL statement is distinguished from the host language statements by EXEC SQL and a matching END-EXEC (or semicolon).

• A precompiler (preprocessor) first scans the source program code to

identify database statements and extract them for processing by the DBMS.

• They are replaced in the program by function calls to the DBMS- generated code. 3

Page 5: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Chapter 9: Introduction to SQL Programming Techniques

Approaches to Database Programming

Using a Library of Database Functions:

• A library of functions is made available to the host programming language for database calls.

• The actual database query and update commands, and any other necessary information, are included as parameters in the function calls.

• This approach provides what is known as an API for accessing a database from application programs.

4

Page 6: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Chapter 9: Introduction to SQL Programming Techniques

Approaches to Database Programming

Designing a Brand-New Language:

• A database programming language s designed from scratch to be compatible with the database model and query language.

• Minimizes impedance mismatch.

• E.g. ORACLE’s PL/SQL.

5

Page 7: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Chapter 9: Introduction to SQL Programming Techniques

A C Program Segment with Embedded SQL

loop = 1;while (loop) { prompt (”Enter a Social Security Number: ", ssn); EXEC SQL select FNAME, MINIT, LNAME, ADDRESS, SALARY into :fname, :minit, :lname, :address, :salary from EMPLOYEE where SSN=:ssn; if (SQLCODE == 0) printf (fname, minit, lname, address, salary) else printf("Social Security Number does not exist: ”, ssn); prompt("More Social Security Numbers (1 = Yes, 0 = No): ”, loop);}

6

Page 8: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Chapter 9: Introduction to SQL Programming Techniques

Embedded Versus Dynamic SQL

• Embedded SQL: including hard-coded SQL statements in a program

written in another language such as C or Java.

• Dynamic SQL: ability for an application program to generate SQL code on the fly, as the application is running.

7

Page 9: Riyadh Philanthropic Society For Science Prince Sultan College For Woman

Chapter 9: Introduction to SQL Programming Techniques

Database Programming with Function Calls

• The use of function calls is a more dynamic approach for database programming than embedded SQL.

• One dynamic database technique is the dynamic SQL.

• Another technique uses a library of functions (API) to access the database.

• Two function call interfaces are: SQL/CLI & JDBC.

8