The SQLCODE Variable

The most important and widely used field of the SQLCA data structure is the SQLCODE variable. Each time that SQL Server runs an Embedded SQL statement, it sets the value of the SQLCODE variable to indicate whether or not the last Embedded SQL statement completed successfully. A value of 0 indicates that the last Embedded SQL statement was successful. Values other than 0 indicate warnings or errors.

To use SQLCODE in your program, you can either declare it explicitly as long SQLCODE; or leave it undeclared and have the precompiler generate a declaration. However, the precompiler will only generate a declaration in a source module that contains a main() or a WinMain() function.

The preprocessor automatically inserts a definition of


extern long SQLCODE;

in all .SQC modules, so the actual definition of SQLCODE should only occur in one module. If your project does not include a .SQC file that includes a main() or WinMain() function, you must explicitly declare SQLCODE in one of your modules. Explicit SQLCODE declarations can occur either inside or outside of a host variable declaration block.

For more information about SQLCODE, see Appendix A, "Advanced Programming."