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++ method that displays the customer table, ordered by name:
void display_customers_by_name (void) { SQL customers; /* print the title */ printf ("name: id: address:\n"); /* select rows in the database */ customers = "select name, customer_id, address from customer order by name"; check_error (customers); /* open the cursor */ customers.open_cursor(); check_error (customers); for (;;) { /* fetch the next row */ customers.fetch_next (customer_name, customer_id, customer_address); /* check end of rows */ if (customers.status() == SQLEND) break; /* check all other errors */ 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 cursor */ customers.close_cursor(); check_error (customers); } void check_error (SQL &sql) { /* error handling */ if(sql.status() < 0) { printf ("\nerror number %i found\n", sql.status()); printf ("%s\n", sql.return_error ()); exit (1); } }
email: sales@justlogic.com
Last modification: 4/96