Обсуждение: PQexecParams not seeing params

Поиск
Список
Период
Сортировка

PQexecParams not seeing params

От
Paul Forgey
Дата:
I am using the libpq client library from 8.1.4 in an application that  
is intended to be compatible with databases hosted on both 7.4 and  
8.1.  At least when talking to a 7.4 server, the following statement:

res = PQexecParams (pgc, "FETCH 100 $1", 1, NULL, paramValues, NULL,  
NULL, 1)

results in "syntax error at or near $1 at character 11".

The documentation says the parameters are referred to in the command  
string as $n.  Is this not always the case?  What am I missing?

since PQexecParams was present in 7.4 I am assuming the server has  
the sufficient protocol level to support it.



Re: PQexecParams not seeing params

От
Tom Lane
Дата:
Paul Forgey <paulf@aphrodite.com> writes:
> At least when talking to a 7.4 server, the following statement:

> res = PQexecParams (pgc, "FETCH 100 $1", 1, NULL, paramValues, NULL,  
> NULL, 1)

> results in "syntax error at or near $1 at character 11".

Well, that would fail regardless because the FETCH syntax requires FROM
or IN between the count and the cursor name; but your big problem is
that parameter symbols can only stand for data values.  Not table names,
not field names, not (as in this case) cursor names.  This must be so
because the backend is supposed to be able to infer the meaning of the
query --- at least to the extent of being able to determine the result
columns, for instance --- before it has the actual values of the
parameters.

You might want to consider assembling the FETCH command as a single
string, along the lines of sprintf(buffer, "FETCH 100 FROM %s", cname)
and sending that.  SQL parameters won't help.
        regards, tom lane