Re: [GENERAL] Question on libpq parameters
On Mon, Dec 1, 2008 at 12:10 AM, Owen Hartnett <[EMAIL PROTECTED]> wrote: > At 1:26 PM -0500 11/30/08, Tom Lane wrote: >> >> Owen Hartnett <[EMAIL PROTECTED]> writes: >>> >>> Yes, it did. I'm confused. My first parameter is a string, but the >>> following two are integers. I thought the paramType parameter >>> indicated the type. Do the integers need to be sprintf'd to strings? >> >> Yes. >> >> Alternatively, you could pass the integers as binary, but that's not >> notation-free either (you need htonl or some such). >> >>regards, tom lane > > Thanks, that did it. I got confused with the binary parameters, and > PQgetvalue returning the binary through a char * when it returns a binary > value. you may want to check out libpqtypes: http://libpqtypes.esilo.com/ http://pgfoundry.org/projects/libpqtypes/ merlin -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Question on libpq parameters
At 1:26 PM -0500 11/30/08, Tom Lane wrote: Owen Hartnett <[EMAIL PROTECTED]> writes: Yes, it did. I'm confused. My first parameter is a string, but the following two are integers. I thought the paramType parameter indicated the type. Do the integers need to be sprintf'd to strings? Yes. Alternatively, you could pass the integers as binary, but that's not notation-free either (you need htonl or some such). regards, tom lane Thanks, that did it. I got confused with the binary parameters, and PQgetvalue returning the binary through a char * when it returns a binary value. -Owen -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Question on libpq parameters
Owen Hartnett <[EMAIL PROTECTED]> writes: > Yes, it did. I'm confused. My first parameter is a string, but the > following two are integers. I thought the paramType parameter > indicated the type. Do the integers need to be sprintf'd to strings? Yes. Alternatively, you could pass the integers as binary, but that's not notation-free either (you need htonl or some such). regards, tom lane -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Question on libpq parameters
At 11:45 PM -0500 11/29/08, Tom Lane wrote: Owen Hartnett <[EMAIL PROTECTED]> writes: 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? You can't just point to integers as if they were strings. Didn't your compiler complain about that? regards, tom lane Yes, it did. I'm confused. My first parameter is a string, but the following two are integers. I thought the paramType parameter indicated the type. Do the integers need to be sprintf'd to strings? There's only one paramValues array and it's type is a const char * array. -Owen -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
Re: [GENERAL] Question on libpq parameters
Owen Hartnett <[EMAIL PROTECTED]> writes: > 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? You can't just point to integers as if they were strings. Didn't your compiler complain about that? regards, tom lane -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general
[GENERAL] Question on libpq parameters
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; } -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general