Guide to demo1.ec File The sample ESQL/C program, demo1.ec, uses a static SELECT statement. This means that at compile time the program can obtain all of the information that it needs to run the SELECT statement. The demo1.ec program reads from the customer table in the stores7 database the first and last names of customers whose last name is a value less than 'C'. Two host variables (:fname and :lname) hold the data from the customer table. A cursor manages the rows that the database server retrieves from the table. The database server fetches the rows one at a time. Your program then prints the names to standard output. 1 #include <stdio.h>
'C'
00
02
Lines 25 to 26 If the class code in SQLSTATE is any value except "02", then this printf() statement displays the SQLSTATE value for the user. This output is useful in the event of a runtime error. Lines 27 to 28 The CLOSE and FREE statements free the resources that the database server had allocated for the cursor. The cursor is no longer usable. 29 EXEC SQL disconnect current; 30 printf("\nDEMO1 Sample Program over.\n\n"); 31 } Lines 29 to 31 The DISCONNECT CURRENT statement closes the database and terminates the current connection to a database server. The final printf() tells the user that the program is over. The right brace (}) on line 31 marks the end of the main() function and of the program.