From johan.de.koning@geodan.nl Wed Aug 10 09:34:03 2005 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 98A6E52889 for ; Wed, 10 Aug 2005 06:34:03 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70442-07 for ; Wed, 10 Aug 2005 09:33:54 +0000 (GMT) Received: from mailbin.geodan.nl (unknown [194.109.122.3]) by svr1.postgresql.org (Postfix) with ESMTP id EAD8B5287F for ; Wed, 10 Aug 2005 06:33:52 -0300 (ADT) Received: from flaptop ([192.168.25.184]) by geodan.nl (geodan.nl [194.109.122.3]) (MDaemon.PRO.v8.1.1.R) with ESMTP id md50001466321.msg for ; Wed, 10 Aug 2005 11:34:03 +0200 From: "Johan C. de Koning" To: Subject: Getting oid with libpq Date: Wed, 10 Aug 2005 11:33:35 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0000_01C59D9F.58286390" X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 thread-index: AcWdjpRNJJHHjqUzQPyUd8JnvsuH4w== X-Spam-Processed: geodan.nl, Wed, 10 Aug 2005 11:34:03 +0200 (not processed: message from valid local sender) X-MDRemoteIP: 192.168.25.184 X-Return-Path: johan.de.koning@geodan.nl X-MDaemon-Deliver-To: pgsql-interfaces@postgresql.org Message-Id: <20050810093352.EAD8B5287F@svr1.postgresql.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.755 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, HTML_MESSAGE, MSGID_FROM_MTA_ID X-Spam-Level: * X-Archive-Number: 200508/12 X-Sequence-Number: 5683 This is a multi-part message in MIME format. ------=_NextPart_000_0000_01C59D9F.58286390 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello, I have stored some large objects (which are images) with the lo_import function. Now I can read the images with the other functions like lo_read within libpq. But I have one problem with the oid I have to give to this method. Inside my program I will do a select like this Select texture from building_face where face_id > 100; Textures is the oid field. When I use PQgetValue() I get a complete different value then when I do a select inside pgAdmin. How can I get the same oid so that I can use this for reading the data of the images inside my c++ program. Because it is not working with the oid from PQgetValue. Best regards, Johan de Koning ------=_NextPart_000_0000_01C59D9F.58286390 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello,

 

I have stored some large objects (which are = images) with the lo_import function. Now I can read the images with the other = functions like lo_read within libpq. But I have one problem with the oid I have to = give to this method. Inside my program I will do a select like = this

 

Select texture from building_face where = face_id > 100;

 

Textures is the oid field. When I use = PQgetValue() I get a complete different value then when I do  a select inside pgAdmin. = How can I get the same oid so that I can use this for reading the data of the images = inside my c++ program. Because it is not working with the oid from PQgetValue. =

 

Best regards,

 

Johan de Koning

 

 

