emb-pro emb-pro - 1 year ago 38
C Question

How can I simply convert an ESQL/C file to a C file? (Embedded- SQL/C file to C file)?

I'm working on a migration project. I need to convert ESQL/C files which have .ec extension into c file on gcc. I know that ESQL/C program will create a .c file. But How can I get that?

FYI : I'm working on IBM Informix server.

Answer Source

TL;DR — For an Informix .ec file compiled with the esql program (script), you can use the -e option to 'Preprocess only, no compilation or linking'.

esql -e esqlcode.ec

This produces esqlcode.c from esqlcode.ec. (Ignore my previous comment about 'sufficiently recent'; you won't be using a version that isn't sufficiently recent — my memory is failing once more.)

The esql script traditionally left the intermediate .c file lying around. My ESQL/C make rules all remove the generated .c file as a separate post-compilation step:

.ec.o:
    ${ESQL} ${ESQLFLAGS} -c $*.ec
    ${RM_F} $*.c

with appropriate definitions of suffixes, macros, etc.

The esql command

Using the Informix esql compiler (script), you can run it with no options to get a help message like this (try not to be scared: there's actually the usages for two commands):

Usage: esql [-e] [-thread] [-glu] [esqlcargs] [-cc] [otherargs] [-o outfile]
            [-cp] [-onlycp] [-np] [-nup]
            [-libs] esqlfile.ec [othersrc.c...] [otherobj.o...] [-lyourlib...]

        -e         Preprocess only, no compilation or linking
        -thread    Multithread support
        -glu       Enable GLU (GLS for Unicode)
        -esqlcargs: esqlc arguments (-g, -G, -nln, -Ipathname, -nowarn, -V, -ansi,
                                    -xopen, -local, -log, -EDname, -EUname,
                                    -icheck
        -cc        Arguments after cc go to c compiler only
        otherargs: Other arguments are passed to cc
        -o         Next argument is program name
        -libs      Display the list of libraries used by esql at link time.
        -cp        Run C preprocessor before esqlc
        -onlycp    Run only the C preprocessor, no esqlc, compilation or linking
        -np        No protection of SQL keywords in SQL statements
        -nup       No unprotection of SQL keywords, forces -onlycp


Usage: esqlc [-thread] [-gG] [-nln] [-Ipathname] [-nowarn] [-V] [-ansi]
             [-static] [-xopen] [-local] [-log file] [-EDname[=val]] [-EUname]
             [-icheck] [-keepccomment] [-version] esqlfile.ec
         -thread     Multithread support
         -g          Number every line (debugging purposes)
         -G          No line number (debugging purposes; same as -nln)
         -nln        No line number (debugging purposes; same as -G)
         -Ipathname  Add pathname to include file search path
         -nowarn     Do not print warnings
         -static     Link with static libraries
         -keepccomment Allow C style comments in SQL statements.
         -version    Displays build and version information.
         -V          Print preprocessor version information
         -ansi       Perform ANSI checking
         -xopen      Perform XOPEN checking
         -local      Make cursor/statement ids local to the file
         -log file   Log error and warning messages in file
         -EDname     Define specified preprocessor name flag
          [=val]     and set it equal to 'val'
         -EUname     Undefine specified preprocessor name flag
         -icheck     Check for indicator variables

The usage for esqlc is for the 'real' preprocessor, $INFORMIXDIR/lib/esqlc. The usage for esql is for the esql script itself — which is what you are primarily using. The esqlcargs in the esql usage are the ones that are listed for esqlc — they're passed through by the script to the program.

This output is from ESQL/C 4.10 associated with Informix 12.10. I won't bore you with a history of the ESQL/C version numbers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download