From: Andrew McNamara <andrewm@object-craft.com.au>
To: Jeff Lynn <jmlynn@rogers.com>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: Re: PQgetvalue failed to return column value for non-text data in binary format
Date: Wed, 23 May 2007 19:43:47 +1000
Message-ID: <20070523094347.64CC3600897@longblack.object-craft.com.au> (raw)
In-Reply-To: <465333D1.2020505@rogers.com>
References: <465333D1.2020505@rogers.com>
>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/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: andrewm@object-craft.com.au, jmlynn@rogers.com
Subject: Re: Re: PQgetvalue failed to return column value for non-text data in binary format
In-Reply-To: <20070523094347.64CC3600897@longblack.object-craft.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox