Just Logic/SQL Relational Database Management System

C program example using Just Logic/SQL C API

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


The C API is a simple, yet efficient, interface to the database engine. It provides the full functionality of SQL. Contrary to other systems, the C API is not just the C interface developped for the Precompiler with unfriendly calls more suitable for machine-generated code. It was designed to be easy to use by programmers.

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_customers_by_name ()
{
   /* sql statement pointer variable */
   sql *customers;

   /* print the title */
   printf ("name:                id:        address:\n");

   /* allocate new sql statement */
   customers = sql_malloc ();

   /* prepare sql statement */
   sql_prepare (customers, "select name, customer_id, address from customer order by name");
   check_error (customers);

   /* open the cursor */
   sql_open_cursor (customers, 0);
   check_error (customers);

   for (;;)
   {  /* fetch next row */
      sql_fetch_next (customers, customer_name, customer_id, customer_address);

      /* check end of rows */
      if (sql_status (customers) == SQLEND)
         break;

      /* check any other error */
      check_error (customers);

      /* print name, id, and address */
      printf ( "%-20.20s", customer_name);
      printf (" %-10.10s", customer_id);
      printf (" %-20.20s\n", customer_address);
   }


   /* close the cursor */
   sql_close_cursor (customers);
   check_error (customers);

   /* free sql statement */
   sql_free (customers);
}

void check_error (sql *sql)
struct sql *sql;
{
   /* error handling */

   if (sql_status (sql) < 0)
   {  printf ("\nerror number %i found\n", sql_status (sql));
      printf ("%s\n", sql_return_error (sql));
      exit (1);
   }
}

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