X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 9E92DD1C9F6 for ; Tue, 23 Sep 2003 16:45:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 18588-07 for ; Tue, 23 Sep 2003 13:45:08 -0300 (ADT) Received: from mxzilla2.xs4all.nl (mxzilla2.xs4all.nl [194.109.6.50]) by svr1.postgresql.org (Postfix) with ESMTP id 28E35D1C9E3 for ; Tue, 23 Sep 2003 13:45:07 -0300 (ADT) Received: from xs1.xs4all.nl (xs1.xs4all.nl [194.109.3.11]) by mxzilla2.xs4all.nl (8.12.3/8.12.3) with ESMTP id h8NGj519070727; Tue, 23 Sep 2003 18:45:05 +0200 (CEST) Received: from xs1.xs4all.nl (jtv@localhost.xs4all.nl [127.0.0.1]) by xs1.xs4all.nl (8.12.9/8.12.9) with ESMTP id h8NGj5dN073271; Tue, 23 Sep 2003 18:45:05 +0200 (CEST) (envelope-from jtv@xs4all.nl) Received: (from Unknown UID 8109@localhost) by xs1.xs4all.nl (8.12.9/8.12.9/Submit) id h8NGj4BF073270; Tue, 23 Sep 2003 18:45:04 +0200 (CEST) (envelope-from jtv) Date: Tue, 23 Sep 2003 18:45:04 +0200 From: "Jeroen T. Vermeulen" To: Roman Bogorodskiy Cc: pgsql-interfaces@postgresql.org Subject: Re: troubles with getting data from tables Message-ID: <20030923164504.GA70502@xs4all.nl> Mail-Followup-To: Roman Bogorodskiy , pgsql-interfaces@postgresql.org References: <20030923201750.7cacf851.bogorodskiy@inbox.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030923201750.7cacf851.bogorodskiy@inbox.ru> User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/59 X-Sequence-Number: 4477 On Tue, Sep 23, 2003 at 08:17:50PM +0400, Roman Bogorodskiy wrote: > sprintf(query, "SELECT * FROM users WHERE name=\'%s\';", login); > if (PQntuples(res) == 1) { > int uid_field_index; > unsigned int *uid; > > uid_field_index = PQfnumber(res, "uid"); First off, a question: why don't you just select the field you want, so you know its index in the result set? That'll probably transport less data, save you that PQfnumber() call, and make your code shorter and more readable. > uid = (int *) PQgetvalue(res, 0, uid_field_index); > But instead of '1001' "uid" value is '134820376'. Where I was wrong? The pointer you're getting is a pointer-to-char, i.e. a string. Unless you explicitly enabled the "binary tuples" option, what you're getting is exactly that: a string. But instead of parsing the string, you're casting its base pointer to pointer-to-int! Jeroen