🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
11 messages
11 total messages Started by NCC Network Fri, 12 Apr 1996 02:19
C compiler Error on EXEC SQL
#3173
Author: NCC Network
Date: Fri, 12 Apr 1996 02:19
309 lines
8832 bytes
Hi

I post this for my friend who has no access to the internet and would like to
get help from C experts in the Net. She has a C program left over from a guy
left the company. The C source code is included below as well as the compiler
error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
to be a standard C. 

I would appreciate any hints or comments.
Thanks in advances.

Dennis. 


-------------------- ERROR MESSAGE ----------------------------------------

I tried to compile "monthly_addup.c" and get the following error message:

(Bundled) cc:  line 4: error 1000: Unexpected symbol: "SQL".
(Bundled) cc:  line 4: error 1000: Unexpected symbol: ";".
(Bundled) cc:  line 12: error 1000: Unexpected symbol: "SQL".
(Bundled) cc:  line 12: error 1000: Unexpected symbol: "DECLARE".
(Bundled) cc:  line 24: error 1000: Unexpected symbol: "SQL".
(Bundled) cc:  line 24: error 1000: Unexpected symbol: "DECLARE".
(Bundled) cc:  line 50: error 1000: Unexpected symbol: "SQL".
(Bundled) cc:  line 50: error 1000: Unexpected symbol: "'revenue'".
...............................

----------------------------- C program ----------------------------
This C program is originally named as "monthly_addup.ec".  It's not like
the normal C program that ends with ".c".  
Here is the source:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
EXEC SQL include decimal.h;

/* Global variables */
char month[3];              /* mm plus null zero to end string */
char year[5];               /* yyyy plus null zero to end string */
char month_name[10];        /* ex: September plus null zero to end string */

EXEC SQL BEGIN DECLARE SECTION;
     long   per_id_revn_de;
     long   loc_id_revn_de;
     long   ind_id_revn_de;
     long   ct_id_revn_de;
     long   fee_id_revn_de;
     long   dist_id_revn_de;
     dec_t  amt_paid_revn_de;
     dec_t  amt_credit_revn_de;
     dec_t  amt_due_revn_de;
     long   trans_count_p_revn_de;
     long   trans_count_c_revn_de;
     long   trans_count_d_revn_de;
EXEC SQL END DECLARE SECTION;

EXEC SQL BEGIN DECLARE SECTION;
     long per_id_perd_de;
     char per_level_perd_de[16];     /* additional byte for null zero */
     char per_desc_perd_de[16];
     char week_perd_de[11];
     char month_perd_de[11];
     char quarter_perd_de[11];
     char year_perd_de[5];
     char fiscal_year_perd_de[6];
     int  sequence_perd_de;
     int  per_num_perd_de;
     char cur_flag_perd_de;
EXEC SQL END DECLARE SECTION; 

/* Main Program */
main(argc,argv)       
int argc;
char *argv[];
{

long per_id_for_month;
int  num_recs_created = 0;
char mmyyyy[7];
char filename[40];
double amt_paid, amt_credit, amt_due;
int x;     
FILE *fptr;

if (argc == 3)        
   ;
else
   {
   printf("Incorrect number of arguements\n");
   printf("Usage: %s [mmyyyy] [output file and path] \n",argv[0]);
   exit(8);   
   }

if (strlen(argv[2]) > 40) 
   {
   printf("Path and filename arguement too long. ");
   printf("Must not exceed 40 characters\n");
   exit(8);
   }

printf("\nMonthly Addup Program is running...\n\n");

strcpy(mmyyyy, argv[1]);
strcpy(filename, argv[2]);

printf("Monthly data will be written to output file: %s\n", filename);

if ( (fptr = fopen(filename,"w")) == NULL )
   {
   printf("Cannot open output file: %s\n", filename);
   exit(8);
   }

edit_and_convert_date(mmyyyy);

printf("Monthly data is being generated for: %s %s\n",month_name, year);

EXEC SQL connect to 'revenue';
if (SQLCODE != 0)
   {
   printf("SQL Error occurred on connect to database. ");
   printf("SQLCODE is: %d\n", SQLCODE);
   exit(8);   
   }
     
EXEC SQL declare get_revenue cursor for
     select loc_id,
            ind_id,
            ct_id,
            fee_id,
            dist_id,
            sum(amt_paid),
            sum(amt_credit),
            sum(amt_due),
            sum(trans_count_p),
            sum(trans_count_c),
            sum(trans_count_d)
       into :loc_id_revn_de,
            :ind_id_revn_de,
            :ct_id_revn_de,
            :fee_id_revn_de,
            :dist_id_revn_de,
            :amt_paid_revn_de,
            :amt_credit_revn_de,
            :amt_due_revn_de,
            :trans_count_p_revn_de,
            :trans_count_c_revn_de,
            :trans_count_d_revn_de
       from revenue
      where per_id in (select per_id      
                         from period
                        where per_level = "Week"         and
                              month     = :month_perd_de and   
                              year      = :year_perd_de)
   group by loc_id, ind_id, ct_id, fee_id, dist_id 
   FOR READ ONLY;


strcpy(year_perd_de,year);
strcpy(month_perd_de,month_name);

EXEC SQL
     select per_id
       into :per_id_perd_de
       from period
      where per_level = "Month"        and
            month     = :month_perd_de and
            year      = :year_perd_de;
 
per_id_for_month = per_id_perd_de;

strcpy(month_perd_de,month_name);
strcpy(year_perd_de,year);
EXEC SQL open get_revenue;
if (SQLCODE != 0)
   {
   printf("SQL Error occurred on open cursor get_revenue.  ");
   printf("SQLCODE is: %d\n", SQLCODE);
   exit(8);   
   }

EXEC SQL fetch get_revenue;
while (SQLCODE == 0)
    {
    if (x = dectodbl(&amt_paid_revn_de, &amt_paid)) 
       {
      printf("Error %d converting DECIMAL amt_paid_revn_de to DOUBLE\n",x);
      exit(8);
       }
    if (x = dectodbl(&amt_credit_revn_de, &amt_credit))
       {
      printf("Error %d converting DECIMAL amt_credit_revn_de to DOUBLE\n",x);
       exit(8);
       }
    if (x = dectodbl(&amt_due_revn_de, &amt_due))
       {
       printf("Error %d converting DECIMAL amt_due_revn_de to DOUBLE\n",x);
       exit(8);
       }
          
    fprintf(fptr, "%ld|",per_id_for_month);
    fprintf(fptr, "%ld|",loc_id_revn_de);
    fprintf(fptr, "%ld|",ind_id_revn_de);
    fprintf(fptr, "%ld|",ct_id_revn_de);
    fprintf(fptr, "%ld|",fee_id_revn_de);
    fprintf(fptr, "%ld|",dist_id_revn_de);
    fprintf(fptr, "%.2f|",amt_paid);
    fprintf(fptr, "%.2f|",amt_credit);
    fprintf(fptr, "%.2f|",amt_due);
    fprintf(fptr, "%ld|",trans_count_p_revn_de);
    fprintf(fptr, "%ld|",trans_count_c_revn_de);
    fprintf(fptr, "%ld|",trans_count_d_revn_de);
    fprintf(fptr, "\n");

    num_recs_created = num_recs_created + 1;
    EXEC SQL fetch get_revenue;  

    }

if (SQLCODE != 0 && SQLCODE != 100)
   {
   printf("SQLCODE is: %d\n",SQLCODE);
   exit(8);   
   }

printf("Number of load records created: %d\n",num_recs_created);

fclose(fptr);

EXEC SQL close get_revenue;  
EXEC SQL free get_revenue; 

EXEC SQL disconnect current;

printf("\nMonthly Addup Program completed...\n\n");
return(0);
}


/* Function to edit the month and year entered.  Convert the month */
/* to a literal (02 --> February)                                  */

edit_and_convert_date(mmyyyy)    
char *mmyyyy;

{
int i, j;
int month_num, year_num;

j=0;
for (i=0; i<2; i++) 
    {
    month[j] = mmyyyy[i];
    j++;
    }
month[j] = '\0';

j=0;
for (i=2; i<6; i++)
    {
    year[j] = mmyyyy[i];
    j++;
    }
year[j] = '\0';
 
month_num = atoi(month);
year_num = atoi(year);

switch (month_num)
   {
   case 1:  strcpy(month_name,"January");
            break;
   case 2:  strcpy(month_name,"February");
            break;
   case 3:  strcpy(month_name,"March");
            break;
   case 4:  strcpy(month_name,"April");
            break;
   case 5:  strcpy(month_name,"May");
            break;
   case 6:  strcpy(month_name,"June");
            break;
   case 7:  strcpy(month_name,"July");
            break;
   case 8:  strcpy(month_name,"August");
            break;
   case 9:  strcpy(month_name,"September");
            break;
   case 10: strcpy(month_name,"October");
            break;
   case 11: strcpy(month_name,"November");
            break;
   case 12: strcpy(month_name,"December");
            break;
   default: printf("Invalid month value.  Value is: %d\n",month_num);
            exit(8);   
   }

if (year_num > 1900 && year_num < 2100)
   ;
else
   {
   printf("Invalid year value.  Value is: %d\n",year_num);
   exit(8);
   }
}
Re: C compiler Error on EXEC SQL
#3171
Author: smryan
Date: Fri, 12 Apr 1996 05:12
16 lines
1292 bytes
: I post this for my friend who has no access to the internet and would like to
: get help from C experts in the Net. She has a C program left over from a guy
: left the company. The C source code is included below as well as the compiler
: error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
: to be a standard C. 

System Query Language?

This looks like it is supposed to be preprocessed by a database system into
legitimate C before compilation.

-- 
The Queen, amused, in quiet power,         | smryan@netcom.com  PO Box 1563
will draw the son to darkenned bower.      |          Cupertino, California
Her face is fair, her fragrance rare,      | (xxx)xxx-xxxx            95015
with woven webs for wayward flower.        |         I don't use no smileys
Re: C compiler Error on EXEC SQL
#3172
Author: Christian Knapmeyer
Date: Fri, 12 Apr 1996 07:57
47 lines
2293 bytes

In article <4kkej2$3ta@news.cc.utah.edu> dpncc@utah.state.ut.us (NCC Network) writes:

  > 
  > Hi
  > 
  > I post this for my friend who has no access to the internet and would like to
  > get help from C experts in the Net. She has a C program left over from a guy
  > left the company. The C source code is included below as well as the compiler
  > error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
  > to be a standard C. 
  > 
  > I would appreciate any hints or comments.
  > Thanks in advances.
  > 
  > Dennis. 
  > 

[ source code deleted ]

This is the source of a relational database application.
I don't know which database it is, cause SQL looks quite similar on the
various systems. It could be, let's say Ingres, Oracle,.. or what else.

The source includes SQL-Statements introduced with "EXEC SQL".
To compile it, you must first feed it through the precompiler
of the database system, which replaces the "EXEC SQL" parts with
some real C code and produces a file named *.c. 
Then give this to your normal C compiler.

When linking the program you must add the link libraries that came
with the database system.

Your friend should ask someone in her company about how to compile
and link this stuff... hopefully there's someone else left who
knows about database programming...

Greetings,
  Christian
--
 ----------------------------------------------------------------------------
  Dipl.-Inform. Christian Knapmeyer     Email: knapmey@tecmath.de
  TecMath GmbH                          Voice: 06301/606-0  Fax: 06301/606-66
  Sauerwiesen 2                         Face : Room 115
  67661 Kaiserslautern, Germany         Disclaimer: as usual
 ---------- press any key to continue. press any other key to quit.----------
Re: C compiler Error on EXEC SQL
#3174
Author: Eric Brown
Date: Fri, 12 Apr 1996 12:15
30 lines
2007 bytes
In <smryanDpqH4n.JIM@netcom.com>, smryan@netcom.com (@#$%!?!) writes:
>: I post this for my friend who has no access to the internet and would like to
>: get help from C experts in the Net. She has a C program left over from a guy
>: left the company. The C source code is included below as well as the compiler
>: error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
>: to be a standard C. 
>
>System Query Language?
>
>This looks like it is supposed to be preprocessed by a database system into
>legitimate C before compilation.
>
>-- 
>The Queen, amused, in quiet power,         | smryan@netcom.com  PO Box 1563
>will draw the son to darkenned bower.      |          Cupertino, California
>Her face is fair, her fragrance rare,      | (xxx)xxx-xxxx            95015
>with woven webs for wayward flower.        |         I don't use no smileys

Structured Query Lamguage.  It is used by relational databases such as DB2, Informix,
Sybase, and Oracle to allow batch or online programs interact with such databases.
As was noted above, the EXEC SQL tag identifies a piece of code to be preprocessed
by an SQL preprocessor.  Your friend must have one of these databases (or could be
one of the other 'off-brands').

Eric Brown
Colorado Springs, CO

*********************************************************************
* The opinions expressed herein do not reflect those of my employer *
*********************************************************************
Re: C compiler Error on EXEC SQL
#3176
Author: Dominic Feeley
Date: Fri, 12 Apr 1996 12:19
21 lines
1356 bytes
In article <4kkej2$3ta@news.cc.utah.edu>
           dpncc@utah.state.ut.us "NCC Network" writes:

> I post this for my friend who has no access to the internet and would like to
> get help from C experts in the Net. She has a C program left over from a guy
> left the company. The C source code is included below as well as the compiler
> error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
> to be a standard C.

It is nothing to do with ANSI C
It's most likely an Oracle extension for rdbms access from C.
You have to link in the Pro*C stuff to get it to compile.
Or similar for other vendors, as SQL is Structured Query Language.

Try comp.databases.oracle if it is an Oracle problem.
Or one of the comp.databases.* groups.

It may well be in their FAQs.

-- 
Dominic Feeley
Re: C compiler Error on EXEC SQL
#3175
Author: Jon Trulson
Date: Fri, 12 Apr 1996 15:09
56 lines
2468 bytes
-----BEGIN PGP SIGNED MESSAGE-----

NCC Network (dpncc@utah.state.ut.us) wrote:
: 
: Hi
: 
: I post this for my friend who has no access to the internet and would like to
: get help from C experts in the Net. She has a C program left over from a guy
: left the company. The C source code is included below as well as the compiler
: error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
: to be a standard C. 
: 
: I would appreciate any hints or comments.
: Thanks in advances.
: 
: Dennis. 
[...errors snipped...]

	This code contains embedded SQL code that will need to be
preprocessed by something like ESQLC (informix), or ProC (? oracle) 
before it can be compiled.

[...code snipped...]


- --
Jon Trulson		Inet: (work) trulsonj@clem.mscd.edu
Systems Programmer II       : (home) jon@radscan.com
Information Technology, Metropolitan State College of Denver, Colorado
Patent Pending 		FREE MARS!

- -----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2

mQENAzFqlGwAAAEH/1u4rzcOtlTHeTePo2o8O9szuLn6WG4tUqSEzPZ2SfjL+t3j
LIrtlGt4hnBEUfU/jmWNyQ75f8NBO2yi8VDcXjgnhfyRNE0duegdchnra9iS1Ukb
UCbvTWQOiPa0hslsvKXDg5XDrg6nxF3kOqam2qnDcHYPmDoV9Pr2QfNuYJefizCw
dswq/9O+LBvuQC7eKhi1BzGm4P2nys2wJPw1j+AH+6kkPLp6WFAN0pkWJkxUDkqK
G+r2xb3NIZjoxPGX+NxboOvHLTMj/k6itTiS0JwDAempOb2azXeqFL2EfmcbHI1T
jsZmow1uoPaDUOwQtcgBNVq0HDI6eraG913yRtkABRG0H0pvbiBUcnVsc29uIDx0
cnVsc29uakBtc2NkLmVkdT4=
=XjvH
- -----END PGP PUBLIC KEY BLOCK-----


-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQEVAwUBMW5yNnq2hvdd8kbZAQFaZgf/VLuJtJoNv6/GrFKXwLV9mEPluscQBiG0
PrkwsyIY53HDxaKZfJgYATdPdSoT/364z+H1XlLYv0BjZ0VNcg/0bPqowYCtlyqk
HFDpqj6WYL1B8MHKnXAdCcQ1lMPtVpsVgau5SggIqSfLAOyxPsNMNizc0Prjx8SS
aZeYG4ZNjpvLlZRTt9Yp+/EdkzDm1ucbOxl7CT94I9aNz+FpBeTtrtyBTGA0i+rc
fxOKfTBPVFK5KHkQi5Fg6O1Wjb3OSLk1P6/D9VQF7zrxoEe7v0/e2vWxc4oOn5UI
PeHaS77Fjwpi15lh61jI2eALIOnv3Y8o9H+RB7SWjndBMQ1znaHKGw==
=l9/m
-----END PGP SIGNATURE-----
Re: C compiler Error on EXEC SQL
#3177
Author: GHouck
Date: Sat, 13 Apr 1996 07:02
33 lines
1972 bytes
dpncc@utah.state.ut.us (NCC Network) wrote:
>
>Hi
>
>I post this for my friend who has no access to the internet and would like to
>get help from C experts in the Net. She has a C program left over from a guy
>left the company. The C source code is included below as well as the compiler
>error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
>to be a standard C. 
>
[snip]
>
>(Bundled) cc:  line 4: error 1000: Unexpected symbol: "SQL".
>(Bundled) cc:  line 4: error 1000: Unexpected symbol: ";".
>(Bundled) cc:  line 12: error 1000: Unexpected symbol: "SQL".
>(Bundled) cc:  line 12: error 1000: Unexpected symbol: "DECLARE".
>(Bundled) cc:  line 24: error 1000: Unexpected symbol: "SQL".
>(Bundled) cc:  line 24: error 1000: Unexpected symbol: "DECLARE".
>(Bundled) cc:  line 50: error 1000: Unexpected symbol: "SQL".
>(Bundled) cc:  line 50: error 1000: Unexpected symbol: "'revenue'".
>...............................
[snip]
Dennis,

Officially known as 'embedded SQL' source.  If Oracle database, then it can
be called PRO*C, if INGRES: ESQL, etc.  As indicated by others, preprocess
with the database vendors pre-processor, then compile with a C compiler
that the vendor supports (I would assume your system has the correct
one resident, if it used to work).  There was likely left behind
command procedures or batch files to invoke the pre-process, compile,
link sequence.
Good luck,
Geoff Houck
Re: C compiler Error on EXEC SQL
#3179
Author: ggil
Date: Tue, 16 Apr 1996 04:17
53 lines
2577 bytes
In Article<4knjii$i9s@nadine.teleport.com>, <hksys@teleport.com> writes:
> Path: 
news.NetVision.net.il!psinntp!psinntp!psinntp!howland.reston.ans.net!newsfeed.i
nternetmci.com!info.ucla.edu!psgrain!nntp.teleport.com!usenet
> From: GHouck <hksys@teleport.com>
> Newsgroups: comp.unix.programmer,comp.lang.c,comp.unix.internals
> Subject: Re: C compiler Error on EXEC SQL
> Date: 13 Apr 1996 07:02:42 GMT
> Organization: systems hk
> Lines: 35
> Message-ID: <4knjii$i9s@nadine.teleport.com>
> References: <4kkej2$3ta@news.cc.utah.edu>
> NNTP-Posting-Host: ip-pdx14-40.teleport.com
> Mime-Version: 1.0
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
> X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
> Xref: news.NetVision.net.il comp.unix.programmer:2897 comp.lang.c:10046 
comp.unix.internals:457
> 
> dpncc@utah.state.ut.us (NCC Network) wrote:
> >
> >Hi
> >
> >I post this for my friend who has no access to the internet and would like 
to
> >get help from C experts in the Net. She has a C program left over from a 
guy
> >left the company. The C source code is included below as well as the 
compiler
> >error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't 
seem
> >to be a standard C. 
> >
> [snip]
> >
> >(Bundled) cc:  line 4: error 1000: Unexpected symbol: "SQL".
> >(Bundled) cc:  line 4: error 1000: Unexpected symbol: ";".
> >(Bundled) cc:  line 12: error 1000: Unexpected symbol: "SQL".
> >(Bundled) cc:  line 12: error 1000: Unexpected symbol: "DECLARE".
> >(Bundled) cc:  line 24: error 1000: Unexpected symbol: "SQL".
> >(Bundled) cc:  line 24: error 1000: Unexpected symbol: "DECLARE".
> >(Bundled) cc:  line 50: error 1000: Unexpected symbol: "SQL".
> >(Bundled) cc:  line 50: error 1000: Unexpected symbol: "'revenue'".
> >...............................
> [snip]
> Dennis,

In order to progress ask your friend to look for
a make file. The answer will probably be there.

Gil Gilad
Re: C compiler Error on EXEC SQL
#3180
Author: Dhawal Tyagi
Date: Tue, 16 Apr 1996 16:09
31 lines
1716 bytes
In article <NEWTNews.829628398.26731.ggil@dialup.netvision.net.il>,
ggil@netvision.net.il wrote:

In Article<4knjii$i9s@nadine.teleport.com>, <hksys@teleport.com> writes:

> >I post this for my friend who has no access to the internet and would like 
to
> >get help from C experts in the Net. She has a C program left over from a 
guy
> >left the company. The C source code is included below as well as the 
compiler
> >error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't 

The "EXEC SQL" instruction is used in embedded SQL program. the program is
related to database access. To compile it with a C compiler, first you have
to pre-compile it with a pre-compiler, one such precompiler is proc, which
is used with Oracle database. The precompiler will generate a .c file from
a .pc file, you can then compile it with a regular C compiler, of course
you'll have to link to some other libs as well to make that EXEC SQL work.

Hope this helps

Regards

Dhawal
--
Programmer/Analyst
Communications Network Services.
1700 Pratt Dr., Blacksburg, VA 24061-0506
Office phone # (540) 231-7973
http://morse.cns.vt.edu:8000/~tyagi/tyagi.html
Re: C compiler Error on EXEC SQL
#3183
Author: Guy Dallaire
Date: Thu, 18 Apr 1996 01:10
23 lines
1254 bytes
dpncc@utah.state.ut.us (NCC Network) wrote:


>Hi

>I post this for my friend who has no access to the internet and would like to
>get help from C experts in the Net. She has a C program left over from a guy
>left the company. The C source code is included below as well as the compiler
>error generated by HP UNIX. What is the EXEC SQL instruction ? It doesn't seem
>to be a standard C. 

That program is in effect an informix EDA/SQL or Oracle PRO*C program.
It cannot be directly compiled by 'cc'. It must be preprocessed by a
database vendor Pre-Compiler which will transform the EXEC SQL etc.
sentences into C calls. Look in your system for a makefile with an
'.ec' target in it...

				Good Luck
Guy Dallaire
Groupe DMR Inc.
dallaire@megatoon.com

P.S. My opinions are my own and do not reflect those of my employer
Re: C compiler Error on EXEC SQL
#3184
Author: Lokman Merican
Date: Fri, 19 Apr 1996 02:21
12 lines
785 bytes
The EXEC SQL sections are used to allow your program to interact with 
an SQL database using standard SQL statements like SELECT and INSERT.

Such programs are usually precompiled by an SQL precompiler (to produce 
a .c file) then fed into a regular c compiler for the final executable code.

As Gil has pointed out, you'll probably need to look for a make file 
(or batch file) to actually do all this.  



Lokman
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads