X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2ADA29DC807 for ; Thu, 15 Dec 2005 09:18:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00254-04 for ; Thu, 15 Dec 2005 09:18:13 -0400 (AST) X-Greylist: delayed 00:07:06.404772 by SQLgrey- Received: from smtp.rol.ru (smtp.rol.ru [194.67.1.9]) by postgresql.org (Postfix) with ESMTP id 438C19DCB68 for ; Thu, 15 Dec 2005 09:18:07 -0400 (AST) Received: from 213.33.239.80.adsl-spb.net.rol.ru ([213.33.239.80]:26770 "EHLO mail.nil5.local" smtp-auth: TLS-CIPHER: "DHE-RSA-AES256-SHA keybits 256/256 version TLSv1/SSLv3" TLS-PEER-CN1: ) by gnome08.net.rol.ru with ESMTPS id S2903989AbVLONLE (ORCPT ); Thu, 15 Dec 2005 16:11:04 +0300 Received: from [192.168.17.26] ([192.168.17.26]) by mail.nil5.local with esmtp; Thu, 15 Dec 2005 16:10:59 +0300 Message-ID: <43A16B2D.20203@rambler.ru> Date: Thu, 15 Dec 2005 16:10:05 +0300 From: Oleg Semykin Reply-To: oss-dev@rambler.ru User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: ru-ru, ru MIME-Version: 1.0 To: pgsql-interfaces@postgresql.org Subject: Get double values from binary cursor Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.253 required=5 tests=[RCVD_NUMERIC_HELO=1.253] X-Spam-Score: 1.253 X-Spam-Level: * X-Archive-Number: 200512/28 X-Sequence-Number: 5896 Hi, all. i want to get a double values from binary cursor in libpq < 7.4 it was simple memcpy(&dfVal, PQgetvalue(...), sizeof(dfVal)); but now we have to convert data from MSB to LSB format it is ok for int but how to convert a double i'am tried to write a simple program, but it does not work .... #include #include #include #include typedef unsigned int int4; typedef double float8; int main() { if ( sizeof(int4) * 2 != sizeof(float8) ) { printf("Error"); return 1; } PGconn * conn = PQconnectdb("dbname=test host=localhost user=trusted"); PGresult * res; PQclear( PQexec(conn, "begin; declare my_cur binary cursor for select 123.123;") ); res = PQexec(conn,"fetch 1 from my_cur"); float8 dfVal; float8 dfOrig = 123.123; union { float8 f; int4 n[2]; } swap; memcpy(&(swap.n), PQgetvalue( res, 0, 0 ), sizeof(int4) * 2 ); int4 tmp = ntohl(swap.n[0]); swap.n[0] = ntohl(swap.n[1]); swap.n[1] = tmp; dfVal = swap.f; printf("ret = [%f]\norig = [%f]\n", dfVal, orig); PQclear(res); PQfinish(conn); return 0; } Is something wrong? Thank for any help.