Re: sqlstate 02000 while declaring cursor/freeing statement

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "Thomas F(dot) O'Connell" <tfo(at)sitening(dot)com>
Cc: andy rost <andy(dot)rost(at)noaa(dot)gov>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sqlstate 02000 while declaring cursor/freeing statement
Date: 2005-08-30 15:13:20
Message-ID: 20050830151320.GA56850@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Tue, Aug 30, 2005 at 09:01:36AM -0500, Thomas F. O'Connell wrote:
> On Aug 29, 2005, at 2:19 PM, andy rost wrote:
> >
> > $declare loop1 cursor with hold for
> > select distinct ( tabname )
> > from meta ;
> >
> >results in sqlca.sqlcode = 100 and sqlca.sqlstate = '02000'
>
> [snip]
>
> I don't see anything wrong with your cursor declaration, so this just
> looks like it's indicating that no rows were returned.

See my response to the same thread in pgsql-sql about what's
happening:

http://archives.postgresql.org/pgsql-sql/2005-08/msg00274.php

The ECPG code generator doesn't issue the DECLARE statement until
the cursor is opened, so checking sqlcode/sqlstate immediately after
DECLARE but before OPEN will get the error code values from a
previous command.

Here's an excerpt from the DECLARE documentation:

The PostgreSQL server does not implement an OPEN statement for
cursors; a cursor is considered to be open when it is declared.
However, ECPG, the embedded SQL preprocessor for PostgreSQL,
supports the standard SQL cursor conventions, including those
involving DECLARE and OPEN statements.

Since declaring a cursor in PostgreSQL also opens it, ECPG apparently
defers doing anything with the cursor until it finds the OPEN
statement (i.e., EXEC SQL DECLARE generates no code, and EXEC SQL
OPEN generates a DECLARE).

--
Michael Fuhr

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Thomas F. O'Connell 2005-08-30 15:13:48 Re: Numerical variables in pqsql statements
Previous Message Thomas F. O'Connell 2005-08-30 14:01:36 Re: sqlstate 02000 while declaring cursor/freeing statement