Includes an external file in an Embedded SQL source file.
exec sql include "filename";
The name of the file to be included in the Embedded SQL source file containing this statement.
common.h:
/* This file contains definitions and
** declarations used in the file getinfo.c.
*/
#include <stdio.h>
#include “./common.h”
void err_handler();
void warning_handler();
exec sql include sqlca;
{
exec sql begin declare section;
CS_CHAR username[33], password[33], date[33];
exec sql end declare section;
exec sql whenever sqlerror call err_handler();
exec sql whenever sqlwarning call warning_handler();
exec sql whenever not found continue;
/*
** Copy the user name and password defined in common.h to
** the variables decalred for them in the declare section.
*/
strcpy (username, USER);
strcpy(password, PASSWORD);
printf(“Today’s date: %s\n”, date);
...
}
void err_handler()
{
...
}
void warning_handler()
{
...
}
/* common.h */
#define USER “sa”
#define PASSWORD ““
============================================================
exec sql begin declare section;
char global_username[100];
char global_password[100];
exec sql end declare section;
getinfo.c
#include <common.h>
printf(“uid?\n”);
gets(global_username);
printf(“password?\n”);
gets(global_password);
do_connect.c
exec sql include “common.h”;
exec sql connect :global_username
identified by :global_password;
The Embedded SQL precompiler processes the included file as though it were part of the Embedded SQL source file, recognizing all declare sections and SQL statements. The Embedded SQL precompiler writes the resulting host language source code into the generated file.
Use the include path precompiler command line option to specify the directories to be searched for any included files. Refer to the Open Client/Server Programmer’s Supplement for more information on precompiler command line options.
Included files can be nested up to a maximum depth of 32 files.
The include "filename" statement can be used anywhere.
declare section