Thread: ECPG - bug in EXEC SQL WHENEVER NOT FOUND?

ECPG - bug in EXEC SQL WHENEVER NOT FOUND?

From
Christian Rank
Date:
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

Re: ECPG - bug in EXEC SQL WHENEVER NOT FOUND?

From
Michael Meskes
Date:
On Sat, Mar 06, 2004 at 09:54:13PM +0100, Christian Rank wrote:
> 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.

Yes, that should work.

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

Which version are you using? I get this:

postgres@feivel:/home/postgres/pgsql/src/interfaces/ecpg$ ./a
[21964]: ECPGdebug: set to 1
[21964]: ECPGconnect: opening database mm on <DEFAULT> port <DEFAULT>
[21964]: ECPGexecute line 16: QUERY: select  n   from t    on connection mm
[21964]: ECPGexecute line 16: Correctly got 0 tuples with 1 fields
[21964]: raising sqlcode 100 in line 16, 'No data found in line 16.'.
no data found
[21964]: ecpg_finish: Connection mm closed.

Looks okay, doesn't it?

Michael
--
Michael Meskes
Email: Michael at Fam-Meskes dot De
ICQ: 179140304, AIM/Yahoo: michaelmeskes, Jabber: meskes@jabber.org
Go SF 49ers! Go Rhein Fire! Use Debian GNU/Linux! Use PostgreSQL!

Re: ECPG - bug in EXEC SQL WHENEVER NOT FOUND?

From
Christian Rank
Date:
Michael Meskes wrote:
> On Sat, Mar 06, 2004 at 09:54:13PM +0100, Christian Rank wrote:
>
>>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.
>
>
> Yes, that should work.
>
>
>>Is this a bug in ECPG or am I doing something wrong?
>
>
> Which version are you using? I get this:
>
> postgres@feivel:/home/postgres/pgsql/src/interfaces/ecpg$ ./a
> [21964]: ECPGdebug: set to 1
> [21964]: ECPGconnect: opening database mm on <DEFAULT> port <DEFAULT>
> [21964]: ECPGexecute line 16: QUERY: select  n   from t    on connection mm
> [21964]: ECPGexecute line 16: Correctly got 0 tuples with 1 fields
> [21964]: raising sqlcode 100 in line 16, 'No data found in line 16.'.
> no data found
> [21964]: ecpg_finish: Connection mm closed.
>
> Looks okay, doesn't it?

Sorry that I didn't mention: I have PostgreSQL 7.4.1 on Slackware 9.1.

Today I tried with a 7.5devel snapshot of 16.02.2004. In this version,
everything works as it should, so I assume that this bug is fixed in the
meantime.

Thank you very much for your help,
    Christian

--
Dr. Christian Rank
Rechenzentrum Universität Passau
Innstr. 33
D-94032 Passau
GERMANY
Tel.: 0851/509-1838
Fax:  0851/509-1802
PGP public key see http://www.rz.uni-passau.de/mitarbeiter/rank


Cant use Win32 API()

From
Karam Chand
Date:
Hello,

I want to implement HAND_CURSOR for my app so I have
ot ifdef SetCursor() and load it accordingly in my
windows app.

Here is the code I am using:

#ifdef _WIN32
    m_HandCursor        = wxCursor ( wxCURSOR_HAND );
#else
    m_HandCursor        = wxCursor ( (WXHCURSOR)    LoadCursor (
NULL, IDC_HAND ) );
#endif

If I compile it is giving me error:

error C2065: 'LoadCursor' : undeclared identifier
error C2065: 'IDC_HAND' : undeclared identifier

I presume that it is not working since I have not
included windows.h. So I go ahead and include it:

#ifdef _WIN32
    #include <windows.h>
#endif

Now, if I compile it is giving me errors in
wxBufferedPaintDC.DrawText() which I am using in my
app. VC 6.0 is giving me:

'DrawTextA' : is not a member of 'wxBufferedPaintDC'
        h:\wxwin\include\wx\dcbuffer.h(85) : see
declaration of 'wxBufferedPaintDC'

Can somebody tell me what I am doing wrong? Am I
missing something

Karam


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com

Re: Cant use Win32 API() ( SORRY .. WRONG LIST )

From
Karam Chand
Date:
Ooooooooooooppss..

I am extremely sorry. I took up the wrong mailing
address from my address book. It should have been
posted to wxWindows mailing list.

Regards
Karam

--- Karam Chand <karam_chand03@yahoo.com> wrote:
> Hello,
>
> I want to implement HAND_CURSOR for my app so I have
> ot ifdef SetCursor() and load it accordingly in my
> windows app.
>
> Here is the code I am using:
>
> #ifdef _WIN32
>     m_HandCursor        = wxCursor ( wxCURSOR_HAND );
> #else
>     m_HandCursor        = wxCursor ( (WXHCURSOR)    LoadCursor (
> NULL, IDC_HAND ) );
> #endif
>
> If I compile it is giving me error:
>
> error C2065: 'LoadCursor' : undeclared identifier
> error C2065: 'IDC_HAND' : undeclared identifier
>
> I presume that it is not working since I have not
> included windows.h. So I go ahead and include it:
>
> #ifdef _WIN32
>     #include <windows.h>
> #endif
>
> Now, if I compile it is giving me errors in
> wxBufferedPaintDC.DrawText() which I am using in my
> app. VC 6.0 is giving me:
>
> 'DrawTextA' : is not a member of 'wxBufferedPaintDC'
>         h:\wxwin\include\wx\dcbuffer.h(85) : see
> declaration of 'wxBufferedPaintDC'
>
> Can somebody tell me what I am doing wrong? Am I
> missing something
>
> Karam
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Search - Find what you�re looking for faster
> http://search.yahoo.com
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose
> an index scan if your
>       joining column's datatypes do not match


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com

Re: ECPG - bug in EXEC SQL WHENEVER NOT FOUND?

From
Bruce Momjian
Date:
Christian Rank wrote:
> > postgres@feivel:/home/postgres/pgsql/src/interfaces/ecpg$ ./a
> > [21964]: ECPGdebug: set to 1
> > [21964]: ECPGconnect: opening database mm on <DEFAULT> port <DEFAULT>
> > [21964]: ECPGexecute line 16: QUERY: select  n   from t    on connection mm
> > [21964]: ECPGexecute line 16: Correctly got 0 tuples with 1 fields
> > [21964]: raising sqlcode 100 in line 16, 'No data found in line 16.'.
> > no data found
> > [21964]: ecpg_finish: Connection mm closed.
> >
> > Looks okay, doesn't it?
>
> Sorry that I didn't mention: I have PostgreSQL 7.4.1 on Slackware 9.1.
>
> Today I tried with a 7.5devel snapshot of 16.02.2004. In this version,
> everything works as it should, so I assume that this bug is fixed in the
> meantime.

And 7.4.2 (unreleased) notes state the fix:

     * Added ecpg WHENEVER NOT_FOUND to     SELECT/INSERT/UPDATE/DELETE

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073