Code controls the user login procedure
Chapter 16: Using SQL within Applications | 337 |
---|
Of course, as you may expect, an SQL statement that suddenly appears in the middle of a C program can present a challenge for a compiler that isn’t expecting it. For that reason, programs containing embedded SQL are usu-ally passed through a preprocessor before being compiled or interpreted. The EXEC SQL directive warns the preprocessor of the imminent appearance of SQL code.
As an example of embedded SQL, look at a program written in Oracle’s Pro*C version of the C language. The program, which accesses a company’s EMPLOYEE table, prompts the user for an employee name and then displays that employee’s salary and commission. It then prompts the user for new salary and commission data — and updates the employee table with it:
338 | |||
---|---|---|---|
|
You don’t have to be an expert in C to understand the essence of what this program is doing (and how it intends to do it). Here’s a rundown of the order in which the statements execute:
1. SQL declares host variables.
7. SQL updates the database with the new values.
8. C then displays an Operation complete message.
|
---|