Re: PQexecParams and CURSOR - Mailing list pgsql-general

From Michael Fuhr
Subject Re: PQexecParams and CURSOR
Date
Msg-id 20050116003215.GA11076@winnie.fuhr.org
Whole thread Raw
In response to PQexecParams and CURSOR  ("Laurent Marzullo" <laurent.marzullo@atosorigin.com>)
Responses Re: PQexecParams and CURSOR
List pgsql-general
On Fri, Jan 14, 2005 at 12:31:24PM +0100, Laurent Marzullo wrote:

> paramValues[0] = "2";    // This is the parameter for the query
>
> res = PQexecParams( conn ,
>   "DECLARE MY_CURSOR FOR "
>   "SELECT * FROM GRGL.RANGE_MODIFIER "
>   "WHERE WEAPON_ID = $1",
>   1,
>   NULL,
>   paramValues,
>   NULL,
>   NULL,
>   0);

Are you checking the result status of this command?  If so, what
does your error checking code look like?  In 8.0.0rc5 this command
fails due to the missing keyword CURSOR before FOR.

> res = PQexec( conn , "FETCH 1 FROM MY_CURSOR" );
>
> => Error
> FETCH failed: ERROR:  no value found for parameter 1

Again, what does your error checking code look like?  If I correct
the syntax error in the DECLARE statement above then this query
succeeds.

> res = PQexecParams( conn ,
>   "FETCH 1 FROM MY_CURSOR",
>   1,
>   NULL,
>   paramValues,
>   NULL,
>   NULL,
>   0);
>
> => Error:
> FETCH failed: ERROR:  bind message supplies 1 parameters, but prepared
> statement "" requires 0

The error tells you what's wrong: you're supplying parameters that
the SQL statement isn't looking for.  Change the nParams value from
1 to 0 and pass NULL instead of paramValues, or use PQexec() instead
of PQexecParams() since you're not passing any parameters.

If you still have trouble then please post a minimal but complete
program so we can see everything you're doing.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Edmund Dengler
Date:
Subject: Re: Multi-column indexes
Next
From: "Jim C. Nasby"
Date:
Subject: Re: Index optimization ?