Prepared statements aren't working with parameters with PQexecParams

From: "Subspace god" <subspacegod(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Prepared statements aren't working with parameters with PQexecParams
Date: 2008-09-05 06:52:05
Message-ID: 5caaea670809042352l7486eacexcc04a6ac9725fc0d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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:

+ lastError 0x00dc4232 "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 "blah" char *
paramLength[0] 4 int
paramFormat[0] 1 int
indices.Size() 1 unsigned 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ow Mun Heng 2008-09-05 07:07:42 Range Partititioning & Constraint Exclusion Oddities
Previous Message Paul Shapley 2008-09-05 06:45:30 Cannot connect to server