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

From: Andrew McNamara <andrewm(at)object-craft(dot)com(dot)au>
To: Jeff Lynn <jmlynn(at)rogers(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Re: PQgetvalue failed to return column value for non-text data in binary format
Date: 2007-05-23 09:43:47
Message-ID: 20070523094347.64CC3600897@longblack.object-craft.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Jeff Lynn 2007-05-23 15:47:44 Re: How do you convert PostgreSQL internal binary field to C datatypes
Previous Message Alvaro Herrera 2007-05-22 19:24:06 Re: How do you convert PostgreSQL internal binary field to C datatypes