BUG #4955: ECPG produces incomplete code - Mailing list pgsql-bugs

From Heiko Folkerts
Subject BUG #4955: ECPG produces incomplete code
Date
Msg-id 200907300659.n6U6xWJe051416@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #4955: ECPG produces incomplete code
List pgsql-bugs
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.

pgsql-bugs by date:

Previous
From: "Steve Caligo"
Date:
Subject: Re: BUG #4925: "select ... for update" doesn't affect rows from sub-query
Next
From: Tom Lane
Date:
Subject: Re: fix: plpgsql: return query and dropped columns problem