(By the way, the term "precompiler" that is used in database terminology has no relation with C precompilers that are part of C compilers and that handle the "#include", "#if", etc. in C programs.)
Here is a short example of program code.
Let's suppose that we have a table named "customer":
Id | Name | Address |
---|---|---|
A0001 |
Johnson, Andy |
21 Sunset Boulevard |
B0001 |
Smith, Martha |
332 12th Ave. |
A0002 |
Clark, Don |
54 Arlington Dr. |
... |
... |
... |
Here is a C function that displays the customer table, ordered by name:
void display_customer () { /* declare a cursor, and it's SQL statement */ EXEC SQL DECLARE customer_cursor CURSOR FOR select customer_id, name, address from customer order by customer_id; /* print the title */ printf ("name: id: address:\n"); /* tell the precompiler what to do in case of exception */ EXEC SQL whenever sqlerror goto end; EXEC SQL whenever sqlwarning continue; EXEC SQL whenever not found goto end; /* open the cursor */ EXEC SQL OPEN customer_cursor; for (;;) { /* fetch next row */ EXEC SQL fetch customer_cursor into :customer_name, :customer_id, :customer_address; /* print name, id and address */ printf ( "%-20.20s", customer_name); printf (" %-10.10s", customer_id); printf (" %-20.20s\n", customer_address); } end: EXEC SQL whenever sqlerror continue; /* close the cursor */ EXEC SQL close customer_name_list_cursor; }
email: sales@justlogic.com
Last modification: 4/96