Re: Re: PQgetvalue failed to return column value for non-text data in binary format - Mailing list pgsql-interfaces

From Andrew McNamara
Subject Re: Re: PQgetvalue failed to return column value for non-text data in binary format
Date
Msg-id 20070523094347.64CC3600897@longblack.object-craft.com.au
Whole thread Raw
In response to Re: PQgetvalue failed to return column value for non-text data in binary format  (Jeff Lynn <jmlynn@rogers.com>)
List pgsql-interfaces
>Thank you for your comment about text and binary format.  To use text, I 
>thought one will have to construct the insert sql statement on the fly, 
>which will incurs server parsing, syntax checking followed by 
>execution.  With binary format, I can simply prepare a statement and 
>then update each binded parameter prior to execute the prepared 
>statement over each records.
>
>Is there a way for me to prepare the insert statment and pass in text 
>instead of, say, double precision?  I experimented with that the the 
>server reject the insert statement with "mismatched datatype" error.

Certainly. Whether you use PQexecParams, or PQprepare and PQexecPrepared,
you can pass text or binary parameters. But I would suggest starting
with PQexecParams and getting that right before moving on to prepared
statements.

A overly simple example of PQexecParams usage:
   PGresult        *res;   int                     i;   const int         l = 4;   const char        *param_vals[l];
   param_vals[0] = "10";   param_vals[1] = "20";   param_vals[2] = "30";   param_vals[3] = "40";   res =
PQexecParams(conn,"INSERT INTO foo VALUES ($1,$2,$3,$4)",                      l, NULL, param_vals, NULL, NULL, 0);
 

>Does someone out there has some example(s) of converting the 
>PostgreSQL's internal (network byte order) representation of  float4, 
>flost8, date, datetime and timestamp into Win32 float, double, CTime or 
>any Win32 date/time construct under Intel x86 h/w architecture?

I'd recommend against using binary args until you've got things working
seemlessly with text (and maybe not even then)... I have enough grey
hairs to prove the folly trying to use the binary interface.

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/


pgsql-interfaces by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: How do you convert PostgreSQL internal binary field to C datatypes
Next
From: Jeff Lynn
Date:
Subject: Re: How do you convert PostgreSQL internal binary field to C datatypes