X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id A9E6DD1B52D for ; Thu, 30 Oct 2003 15:11:30 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 70970-04 for ; Thu, 30 Oct 2003 11:11:03 -0400 (AST) Received: from mail.netbcg.com (ip-216-46-80-134.dsl.ewr.megapath.net [216.46.80.134]) by svr1.postgresql.org (Postfix) with SMTP id 0A089D1B51A for ; Thu, 30 Oct 2003 11:10:59 -0400 (AST) Received: (qmail 4975 invoked from network); 30 Oct 2003 15:11:03 -0000 Received: from ip-216-46-80-134.dsl.ewr.megapath.net (HELO genesis) (216.46.80.134) by 0 with SMTP; 30 Oct 2003 15:11:03 -0000 From: "creid" To: Subject: PGEASY QUESTION Date: Thu, 30 Oct 2003 10:11:23 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal In-Reply-To: <200310270925.26056.igor@carcass.ath.cx> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/58 X-Sequence-Number: 4547 I am experimenting with LIBPGEASY Problem: When I access a "varchar(30)" column using "DECLARE.....FOR SELECT= column from schema.table WHERE pkey=3D'KEY'" When I fetch to a declared variable to return to a calling procedure, my pr= ogram does a (segmentation error) unless I declare the char variable to som= e much higher value than it is seemingly necessary. Moreover, the problem = does not occur when I manipulate the result in the called procedure. In fa= ct, in my experimentation, I have noticed that I can declare a char variabl= e array less than what the result is and it still works. The crash only oc= curs in the calling procedure. What might I be doing wrong? Thanks Cliff -----Original Message----- From: pgsql-interfaces-owner@postgresql.org [mailto:pgsql-interfaces-owner@postgresql.org]On Behalf Of Igor Shevchenko Sent: Monday, October 27, 2003 2:25 AM To: Tomasz Myrta Cc: pgsql-interfaces@postgresql.org Subject: Re: [INTERFACES] LIBPQ Question On Monday 27 October 2003 09:15, Tomasz Myrta wrote: > Dnia 2003-10-27 00:08, U=C5=BCytkownik creid napisa=C5=82: > > Problem: Assigning a COUNT(*) result into an integer variable in my C > > program consistently fails except when I assign the same result to a ch= ar > > variable. I can only assume that the internal data type the COUNT > > function uses is integer. > > > > Can anyone help put me in the proper mindset so I may deal with this, > > seemingly simple issue, to resolution. > > > > I need the integer result to to help me satisfy a dynamic memory > > requirement... COUNT(*) result will tell me how many rows of data I need > > to malloc and I cannot perform a math operation on a char variable. > > All libpq results are strings. > some_int_value=3Datoi(PQgetvalue(...)) Not true anymore with protocol v3, which added the binary format. Text form= at=20 is still the default. > Anyway why do you need count(*) ? When you retrieve your rows, you can > always check how many are them using PQntuples(...) and then malloc your > memory tables. > > Regards, > Tomasz Myrta > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match --=20 Best regards, Igor Shevchenko ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly