6. Embedded SQL for BASIC : The SQL Communications Area : The Include SQLCA Statement
 
Share this page                  
The Include SQLCA Statement
You should issue the include sqlca statement in your main program module as well as in each subprogram of your BASIC file that includes Embedded SQL statements. If the file is made up of one main program and a few subprograms, include sqlca should be the first Embedded SQL statement in each of the program units. For example:
10     ! main program
     exec sql include sqlca
     . . .
     end ! main

100     sub emp_sub
     exec sql include sqlca
     . . .
     end sub ! Emp_sub

200 function integer emp_func
     exec sql include sqlca
     . . .
     end func ! Emp_Func
The include sqlca statement instructs the preprocessor to generate code to call Ingres runtime libraries. It generates a BASIC %include statement to make all the calls generated by the preprocessor acceptable to the compiler. The include sqlca statement also generates a BASIC %include directive to define the SQLCA (SQL Communications Area) common block, which is used for error handling.
Whether or not you intend to use the SQLCA for error handling, you must issue an include sqlca statement in each program unit containing Embedded SQL statements. If you do not, the BASIC compiler may complain about undeclared functions. Furthermore, the program will abort at runtime because program memory will be overwritten. This occurs because, with no explicit declaration of the SQLCA using the include sqlca statement, the BASIC compiler implicitly declares all references (including preprocessor-generated references) to the SQLCA as the default data type (the default set by the BASIC environment or by the system). Therefore, to help detect runtime errors due to missing include sqlca statements, you may want to use the qualifier type_default=explicit with the BASIC compiler command. By doing so, you can ensure that the compiler generates a warning upon encountering a reference to an undeclared SQLCA.