------=_NextPart_000_0000_01C59D9F.58286390-- From jtv@xs4all.nl Wed Aug 10 10:52:17 2005 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2F26152C00 for ; Wed, 10 Aug 2005 07:52:17 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82703-01 for ; Wed, 10 Aug 2005 10:52:13 +0000 (GMT) Received: from smtp-vbr13.xs4all.nl (smtp-vbr13.xs4all.nl [194.109.24.33]) by svr1.postgresql.org (Postfix) with ESMTP id 7AA3552A11 for ; Wed, 10 Aug 2005 07:52:11 -0300 (ADT) Received: from webmail.xs4all.nl (webmail12.xs4all.nl [194.109.22.172]) by smtp-vbr13.xs4all.nl (8.13.3/8.13.3) with ESMTP id j7AAqChS075987; Wed, 10 Aug 2005 12:52:12 +0200 (CEST) (envelope-from jtv@xs4all.nl) Received: from 202.47.227.25 by webmail.xs4all.nl with HTTP; Wed, 10 Aug 2005 12:52:12 +0200 (CEST) Message-ID: <10445.202.47.227.25.1123671132.squirrel@202.47.227.25> In-Reply-To: <20050810093352.EAD8B5287F@svr1.postgresql.org> References: <20050810093352.EAD8B5287F@svr1.postgresql.org> Date: Wed, 10 Aug 2005 12:52:12 +0200 (CEST) Subject: Re: Getting oid with libpq From: jtv@xs4all.nl To: "Johan C. de Koning" Cc: pgsql-interfaces@postgresql.org User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.228 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200508/15 X-Sequence-Number: 5686 Johan C. de Koning wrote: > I have stored some large objects (which are images) with the lo_import > function. Now I can read the images with the other functions like lo_read > within libpq. But I have one problem with the oid I have to give to this > method. Inside my program I will do a select like this > Select texture from building_face where face_id > 100; > Textures is the oid field. When I use PQgetValue() I get a complete > different value then when I do a select inside pgAdmin. How can I get the > same oid so that I can use this for reading the data of the images inside > my c++ program. Because it is not working with the oid from PQgetValue. Just a guess, but... One mistake many people make is to cast the char * returned by PQgetValue() to the type they expect to get. Which won't work, since it's a pointer to a value (in this case a number) in a textual format. It needs to be parsed so you get the actual numeric value. Also, when you parse the number, be aware that the standard-library functions (such as sscanf()) take the applicable locale setting into account--which is not what you want in this case. Best reset to the default locale before parsing. Jeroen From johan.de.koning@geodan.nl Wed Aug 10 12:13:17 2005 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C38C152904 for ; Wed, 10 Aug 2005 09:13:17 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 56987-08 for ; Wed, 10 Aug 2005 12:13:07 +0000 (GMT) Received: from mailbin.geodan.nl (unknown [194.109.122.3]) by svr1.postgresql.org (Postfix) with ESMTP id 4ED2B52A83 for ; Wed, 10 Aug 2005 09:13:06 -0300 (ADT) Received: from flaptop ([192.168.25.184]) by geodan.nl (geodan.nl [194.109.122.3]) (MDaemon.PRO.v8.1.1.R) with ESMTP id md50001466587.msg for ; Wed, 10 Aug 2005 14:12:49 +0200 From: "Johan C. de Koning" To: Cc: Subject: Re: Getting oid with libpq Date: Wed, 10 Aug 2005 14:12:15 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 In-Reply-To: <10445.202.47.227.25.1123671132.squirrel@202.47.227.25> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 thread-index: AcWdm59qiOvujspoRJa/ism9kyNHAwACGfgw X-Spam-Processed: geodan.nl, Wed, 10 Aug 2005 14:12:49 +0200 (not processed: message from valid local sender) X-MDRemoteIP: 192.168.25.184 X-Return-Path: johan.de.koning@geodan.nl X-MDaemon-Deliver-To: pgsql-interfaces@postgresql.org Message-Id: <20050810121306.4ED2B52A83@svr1.postgresql.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.217 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, MSGID_FROM_MTA_ID X-Spam-Level: * X-Archive-Number: 200508/16 X-Sequence-Number: 5687 Thanks for you answer, I am not an expert in C/C++ so do you know maybe where I can find some example code or documentation about the parsing process with sscanf? Best regards, Johan de Koning -----Oorspronkelijk bericht----- Van: pgsql-interfaces-owner@postgresql.org [mailto:pgsql-interfaces-owner@postgresql.org] Namens jtv@xs4all.nl Verzonden: woensdag 10 augustus 2005 12:52 Aan: Johan C. de Koning CC: pgsql-interfaces@postgresql.org Onderwerp: Re: [INTERFACES] Getting oid with libpq Johan C. de Koning wrote: > I have stored some large objects (which are images) with the lo_import > function. Now I can read the images with the other functions like lo_read > within libpq. But I have one problem with the oid I have to give to this > method. Inside my program I will do a select like this > Select texture from building_face where face_id > 100; > Textures is the oid field. When I use PQgetValue() I get a complete > different value then when I do a select inside pgAdmin. How can I get the > same oid so that I can use this for reading the data of the images inside > my c++ program. Because it is not working with the oid from PQgetValue. Just a guess, but... One mistake many people make is to cast the char * returned by PQgetValue() to the type they expect to get. Which won't work, since it's a pointer to a value (in this case a number) in a textual format. It needs to be parsed so you get the actual numeric value. Also, when you parse the number, be aware that the standard-library functions (such as sscanf()) take the applicable locale setting into account--which is not what you want in this case. Best reset to the default locale before parsing. Jeroen ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match From jtv@xs4all.nl Thu Aug 11 07:06:43 2005 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CF15F52EBB for ; Thu, 11 Aug 2005 04:06:43 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72625-06 for ; Thu, 11 Aug 2005 07:06:40 +0000 (GMT) Received: from smtp-vbr5.xs4all.nl (smtp-vbr5.xs4all.nl [194.109.24.25]) by svr1.postgresql.org (Postfix) with ESMTP id 61EEE52EB5 for ; Thu, 11 Aug 2005 04:06:39 -0300 (ADT) Received: from webmail.xs4all.nl (webmail12.xs4all.nl [194.109.22.172]) by smtp-vbr5.xs4all.nl (8.13.3/8.13.3) with ESMTP id j7B76brT015956; Thu, 11 Aug 2005 09:06:37 +0200 (CEST) (envelope-from jtv@xs4all.nl) Received: from 202.47.227.25 by webmail.xs4all.nl with HTTP; Thu, 11 Aug 2005 09:06:37 +0200 (CEST) Message-ID: <8327.202.47.227.25.1123743997.squirrel@202.47.227.25> In-Reply-To: <200508101213.j7ACD9lb077874@mxdrop11.xs4all.nl> References: <10445.202.47.227.25.1123671132.squirrel@202.47.227.25> <200508101213.j7ACD9lb077874@mxdrop11.xs4all.nl> Date: Thu, 11 Aug 2005 09:06:37 +0200 (CEST) Subject: Re: Getting oid with libpq From: jtv@xs4all.nl To: "Johan C. de Koning" Cc: jtv@xs4all.nl, pgsql-interfaces@postgresql.org User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.228 tagged_above=0 required=5 tests=[AWL=-0.000, FORGED_RCVD_HELO=0.05, NO_REAL_NAME=0.178] X-Spam-Level: X-Archive-Number: 200508/19 X-Sequence-Number: 5690 Johan C. de Koning wrote: > I am not an expert in C/C++ so do you know maybe where I can find some > example code or documentation about the parsing process with sscanf? In C, you'd probably want to use const char *OldLocale = setlocale(LC_NUMERIC, "C"); Then run the pointer returned by PQgetValue() through atol() to get a numeric value, and finally restore the previous locale with setlocale(LC_NUMERIC, OldLocale); If you're using C++, best thing to do may be to use libpqxx instead of libpq. It has functions to do the conversions for you, and takes care of locale and overflow issues as well. Jeroen From tgl@sss.pgh.pa.us Thu Aug 11 13:57:45 2005 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3C82F52990 for ; Thu, 11 Aug 2005 10:57:45 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31330-02 for ; Thu, 11 Aug 2005 13:57:43 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 8B5EF52986 for ; Thu, 11 Aug 2005 10:57:41 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j7BDvOtw021818; Thu, 11 Aug 2005 09:57:24 -0400 (EDT) To: jtv@xs4all.nl Cc: "Johan C. de Koning" , pgsql-interfaces@postgresql.org Subject: Re: Getting oid with libpq In-reply-to: <8327.202.47.227.25.1123743997.squirrel@202.47.227.25> References: <10445.202.47.227.25.1123671132.squirrel@202.47.227.25> <200508101213.j7ACD9lb077874@mxdrop11.xs4all.nl> <8327.202.47.227.25.1123743997.squirrel@202.47.227.25> Comments: In-reply-to jtv@xs4all.nl message dated "Thu, 11 Aug 2005 09:06:37 +0200" Date: Thu, 11 Aug 2005 09:57:24 -0400 Message-ID: <21817.1123768644@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/20 X-Sequence-Number: 5691 jtv@xs4all.nl writes: > const char *OldLocale = setlocale(LC_NUMERIC, "C"); > Then run the pointer returned by PQgetValue() through atol() to get a > numeric value, and finally restore the previous locale with > setlocale(LC_NUMERIC, OldLocale); Uh ... there is nothing at all locale-sensitive about atol, nor strtoul which is what you really want to use for an OID. regards, tom lane From johan.de.koning@geodan.nl Thu Aug 11 14:09:10 2005 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 80D9552B31 for ; Thu, 11 Aug 2005 11:09:10 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 69668-02 for ; Thu, 11 Aug 2005 14:09:07 +0000 (GMT) Received: from mailbin.geodan.nl (unknown [194.109.122.3]) by svr1.postgresql.org (Postfix) with ESMTP id 1C7B552869 for ; Thu, 11 Aug 2005 11:09:05 -0300 (ADT) Received: from flaptop ([192.168.25.184]) by geodan.nl (geodan.nl [194.109.122.3]) (MDaemon.PRO.v8.1.1.R) with ESMTP id md50001468307.msg for ; Thu, 11 Aug 2005 16:09:03 +0200 From: "Johan C. de Koning" To: "'Tom Lane'" , Cc: Subject: Re: Getting oid with libpq Date: Thu, 11 Aug 2005 16:08:31 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 In-Reply-To: <21817.1123768644@sss.pgh.pa.us> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Thread-Index: AcWefLY1vz1sLwnWTJidnswogqjx3AAATtoA X-Spam-Processed: geodan.nl, Thu, 11 Aug 2005 16:09:03 +0200 (not processed: message from valid local sender) X-MDRemoteIP: 192.168.25.184 X-Return-Path: johan.de.koning@geodan.nl X-MDaemon-Deliver-To: pgsql-interfaces@postgresql.org Message-Id: <20050811140905.1C7B552869@svr1.postgresql.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.193 tagged_above=0 required=5 tests=[AWL=-0.561, FORGED_RCVD_HELO=0.05, MSGID_FROM_MTA_ID=1.704] X-Spam-Level: * X-Archive-Number: 200508/21 X-Sequence-Number: 5692 I tried to use atol but i get always 0 as result. Is this because I use a binary cursor to select the data (there are some PostGIS datatypes inside my resultset which are binary data). Best regards, Johan de Koning -----Oorspronkelijk bericht----- Van: Tom Lane [mailto:tgl@sss.pgh.pa.us] Verzonden: donderdag 11 augustus 2005 15:57 Aan: jtv@xs4all.nl CC: Johan C. de Koning; pgsql-interfaces@postgresql.org Onderwerp: Re: [INTERFACES] Getting oid with libpq jtv@xs4all.nl writes: > const char *OldLocale = setlocale(LC_NUMERIC, "C"); > Then run the pointer returned by PQgetValue() through atol() to get a > numeric value, and finally restore the previous locale with > setlocale(LC_NUMERIC, OldLocale); Uh ... there is nothing at all locale-sensitive about atol, nor strtoul which is what you really want to use for an OID. regards, tom lane From jtv@xs4all.nl Sat Aug 13 06:20:10 2005 X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7E318530A3 for ; Sat, 13 Aug 2005 03:20:10 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 80912-08 for ; Sat, 13 Aug 2005 06:20:08 +0000 (GMT) Received: from smtp-vbr3.xs4all.nl (smtp-vbr3.xs4all.nl [194.109.24.23]) by svr1.postgresql.org (Postfix) with ESMTP id B567D5309C for ; Sat, 13 Aug 2005 03:20:04 -0300 (ADT) Received: from webmail.xs4all.nl (webmail12.xs4all.nl [194.109.22.172]) by smtp-vbr3.xs4all.nl (8.13.3/8.13.3) with ESMTP id j7D6K2mD093176; Sat, 13 Aug 2005 08:20:02 +0200 (CEST) (envelope-from jtv@xs4all.nl) Received: from 203.170.164.130 by webmail.xs4all.nl with HTTP; Sat, 13 Aug 2005 08:20:02 +0200 (CEST) Message-ID: <22138.203.170.164.130.1123914002.squirrel@203.170.164.130> In-Reply-To: <20050811140905.1C7B552869@svr1.postgresql.org> References: <21817.1123768644@sss.pgh.pa.us> <20050811140905.1C7B552869@svr1.postgresql.org> Date: Sat, 13 Aug 2005 08:20:02 +0200 (CEST) Subject: Re: Getting oid with libpq From: jtv@xs4all.nl To: "Johan C. de Koning" Cc: "'Tom Lane'" , jtv@xs4all.nl, pgsql-interfaces@postgresql.org User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by XS4ALL Virus Scanner X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.228 tagged_above=0 required=5 tests=[FORGED_RCVD_HELO=0.05, NO_REAL_NAME=0.178] X-Spam-Level: X-Archive-Number: 200508/26 X-Sequence-Number: 5697 > I tried to use atol but i get always 0 as result. Is this because I use a > binary cursor to select the data (there are some PostGIS datatypes inside > my resultset which are binary data). That changes everything. With a binary cursor you get all data in a binary format which "I'm sure is documented somewhere." I believe in the case of oids it's a 32-bit integer in network (big-endian) byte order. If that is indeed the case, you should be able to read the oid as "ntohl(*(uint32_t *)PQgetValue(...))". On a side note, I don't think you actually need a binary cursor to transfer binary data (apart from the fact that it's likely to improve performance). Jeroen