ESQL/C : Syntax error
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Hi,
I am a beginner at ESQL/C, in the first program I've
tried
I have got an syntax error which I
am not able to debug.
It is a simple program .
It uses a cursor and a structure to copy selected rows
from table abcde
to table abcd.
Any help /hints are welcome and appreciated.My
apologies if it is too dumb :)
Thanks - Maria
Informix -Online Version 7.23.UC1
The Error:
##########
Syntax error at line 22 : 'from ' unexpected
##################################################
The Program:
############
#include <stdio.h>
#define ON 1
#define OFF 0
main()
{
EXEC SQL connect to 'newdb';
EXEC SQL BEGIN DECLARE SECTION;
struct stc
{
int v1;
int v2;
int v3;
int v4;
}stc01;
EXEC SQL END DECLARE SECTION;
EXEC SQL declare cur1 cursor for
select a,b,c,d
from abcde
where e = 0;
EXEC SQL open cur1;
for(;;)
{
EXEC SQL fetch cur1 into :stc01 ;
EXEC SQL insert into abcd values (:stc01);
}
EXEC SQL close cur1;
EXEC SQL free cur1;
}
__________________________________________________
Do You Yahoo!?
Thousands of Stores. Millions of Products. All in one place.
Yahoo! Shopping: http://shopping.yahoo.com
> main() > { > EXEC SQL connect to 'newdb'; > EXEC SQL BEGIN DECLARE SECTION; > struct stc > {...} > EXEC SQL END DECLARE SECTION; Hi Maria, I think you will have to DECLARE your stuff first, then CONNECT to your database. Hth, Chris
Oooooo That's an esotheric one. Read on and I shall enlighten:
Maria Seagull wrote:
>
> Hi,
> I am a beginner at ESQL/C, in the first program I've
> tried
> I have got an syntax error which I
> am not able to debug.
>
> It is a simple program .
> It uses a cursor and a structure to copy selected rows
> from table abcde
> to table abcd.
>
> Any help /hints are welcome and appreciated.My
> apologies if it is too dumb :)
> Thanks - Maria
>
> Informix -Online Version 7.23.UC1
>
> The Error:
> ##########
>
> Syntax error at line 22 : 'from ' unexpected
>
> ##################################################
>
> The Program:
> ############
>
> #include <stdio.h>
> #define ON 1
> #define OFF 0
> main()
> {
Function level declarations, in C, belong at the beginning of the function
(main) before any executable code. The next line (connect) is generated as
an executable function call so the subsequent structure definition (struct stc)
and variable declaration (stc01) are illegal syntax where they are.
C++ permits definitions and declarations anywhere in the code but ANSI C
permits them ONLY at the beginning of a statement block (ie immediately
following an opening curly brace and before any executable statements in the
block). Why the error was not caught until the syntax confusion of the
cursor DECLARE below that I do not know.
> EXEC SQL connect to 'newdb';
>
> EXEC SQL BEGIN DECLARE SECTION;
> struct stc
> {
> int v1;
> int v2;
> int v3;
> int v4;
> }stc01;
> EXEC SQL END DECLARE SECTION;
>
> EXEC SQL declare cur1 cursor for
> select a,b,c,d
> from abcde
> where e = 0;[SNIP]
Art S. Kagel