#!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # esqlutil.news # # This shell archive created: Thu Mar 5 11:54:33 EST 1992 # echo "Extracting file esqlutil.news" sed -e 's/^X//' <<\SHAR_EOF > esqlutil.news XFrom: markj@informix.com (Mark Jeske(Chicago Consultan)t) XNewsgroups: comp.databases.informix XMessage-ID: <1992Mar5.051017.17231@informix.com> XDate: 5 Mar 92 05:10:17 GMT XReferences: <1992Mar3.233906.8757@dbsm.oz.au> XSender: news@informix.com (Usenet News) XOrganization: Informix Software, Inc. XSubject: Re: INFORMIX schemas -> C header files XX-Informix-List-Id: X XIn article <1992Mar3.233906.8757@dbsm.oz.au> ralph@thor (Ralph Michael Gyoery) writes: X>Does anyone know of a public domain utility that will generate for me X>C header files from an INFORMIX database schema?. X XThe following is now posted into the public domain. Please feel Xfree to email me any comments or bugs. This program will generate Xan esql/c template program with c structures for the database and Xtables listed. For example, X X $ esqlutil stores items customers X XAll output goes to standard out. X Xmark X X X/* X esqlutil.ec X X Generate the beginning of an esql/c program. Structures for the X tables specified will be generated as well as the neccesary include X files and an error checking function. X X cc -o esqlutil esqlutil.ec X X Author: Mark Jeske (Informix) markj@informix.com X Date: 11-19-91 X*/ X X X#include X$include sqlca; X$include sqlda; X$include sqltypes; X X#define sqlerr() sqlerrln( __LINE__ ) X X$char dbname[20] ; X Xint ansi ; Xint numproccessed ; X Xchar *progtop[] = { X "#include \n\n", X "#define sqlerr() sqlerrln( __LINE__ )\n", X "\n\n", X 0 X} ; X Xchar *funcs[] = { X "/*\n", X " Checks global sqlca.sqlcode for errors. Displays error and exits.\n", X "*/\n", X "void sqlerrln( ln )\n", X "", X " int ln ; /* line # of caller */\n", X "{\n", X " char msg[160] ;\n", X "", X " if( sqlca.sqlcode ) {\n", X " fprintf( stderr,\n", X " \"sqlcode %ld, isam %ld line %d\\n\", \n", X " sqlca.sqlcode, sqlca.sqlerrd[1], ln ) ;\n", X " rgetmsg( sqlca.sqlcode, msg, sizeof(msg) ) ;\n", X " fprintf( stderr, \"%s\", msg ) ;\n", X " exit(1) ;\n", X " }\n", X "}\n", X "\n\n", X 0 X} ; X Xchar *ansiincl[] = { X "EXEC SQL include sqlca ;\n", X "EXEC SQL include sqlda ;\n", X "EXEC SQL include sqlstype ;\n", X "EXEC SQL include sqltypes ;\n", X "EXEC SQL include locator ;\n", X/* "EXEC SQL include decimal ;\n", */ X "EXEC SQL include datetime ;\n", X "\n\n", X 0 X} ; X Xchar *incl[] = { X "$include sqlca ;\n", X "$include sqlda ;\n", X "$include sqlstype ;\n", X "$include sqltypes ;\n", X "$include locator ;\n", X/* "$include decimal ;\n", */ X "$include datetime ;\n", X "\n\n", X 0 X} ; X Xchar *progbot[] = { X "main( argc, argv )\n\n", X " int argc ;\n", X " char **argv ;\n", X "{\n", X " printf( \"Hello world\\n\" ) ;\n", X " exit(0) ;\n", X "}\n", X 0 X} ; X X/* X Checks global sqlca.sqlcode for errors. Displays error and exits. X*/ Xvoid sqlerrln( ln ) X X int ln ; /* line # of caller */ X{ X char msg[160] ; X X if( sqlca.sqlcode ) { X fprintf( stderr, X "sqlcode %ld, isam %ld line %d\n", X sqlca.sqlcode, sqlca.sqlerrd[1], ln ) ; X rgetmsg( sqlca.sqlcode, msg, sizeof(msg) ) ; X fprintf( stderr, "%s", msg ) ; X exit(1) ; X } X} X Xrtrim( s ) X X char *s ; X{ X int i ; X X while( s[ i=strlen(s)-1 ] == ' ' ) X s[i] = '\0' ; X} X Xusage( s ) X X char *s ; X{ X fprintf( stderr, X "usage: %s [-a] dbname tblname ...\n\n", s ) ; X fprintf( stderr, X "-a Generate ansi sql definitions\n\n" ) ; X fprintf( stderr, X "Generate esql structure definitions for the indicated tables.\n" ) ; X fprintf( stderr, X "If no tables are listed generate structs for all tables in the db.\n" ) ; X fprintf( stderr, X "Information is written to standard output.\n" ) ; X exit( 1 ) ; X} X Xprocargs( argc, argv ) X X int argc ; X char **argv ; X{ X int first = 1 ; X int i ; X X if( argc < 2 ) usage( argv[0] ) ; X X for( i=1; i 99" ; X sqlerr() ; X X $declare c1 cursor for p2 ; X sqlerr() ; X X $open c1 ; X sqlerr() ; X X while( 1 ) { X $fetch c1 into $tbl ; X if( sqlca.sqlcode == 100 ) break ; X sqlerr() ; X onetable( tbl ) ; X } X X $close c1 ; X sqlerr() ; X} X X Xonetable( tbl ) X X char *tbl ; X{ X $char s[40] ; X int i ; X struct sqlda *udesc; X struct sqlvar_struct *col; X X rtrim( tbl ) ; X X ++numproccessed ; X X sprintf( s, "select * from %s", tbl ) ; X X $prepare p1 from $s; X sqlerr() ; X X $describe p1 into udesc; X sqlerr() ; X X if( ansi ) { X printf( "EXEC SQL BEGIN DECLARE SECTION\n" ) ; X printf( " struct %s_s {\n", tbl ) ; X } X else X printf( "$struct %s_s {\n", tbl ) ; X X for (col = udesc->sqlvar, i = 0; i < udesc->sqld; col++, i++) { X X printf( " " ) ; X if( ansi ) printf( " " ) ; X X switch( col->sqltype ) { X case SQLVCHAR: X case SQLCHAR: printf( "char " ) ; break ; X case SQLSERIAL: X case SQLDATE: X case SQLINT: printf( "long " ) ; break ; X case SQLSMINT: printf( "int " ) ; break ; X case SQLFLOAT: printf( "double " ) ; break ; X case SQLSMFLOAT: printf( "float " ) ; break ; X case SQLMONEY: X case SQLDECIMAL: printf( "dec_t " ) ; break ; X case SQLDTIME: printf( "dtime_t " ) ; break ; X case SQLTEXT: X case SQLBYTES: printf( "loc_t " ) ; break ; X case SQLINTERVAL: printf( "intrvl_t " ) ; break ; X default: printf( "??? " ) ; break ; X } X X printf( "%s", col->sqlname ) ; X if( col->sqltype == SQLCHAR ) printf( "[%d]", col->sqllen + 1 ) ; X X printf( " ;\n" ) ; X } X X if( ansi ) printf( " " ) ; X printf( "} %s_r ;\n", tbl ) ; X X if( ansi ) printf( "EXEC SQL END DECLARE SECTION\n" ) ; X printf( "\n" ) ; X} X X-- Xmark jeske (informix consulting) Xmark@infmx.com X708-699-5850 SHAR_EOF if [ `wc -c < esqlutil.news` -ne 6667 ] then echo "Lengths do not match -- Bad Copy of esqlutil.news" fi echo "Done."