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); } }
email: sales@justlogic.com
Last modification: 4/96