ECPG - bug in EXEC SQL WHENEVER NOT FOUND?

From: Christian Rank <christian(dot)rank(at)rz(dot)uni-passau(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: ECPG - bug in EXEC SQL WHENEVER NOT FOUND?
Date: 2004-03-06 20:54:13
Message-ID: 404A3A75.7090104@rz.uni-passau.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Today I ran into problems when combining a C program with SQL statements
with the ECPG interface of PostgreSQL:

According to the documentation, it should be possible with
EXEC SQL WHENEVER NOT FOUND action
to trigger an action when a query does not return a row.

This does not seem to function. Here is the C program I tested:

----------------------------------------------------------------
/* Test for ecpg interface */
/* An empty table
t (n INTEGER);
must exist in the database
*/
#include <stdio.h>
EXEC SQL BEGIN DECLARE SECTION;
int i;
EXEC SQL END DECLARE SECTION;
int main ()
{ int c;
ECPGdebug(1,stdout);
EXEC SQL WHENEVER SQLERROR SQLPRINT;
EXEC SQL WHENEVER NOT FOUND GOTO notfound;
EXEC SQL CONNECT TO unix:postgresql://localhost/mydb USER rank;
EXEC SQL SELECT n INTO :i FROM t;
printf ("%d\n", i);
EXEC SQL DISCONNECT;
exit (0);
notfound:
printf ("no data found\n");
EXEC SQL DISCONNECT;
exit (0);
}
----------------------------------------------------------------

When running this program on an empty table t in the database, it produces:

[1116]: ECPGdebug: set to 1
[1116]: ECPGconnect: opening database mydb on <DEFAULT> port <DEFAULT>
for user rank
[1116]: ECPGexecute line 16: QUERY: select n from t on connection mydb
[1116]: ECPGexecute line 16: Correctly got 0 tuples with 1 fields
[1116]: raising sqlcode 100 in line 16, 'No data found in line 16.'.
0
[1116]: ecpg_finish: Connection mydb closed.

We can see that sqlcode is set correctly, but the jump to the C-label
notfound does not occur.

Is this a bug in ECPG or am I doing something wrong?

Thanks in advance for your help,
Christian Rank

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Reyes 2004-03-06 20:55:56 Re: Changing schema owner?
Previous Message Gavin M. Roy 2004-03-06 18:12:47 Re: why is this index not being used?