Define thread-safe variables (UNIX)

When you specify the -thread command-line option to esql, the preprocessor passes the IFX_THREAD definition to the C compiler. The IFX_THREAD definition tells the C compiler to create thread-scoped variables for variables that are global in non-thread-safe code.

For example, when the C compiler includes the sqlca.h file with IFX_THREAD set, it defines thread-scoped variables for the status variables: SQLCODE, SQLSTATE, and the sqlca structure. The thread-scoped versions of status variables are macros that map the global status variables to thread-safe function calls that obtain thread-specific status information.

The following figure shows an excerpt from the sqlca.h file with the thread-scoped definitions for status variables.
Figure 1: Declaration of thread-scoped status variables
;

extern struct sqlca_s sqlca;

extern int4 SQLCODE;

extern char SQLSTATE[];
#else /* IFX_THREAD */
extern int4 * ifx_sqlcode();
extern struct sqlca_s * ifx_sqlca();
#define SQLCODE (*(ifx_sqlcode()))
#define SQLSTATE ((char *)(ifx_sqlstate()))
#define sqlca (*(ifx_sqlca()))
#endif /* IFX_THREAD */