![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm porting a number of programs from Informix embedded SQL to postgreSQL, and ran into the following problem. The optim_accounts.ec program included the following: EXEC SQL BEGIN DECLARE SECTION; EXEC SQL INCLUDE acct_plan_web.h; EXEC SQL END DECLARE SECTION; |
|
If I delete the header guard from acct_plan_web.h, it preprocesses cleanly. If I eliminate the declare section and use a more conventional EXEC SQL INCLUDE acct_plan_web; then I get: begin output $ make optim_accounts.c ecpg optim_accounts.ec optim_accounts.ec:482: ERROR: invalid datatype 'struct acct_plan_web_st' end output Any ideas? Does ecpg not like typedefs? Am I going blind and missing something obvious? |
#3
| |||
| |||
|
|
Al Balmer <albalmer (AT) att (DOT) net> wrote: I'm porting a number of programs from Informix embedded SQL to postgreSQL, and ran into the following problem. The optim_accounts.ec program included the following: EXEC SQL BEGIN DECLARE SECTION; EXEC SQL INCLUDE acct_plan_web.h; EXEC SQL END DECLARE SECTION; [...] If I delete the header guard from acct_plan_web.h, it preprocesses cleanly. If I eliminate the declare section and use a more conventional EXEC SQL INCLUDE acct_plan_web; then I get: begin output $ make optim_accounts.c ecpg optim_accounts.ec optim_accounts.ec:482: ERROR: invalid datatype 'struct acct_plan_web_st' end output Any ideas? Does ecpg not like typedefs? Am I going blind and missing something obvious? I played around, and found that when you EXEC SQL INCLUDE mumble; ecpg will look for 'mumble' before looking for 'mumble.h'. |
|
Is there maybe a file 'acct_plan_web' around? Other than that, it should work. I'll append some sample code that works on my PostgreSQL 8.1.4 system. Yours, Laurenz Albe -------------------- begin ecpg.pgc --------------------- #include <stdio.h #include <stdlib.h EXEC SQL BEGIN DECLARE SECTION; EXEC SQL INCLUDE ecpg; EXEC SQL END DECLARE SECTION; int main(int argc, char** argv) { EXEC SQL BEGIN DECLARE SECTION; my_t my = (my_t)malloc(sizeof(struct mystruct)); EXEC SQL END DECLARE SECTION; EXEC SQL CONNECT TO DEFAULT; EXEC SQL SELECT 1, 2 INTO :my; EXEC SQL DISCONNECT; printf("my = { %ld, %ld }\n", my->a, my->b); return 0; } ------------------------ end ---------------------------- -------------------- begin ecpg.h ----------------------- typedef struct mystruct { long a; long b; } *my_t; ------------------------ end ---------------------------- $ ecpg ecpg $ gcc -Wall -g -o ecpgtest ecpg.c -I/magwien/postgres/include \ -L/magwien/postgres/lib -lecpg -Wl,-rpath,/magwien/postgres/lib $ ./ecpgtest my = { 1, 2 } |
#4
| |||
| |||
|
|
I'm porting a number of programs from Informix embedded SQL to postgreSQL, and ran into the following problem. The optim_accounts.ec program included the following: EXEC SQL BEGIN DECLARE SECTION; EXEC SQL INCLUDE acct_plan_web.h; EXEC SQL END DECLARE SECTION; [...] If I delete the header guard from acct_plan_web.h, it preprocesses cleanly. If I eliminate the declare section and use a more conventional EXEC SQL INCLUDE acct_plan_web; then I get: begin output $ make optim_accounts.c ecpg optim_accounts.ec optim_accounts.ec:482: ERROR: invalid datatype 'struct acct_plan_web_st' end output Any ideas? Does ecpg not like typedefs? Am I going blind and missing something obvious? I played around, and found that when you EXEC SQL INCLUDE mumble; ecpg will look for 'mumble' before looking for 'mumble.h'. That's a good thing to know, though it doesn't seem to be the problem here. I notice that the include file in your sample doesn't have a header guard, and my problem seems to go away if I remove the header guard. |
#5
| |||
| |||
|
|
I played around, and found that when you EXEC SQL INCLUDE mumble; ecpg will look for 'mumble' before looking for 'mumble.h'. That's a good thing to know, though it doesn't seem to be the problem here. I notice that the include file in your sample doesn't have a header guard, and my problem seems to go away if I remove the header guard. Ah, good, I thought there was another problem besides the #ifdefs. You could report it as a bug on pgsql-bugs that the header guards make ecpg choke. Maybe somebody will fix it some day. |
#6
| |||
| |||
|
|
Dang! I figured out what it was. If the struct definition is used in a declare section, the definition itself has to be in a declare section, else the preprocessor doesn't recognize it. The problem only seemed to go away because the preprocessor stopped complaining (a bug in itself, probably.) |
|
The modified include file is: begin code #ifndef H_ACCT_PLAN_WEB #define H_ACCT_PLAN_WEB EXEC SQL BEGIN DECLARE SECTION; <--- this line added typedef struct acct_plan_web_st { long acct; long plan; long min_deposit; long max_deposit; } *user_t; EXEC SQL END DECLARE SECTION; <--- this line added #endif end code |
#7
| |||
| |||
|
|
Al Balmer <albalmer (AT) att (DOT) net> wrote: Dang! I figured out what it was. If the struct definition is used in a declare section, the definition itself has to be in a declare section, else the preprocessor doesn't recognize it. The problem only seemed to go away because the preprocessor stopped complaining (a bug in itself, probably.) So you think that the example I posted contains a bug that does not get reported by ecpg? Or do I misunderstand you? If you surround the EXEC SQL INCLUDE with a DECLARE SECTION, the struct definition _is_ inside the DECLARE SECTION. I'm probably confusing myself as well as you <g>. This is a different |
|
The modified include file is: begin code #ifndef H_ACCT_PLAN_WEB #define H_ACCT_PLAN_WEB EXEC SQL BEGIN DECLARE SECTION; <--- this line added typedef struct acct_plan_web_st { long acct; long plan; long min_deposit; long max_deposit; } *user_t; EXEC SQL END DECLARE SECTION; <--- this line added #endif end code Do I get it right that you removed the EXEC SQL BEGIN/END DECLARE SECTION surrounding the EXEC SQL INCLUDE in the .c file? That would work. Take care that the header file is never #included in regular C code. Yours, Laurenz Albe |
![]() |
| Thread Tools | |
| Display Modes | |
| |