















































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
Database for education CHAPTER 3
Typology: Summaries
1 / 55
This page cannot be seen from the preview
Don't miss anything!
















































accomplished through software programs that
implement database applications.
purpose programming language such as Java, C/C+
+/C#, COBOL, or some other programming
language.
JavaScript, are also being used for programming of
database access within Web applications.
is a very broad topic.
II. Database Programming Approaches
(contd.)
Several techniques exist for including database interactions in
application programs. The main approaches for database
programming are the following:
1. Embedded commands :
programming language (host language). For example, the prefix for
embedded SQL is the string EXEC SQL, which precedes all SQL
commands in a host language program.
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. This technique is generally referred to as
embedded SQL.
II. Database Programming Approaches
(contd.)
common, since many applications are already
written in general-purpose programming languages
but require some database access. The third
approach is more appropriate for applications that
have intensive database interaction.
approaches is impedance mismatch , which does not
occur in the third approach.
II. Database Programming Approaches
(contd.)
IV. Embedded SQL
IV. Embedded SQL (contd.)
IV. Embedded SQL (contd.)
loop = 1;
while (loop) {
prompt (“Enter SSN: “, ssn);
EXEC SQL
select FNAME, LNAME, ADDRESS, SALARY
into :fname, :lname, :address, :salary
from EMPLOYEE where SSN == :ssn;
if (SQLCODE == 0) printf(fname, …);
else printf(“SSN does not exist: “, ssn);
prompt(“More SSN? (1=yes, 0=no): “, loop);
END-EXEC
}
Note: The INTO clause can be used in this way only
when the query result is a single record;if multiple
records are retrieved, an error will be generated
16
IV. Embedded SQL (contd.)
The SQL types INTEGER, SMALLINT, REAL, and
DOUBLE are mapped to the C types long, short, float, and
double, respectively.
Fixed-length and varying-length strings (CHAR[i],
VARCHAR[i]) in SQL can be mapped to arrays of
characters (char [i+1], varchar [i+1]) in C that are one
character longer than the SQL type because strings in C
are terminated by a NULL character (\0),which is not part of
the character string itself.
Although varchar is not a standard C data type, it is
permitted when C is used for SQL database programming.
IV. Embedded SQL (contd.)
Note: communication variables:
SQLCODE == 0 : the statement was executed successfully
SQLCODE > 0 : no more data (records) are available in a
query result
SQLCODE < 0 : some error has occurred
SQLSTATE: a string of five characters
SQLSTATE ==‘00000’: no error or exception
other values indicate various errors or exceptions. For
Example, SQLSTATE ==‘02000’indicates ‘no more data’
it is generally better to use SQLSTATE because this
makes error handling in the application programs
independent of a particular DBMS.
IV. Embedded SQL (contd.)
In general, an SQL query can retrieve many tuples. In that
case, the C program will typically go through the retrieved
tuples and process them one at a time. The concept of a
cursor is used.
A cursor (iterator) is needed to process multiple tuples
OPEN
fetches its result.
FETCH command move the cursor to the next tuple
CLOSE CURSOR indicates that the processing of query
results has been completed
IV. Embedded SQL (contd.)