Thread: BUG #4955: ECPG produces incomplete code

BUG #4955: ECPG produces incomplete code

From
"Heiko Folkerts"
Date:
The following bug has been logged online:

Bug reference:      4955
Logged by:          Heiko Folkerts
Email address:      heiko.folkerts@david-bs.de
PostgreSQL version: 8.4
Operating system:   Windows XP
Description:        ECPG produces incomplete code
Details:

When compiling the following code with ecpg the result is missing some of
the embedded SQL code:
source in a pgc file:
EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR synonymstring[500];
    long ID;
    char* keywordstring;
    EXEC SQL END DECLARE SECTION;
    QByteArray buf = Keyword.getKeyword().toUtf8();
    keywordstring = buf.data();
    ID = Keyword.getLanguageID().getID();
    EXEC SQL DECLARE synonymcursor CURSOR FOR SELECT synonym FROM
modelisar_data.tfsssynonym s, modelisar_data.tfsskeyword k WHERE k.id =
s.original_id AND k.keyword = :keywordstring AND k.catalog_id = :ID AND
synonym IS NOT NULL;
    int a;
    EXEC SQL OPEN synonymcursor;
    int b;
    EXEC SQL WHENEVER SQLWARNING SQLPRINT;
    int c;
    EXEC SQL WHENEVER NOT FOUND DO BREAK;
    while(true)
    {
                EXEC SQL FETCH NEXT FROM synonymcursor INTO :synonymstring;

Result in C-File:
/* exec sql begin declare section */




#line 65 "../../repository/TSSDB/TSSDBPGAccessor.pgc"
  struct varchar_synonymstring_65  { int len; char arr[ 500 ]; }
synonymstring ;

#line 66 "../../repository/TSSDB/TSSDBPGAccessor.pgc"
 long ID ;

#line 67 "../../repository/TSSDB/TSSDBPGAccessor.pgc"
 char * keywordstring ;
/* exec sql end declare section */
#line 68 "../../repository/TSSDB/TSSDBPGAccessor.pgc"

    QByteArray buf = Keyword.getKeyword().toUtf8();
    keywordstring = buf.data();
    ID = Keyword.getLanguageID().getID();
    /* declare synonymcursor cursor for select synonym from modelisar_data .
tfsssynonym s , modelisar_data . tfsskeyword k where k . id = s .
original_id and k . keyword = $1  and k . catalog_id = $2  and synonym is
not null */
#line 72 "../../repository/TSSDB/TSSDBPGAccessor.pgc"

    int a;
    { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare synonymcursor
cursor for select synonym from modelisar_data . tfsssynonym s ,
modelisar_data . tfsskeyword k where k . id = s . original_id and k .
keyword = $1  and k . catalog_id = $2  and synonym is not null",
    ECPGt_char,&(keywordstring),(long)0,(long)1,(1)*sizeof(char),
    ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
    ECPGt_long,&(ID),(long)1,(long)1,sizeof(long),
    ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
#line 74 "../../repository/TSSDB/TSSDBPGAccessor.pgc"

    int b;
    /* exec sql whenever sql_warning  sqlprint ; */
#line 76 "../../repository/TSSDB/TSSDBPGAccessor.pgc"

    int c;
    /* exec sql whenever not found  break ; */
#line 78 "../../repository/TSSDB/TSSDBPGAccessor.pgc"

    while(true)
    {
                { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch next from
synonymcursor", ECPGt_EOIT,
    ECPGt_varchar,&(synonymstring),(long)500,(long)1,sizeof(struct
varchar_synonymstring_65),
    ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 81 "../../repository/TSSDB/TSSDBPGAccessor.pgc"

if (sqlca.sqlcode == ECPG_NOT_FOUND) break;
#line 81 "../../repository/TSSDB/TSSDBPGAccessor.pgc"

if (sqlca.sqlwarn[0] == 'W') sqlprint();}
#line 81 "../../repository/TSSDB/TSSDBPGAccessor.pgc"

It seems that the open command for the cursor is not present. The first
fetch passes but with wrong data in the host variables.

Re: BUG #4955: ECPG produces incomplete code

From
Michael Meskes
Date:
On Thu, Jul 30, 2009 at 06:59:32AM +0000, Heiko Folkerts wrote:
> When compiling the following code with ecpg the result is missing some of
> the embedded SQL code:
> ...
> It seems that the open command for the cursor is not present. The first

No, there simply is no such thing as an open command in PostgreSQL. Instead the
declare command opens the cursor which is why the declare is called in the
position open was listed.

Michael
--
Michael Meskes
Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org)
Michael at BorussiaFan dot De, Meskes at (Debian|Postgresql) dot Org
ICQ: 179140304, AIM/Yahoo/Skype: michaelmeskes, Jabber: meskes@jabber.org
Go VfL Borussia! Go SF 49ers! Use Debian GNU/Linux! Use PostgreSQL!