Re: PQexecParams and CURSOR

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: PQexecParams and CURSOR
Дата
Msg-id 20050116003215.GA11076@winnie.fuhr.org
обсуждение исходный текст
Ответ на PQexecParams and CURSOR  ("Laurent Marzullo" <laurent.marzullo@atosorigin.com>)
Ответы Re: PQexecParams and CURSOR  ("Laurent Marzullo" <laurent.marzullo@atosorigin.com>)
Список 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 по дате отправления:

Предыдущее
От: Edmund Dengler
Дата:
Сообщение: Re: Multi-column indexes
Следующее
От: "Jim C. Nasby"
Дата:
Сообщение: Re: Index optimization ?