[GENERAL] Prepared statements aren't working with parameters with PQexecParams

2008-09-05 Thread Subspace god
The following works executed in the query browser:

PREPARE myquery (text) AS INSERT INTO myTable (word) VALUES ($1);
EXECUTE myquery('blah');

The following works in C++, executed as two statements with PQexecParams
using PQEXECPARAM_FORMAT_BINARY

PREPARE myquery AS INSERT INTO myTable (word) VALUES ('blah');
EXECUTE myquery;

The following does not work in C++, executed as above, in another session
using two subsequent calls to PQexecParams

PREPARE myquery (text) AS INSERT INTO myTable (word) VALUES ($1);
EXECUTE myquery($1::text);

The error is:

+lastError0x00dc4232 ERROR:  bind message supplies 1
parameters, but prepared statement  requires 0
char [1024]

Code is:

PQexecParams(pgConn,
query.C_String(),indices.Size(),0,paramData,paramLength,paramFormat,PQEXECPARAM_FORMAT_BINARY);

Parameters:

+paramData[0]0x00e00208 blahchar *
paramLength[0]4int
paramFormat[0]1int
indices.Size()1unsigned int

The difference between the two C++ calls is that the 2nd call has parameters
passed to the prepared statement, while the first does not.

Any ideas? Note that it is saying that the prepared statement is , rather
than the name of the prepared statement. It also says 0 parameters, although
it takes 1 parameter.


Re: [GENERAL] Prepared statements aren't working with parameters with PQexecParams

2008-09-05 Thread David Wilson
On Fri, Sep 5, 2008 at 2:52 AM, Subspace god [EMAIL PROTECTED] wrote:

 The following does not work in C++, executed as above, in another session
 using two subsequent calls to PQexecParams

 PREPARE myquery (text) AS INSERT INTO myTable (word) VALUES ($1);
 EXECUTE myquery($1::text);

You're doing prepared statements incorrectly. Use PQprepare() and
PQexecPrepared() when using them from libpq; don't do them by hand on
your own.

-- 
- David T. Wilson
[EMAIL PROTECTED]

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general