Just Logic/SQL Relational Database Management System

C program example using the Just Logic/SQL C Precompiler

Home | Technical Features | Web-enabling option| Client-Server option | How to Order



All commercial relational databases use a precompiler to convert a program containing embedded SQL code into source code that can be compiled and linked. Such a precompiler interface lets you port programs written for another relational database system. Of course non standard code (such as error return codes) must be modified, but most code do not need to. It is worth noting that the Just Logic/SQL C API and C++ classes do not need a precompiler and directly use the native C or C++ code.

(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;
}

TopUp


Just Logic Technologies Inc.
P.O. Box 63050
40 Commerce St.,
Nun's Island, Qc, H3E 1V6
Canada

email: sales@justlogic.com

Last modification: 4/96