Database Reference
In-Depth Information
execution of the SQL statements; no other code in any programming language is
necessary. However, the results are displayed or printed only in certain standard
formats.
What if you are writing an application program with the necessary logic in a
programming language such as Visual Basic, C, C++, COBOL, Ada, and so on, and
want your program to access a relational database? SQL is the standard language
for relational database access. How can your application program interface with the
database using the facilities of SQL? The following two methods provide database
access to an application program.
Embedded SQL In this approach, SQL statements are included directly in
the source code of the application program. At the points in the application
program where database access is necessary, SQL statements are embedded into
the program. The application program directly accesses the database using SQL
statements. A special precompiler replaces the SQL statements in the application
programs written in a host programming language with database functions.
Figure 13-13 shows a sample program written in C with embedded SQL. Observe
how standard SQL statements are embedded at the appropriate points in the
program.
Application Programming Interface (API) In this alternative approach, the
application programmer is provided with a set of standard functions that can be
invoked or called from the application program. This type of call-level interface
allows the application program to access the database. These APIs enable the
application program to access the database as do the embedded SQL statements in
the other approach. However, this approach does not require any precompilation
of the program.
An initial function call in the application program establishes the connection to
the database. Then, at the point in the program where database access is required,
a call is made to the appropriate database function to process the relevant SQL
statements passed on in the call.
Figure 13-14 illustrates how an application program uses an SQL call-level
interface (CLI).
Although this approach does away with precompilation, unfortunately, each data-
base vendor's API is specific to that vendor's DBMS. This is the case even though
all the calls result in the execution of standard SQL statements. No standards insti-
tution has established a common interface. However, Microsoft's Open Database
Connectivity (ODBC), a SQL-based API, has become the industry standard.
QUERY PROCESSING
As you have seen, SQL provides a high-level data manipulation language to write
queries and obtain the desired data from a relational database. You construct a
query with SQL statements. You can either execute a query interactively or embed
a query in a host language for execution at appropriate points in the application
program. Query processing is a major consideration in the implementation of data-
base systems.
Search WWH ::




Custom Search