Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 7F0179FB6F0 for ; Wed, 23 May 2007 06:43:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 34397-09 for ; Wed, 23 May 2007 06:43:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from syd.object-craft.com.au (ppp167-236-184.static.internode.on.net [59.167.236.184]) by postgresql.org (Postfix) with ESMTP id 2E77F9FB5F1 for ; Wed, 23 May 2007 06:43:50 -0300 (ADT) Received: by longblack.object-craft.com.au (Postfix, from userid 1000) id 64CC3600897; Wed, 23 May 2007 19:43:47 +1000 (EST) Received: from longblack (localhost [127.0.0.1]) by longblack.object-craft.com.au (Postfix) with ESMTP id 4AB44600896; Wed, 23 May 2007 19:43:47 +1000 (EST) To: Jeff Lynn cc: pgsql-interfaces@postgresql.org Subject: Re: Re: PQgetvalue failed to return column value for non-text data in binary format In-reply-to: <465333D1.2020505@rogers.com> References: <465333D1.2020505@rogers.com> Comments: In-reply-to Jeff Lynn message dated "Tue, 22 May 2007 14:17:53 -0400." Date: Wed, 23 May 2007 19:43:47 +1000 From: Andrew McNamara Message-Id: <20070523094347.64CC3600897@longblack.object-craft.com.au> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/46 X-Sequence-Number: 6553 >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/