BUG #4549: ecpg produces code that don't compile

From: "Clemens Fischer" <cfi(at)mbs-software(dot)de>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #4549: ecpg produces code that don't compile
Date: 2008-11-25 10:44:32
Message-ID: 200811251044.mAPAiWi0090108@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 4549
Logged by: Clemens Fischer
Email address: cfi(at)mbs-software(dot)de
PostgreSQL version: 8.3.5
Operating system: QNX 6.3
Description: ecpg produces code that don't compile
Details:

Hello List,

Don't know whether anyone here can help but...
We have some code that has compiled and ran just fine from postgresql 7.4.x
thru 8.2.9. It uses embedded sql. With the new port - 8.3.5 - this code will
no longer compile. Below is a standalone code, which shows you the details.
Any help or ideas would be appreciated.

-- snip ecpgtest-multidim.pgc begin --
#include <stdio.h>
#include <stdlib.h>

EXEC SQL include sqlca;
EXEC SQL WHENEVER SQLERROR sqlprint;
EXEC SQL WHENEVER SQLWARNING sqlprint;
EXEC SQL WHENEVER NOT FOUND continue;

int main( void )
{
EXEC SQL begin declare section;
char multidim_char[4][50]; // works
VARCHAR multidim_varchar[4][50]; // failed
EXEC SQL end declare section;

ECPGdebug(1, stderr);
EXEC SQL connect to postgres user postgres using postgres;

EXEC SQL DROP TABLE IF EXISTS ecpgtest;
EXEC SQL CREATE TABLE ecpgtest (no INTEGER PRIMARY KEY,
name VARCHAR(30) NOT NULL);
EXEC SQL INSERT INTO ecpgtest VALUES (1, 'first');
EXEC SQL INSERT INTO ecpgtest VALUES (2, 'second');
EXEC SQL INSERT INTO ecpgtest VALUES (3, 'third');

// test 1
EXEC SQL SELECT name INTO :multidim_char[0] FROM ecpgtest WHERE no = 1;
// test 2
EXEC SQL SELECT name INTO :multidim_varchar[0] FROM ecpgtest WHERE no =
1;

EXEC SQL DISCONNECT ALL;
ECPGdebug(0, stderr);

return( EXIT_SUCCESS );
}
-- snip ecpgtest-multidim.pgc end --

Using ecpg and gcc generates the following output:
ecpg -t -o ecpgtest-multidim.c ecpgtest-multidim.pgc
cc -c -I/usr/local/pgsql/include ecpgtest-multidim.c
ecpgtest-multidim.pgc: In function `main':
ecpgtest-multidim.pgc:30: parse error before `_13'
cc: /usr/qnx630/host/qnx6/x86/usr/lib/gcc-lib/ntox86/2.95.3/cc1 error 33
make: *** [ecpgtest-multidim.o] Error 1

-- snip ecpgtest-multidim.c code fragment 1 begin --
int main( void )
{
/* exec sql begin declare section */
// works
// failed

#line 12 "ecpgtest-multidim.pgc"
char multidim_char [ 4 ] [ 50 ] ;

#line 13 "ecpgtest-multidim.pgc"
struct varchar_multidim_varchar_13 { int len; char arr[ 50 ]; }
multidim_va rchar [4] ;
/* exec sql end declare section */
#line 14 "ecpgtest-multidim.pgc"

ECPGdebug(1, stderr);
-- snip ecpgtest-multidim.c code fragment 1 end --

You see in "#line 13" the definition of the varchar.

-- snip ecpgtest-multidim.c code fragment 2 begin --
// test 1
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select name from
ecpgtest where no = 1 ", ECPGt_EOIT,
ECPGt_char,(multidim_char[0]),(long)50,(long)1,(50)*sizeof(char),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 27 "ecpgtest-multidim.pgc"

if (sqlca.sqlwarn[0] == 'W') sqlprint();
#line 27 "ecpgtest-multidim.pgc"

if (sqlca.sqlcode < 0) sqlprint();}
#line 27 "ecpgtest-multidim.pgc"

// test 2
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select name from
ecpgtest where no = 1 ", ECPGt_EOIT,
ECPGt_varchar,&(multidim_varchar[0]),(long)50,(long)1,sizeof(struct
varchar_multidim_varchar[0]_13),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 29 "ecpgtest-multidim.pgc"

-- snip ecpgtest-multidim.c fragment 2 end --

In the second fragment you see the wrong sizeof-call:
varchar_multidim_varchar[0]_13
one solution is:
varchar_multidim_varchar_13[0]

Can you fix this, please?
Thank you
Clemens Fischer

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Clemens Fischer 2008-11-25 12:28:38 BUG #4550: ecpg problem with copy command and hostvar
Previous Message Peter Eisentraut 2008-11-24 21:55:17 Re: BUG #4548: Documentation Contradiction for 8.3