Preprocessing the ESQL Source Files

After you write your ESQL source files, preprocess them using the SQL preprocessor (sqlcpp). The preprocessor creates a pure C source file for each ESQL source file that it processes.

NOTE: Complete this step only for ESQL source files that contain static and dynamic Progress/ESQL statements. Files that only contain calls to dynamic ESQL-LIB functions do not require preprocessing. However, you must ensure that any files you do not preprocess contain any necessary data declarations that the preprocessor provides.

As it generates output, the preprocessor:

Figure 1–5 and Figure 1–6 demonstrate the differences between C source files preprocessed without precompilation and with it. The bold code shows the ESQL-LIB function calls.

Preprocessing Without Precompilation

Figure 1–5 shows the fragment from Figure 1–4 after preprocessing without precompilation.

    while (1) /* loop until last customer record read */
    {
        /* EXEC SQL fetch x into :custnum,
                 :nam, :city, :state, :maxcred; */
        {
static char sqltxt[] = {’f’,’e’,’t’,’c’,’h’,’ ’,’x’,’ ’,’i’,’n’,’t’,’o’,’ 
’,’e’,’s’,’q’,’l’,’o’,’0’,’,’,’’,’e’,’s’,’q’,’l’,’o’,’1’,’,’,’,’e’,’s’,’q’’,
’l’,’o’,’2’,’,’,’’,’e’,’s’,’q’,’l’,’o’,’3’,’,’,’,’e’,’s’,’q’,’l’,’o’,’4’’,’.
’,0};
static char sqlfmt[] = {’4’,’i’,’3’,’0’,’s’,’2’,’0’,’s’,’3’,’s’,’4’,’i’,0};
static char *sqlv[6];
            sqlv[0] = (char *) &custnum;
            sqlv[1] = (char *) nam;
            sqlv[2] = (char *) city;
            sqlv[3] = (char *) state;
            sqlv[4] = (char *) &maxcred;
            sqlv[5] = (char *) 0;
            sqlcdbind(&SQLCODE, (char *)0);
            sqlfetch(sql0,(int) 0x08,sqltxt,sqlfmt,sqlv);
            if (SQLCODE == 100) goto done1;
            if (SQLCODE < 0) goto err;
        }
        printf("%-7d%-22s%-14s%-7s%8d\n",custnum, nam, city, state, maxcred);
        if (custnum > hicustnum - 3)
        {
            /* EXEC SQL delete from customer where current of x; */
            {
                sqlcdbind(&SQLCODE, (char *)0);
                sqldelrow(sql0,(int)0x010,"");
                if (SQLCODE == 100) goto done1;
                if (SQLCODE < 0) goto err;
            }
            printf("Record for customer %d deleted\n", custnum);
        }
    }
																						
.
																						
.
																						
. 

Figure 1–5: Preprocessed Source File Fragment (Not Precompiled)

Without precompilation, each ESQL-LIB function is passed either a character string that contains the text of the corresponding SQL statement (sqltxt in the figure) or a null string, depending on the function.

Preprocessing with Precompilation

Figure 1–6 shows the fragment in Figure 1–4 after preprocessing with precompilation. The bold code shows the ESQL-LIB function calls.

    while (1) /* loop until last customer record read */
    {
        /* EXEC SQL fetch x into :custnum,
                 :nam, :city, :state, :maxcred; */
        {
static char sqlfmt[] = {’4’,’i’,’3’,’0’,’s’,’2’,’0’,’s’,’3’,’s’,’4’,’i’,0};
static char *sqlv[6];
            sqlv[0] = (char *) &custnum;
            sqlv[1] = (char *) nam;
            sqlv[2] = (char *) city;
            sqlv[3] = (char *) state;
            sqlv[4] = (char *) &maxcred;
            sqlv[5] = (char *) 0;
            sqlcdbind(&SQLCODE, (char *)0);
            sqlfetch(sql0,(int) 0x0208,"0BCA34.p",sqlfmt,sqlv);
            if (SQLCODE == 100) goto done1;
            if (SQLCODE < 0) goto err;
        }
        printf("%-7d%-22s%-14s%-7s%8d\n",custnum, nam, city, state, maxcred);
        if (custnum > hicustnum - 3)
        {
            /* EXEC SQL delete from customer where current of x; */
            {
                sqlcdbind(&SQLCODE, (char *)0);
                sqldelrow(sql0,(int)0x0210,"AFAD67.p");
                if (SQLCODE == 100) goto done1;
                if (SQLCODE < 0) goto err;
            }
            printf("Record for customer %d deleted\n", custnum);
        }
    }
																						
.
																						
.
																						
. 

Figure 1–6: Preprocessed Source File Fragment (Precompiled)

With precompilation, the preprocessor passes the r-code filename created to execute the corresponding SQL statement to each ESQL-LIB function.

Working with Preprocessor Output

The preprocessor generates a C source file with the same name as the ESQL source file but with a different extension. (By convention, the ESQL source file extension is .cc, but can be any value subject to your operating system naming requirements.) For example, if you preprocess an ESQL source file named esqltest.cc, the preprocessor generates a C source file named esqltest.c.

Although you can view your preprocessed source file to understand how it works, do not modify it.

For more information on using the SQL preprocessor, see Building and Running ESQL Applications."


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095