Question on libpq parameters

From: Owen Hartnett <owen(at)clipboardinc(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Question on libpq parameters
Date: 2008-11-30 04:40:44
Message-ID: p06240806c557c8691240@[192.168.0.107]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


The following libpq code chokes on me with invalid input to an
integer parameter (state == PGRES_FATAL_ERR aPtr == "Error: Invalid
Input syntax for integer """ . It fails on the call to
PQexecPrepared. I suspect I'm not doing the parameters right. Can
anyone spot anything wrong?

Thanks,

-Owen

char * getPicture(PGconn * myconnection, char * maplot, int unitno, int bldgno)
{
PGresult * resultant;
Oid paramTypes[3] = { 25, 23, 23 };
ExecStatusType state;

char * sqlquery = "Select image from images where maplot = $1
and unitno = $2 and imageno = $3";

const char * myparamValues[3];
char * aPtr;

myparamValues[0] = maplot;
myparamValues[1] = &unitno;
myparamValues[2] = &bldgno;

resultant = PQprepare(myconnection, "pictureplan", sqlquery ,
3, paramTypes);
if (PQresultStatus(resultant) == PGRES_COMMAND_OK)
{
resultant = PQexecPrepared( myconnection,
"pictureplan", 3, myparamValues, NULL, NULL, 1);
if (PQresultStatus(resultant) == PGRES_TUPLES_OK)
{
aPtr = PQgetvalue(resultant, 0, 0);
return aPtr;
}
else
{
state = PQresultStatus(resultant);
aPtr = PQresultErrorMessage(resultant);
}
}
else
{
state = PQresultStatus(resultant);
aPtr = PQresultErrorMessage(resultant);
}
return NULL;
}

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-11-30 04:45:08 Re: Question on libpq parameters
Previous Message Shane Ambler 2008-11-30 02:52:02 Re: Install question on Mac Leopard Server 10.5