riyadh philanthropic society for science prince sultan college for woman
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 PresentationTRANSCRIPT
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)
Chapter 9: Introduction to SQL Programming Techniques 1
Outline
• Database Programming• Approaches to Database Programming
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
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
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
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
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
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
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