Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id EF70A633072 for ; Tue, 22 Jun 2010 22:36:57 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 70436-01 for ; Wed, 23 Jun 2010 01:36:48 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-px0-f174.google.com (mail-px0-f174.google.com [209.85.212.174]) by mail.postgresql.org (Postfix) with ESMTP id 4BAA863353E for ; Tue, 22 Jun 2010 22:36:50 -0300 (ADT) Received: by pxi7 with SMTP id 7so71790pxi.19 for ; Tue, 22 Jun 2010 18:36:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=yifqEtkrzjSBApPEwwsg65aHeZNuHWZ48I9M28zle10=; b=pAi6FMXMOUKIhZP7pYMcng0j4C5GPyAvPuzc13hwfFGqbxjW7gf6KJ0sDz904p0XSO 8bqSrwmp9Pp667RX4+J8Xg0USv/NbukF0snO0BB1ijpjinj7vi1Kr9Qc2vFDX7NiAsac lr78GEteF9aA+Pqlsdav39mU/peB6mzNnNRjM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=quc5j2TFA3+hgzVibEUbG7LqrwIix38UTyrDHdnfIJmWuRwQK85SUdJpe2D9r75cDr UjLvHdsJZa9Up9HSD/TvMbnIe6umsgYWHiA+14zUv6Mf+T1IRtx3QOOA2wAXsC4PANNU oKBvjtsoRGc09+LKo34BlF0cHpscYCC35Gtzc= Received: by 10.142.55.19 with SMTP id d19mr6184065wfa.163.1277257008024; Tue, 22 Jun 2010 18:36:48 -0700 (PDT) Received: from [10.0.2.101] (p0245ed.tokyff01.ap.so-net.ne.jp [121.2.69.237]) by mx.google.com with ESMTPS id q10sm3099493rvp.8.2010.06.22.18.36.45 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 22 Jun 2010 18:36:46 -0700 (PDT) Message-ID: <4C216532.1000300@gmail.com> Date: Wed, 23 Jun 2010 10:36:50 +0900 From: Satoshi Nagayasu User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.1.10) Gecko/20100512 Thunderbird/3.0.5 MIME-Version: 1.0 To: pgsql-interfaces@postgresql.org Subject: Re: SQLDA question References: <4C206CD8.7050801@gmail.com> In-Reply-To: <4C206CD8.7050801@gmail.com> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201006/14 X-Sequence-Number: 6915 Hi all, Finally, I have found that the values are coming in binary forms, not string forms. So I was misunderstanding. > (By the way, all values are represented as string form > in sqlvar.sqldata, right?) This is wrong. I have to parse the binary forms when retreiving number values. So here is my example. If you're interested in, please check it out. test_desc3.pgc http://gist.github.com/449338 Regards, On 2010/06/22 16:57, Satoshi Nagayasu wrote: > Hi all, > > I'm trying SQLDA features, and I'm encountered strange thing > which I can't solve. > > In my sample code, I retreived some records from the pg_database > table, and dump all columns of the records. > > Almost works well, but the "datconnlimit" column shows > a string "????" instead of the correct value. > (See below for more details.) > > I think it should show "-1". > (By the way, all values are represented as string form > in sqlvar.sqldata, right?) > > Why does it happen? Any suggestions? > > Here are my sample code, the result of execution and the correct table. > -------------------------------------------------------------- > EXEC SQL include sqlda.h; > > sqlda_t *sqlda1; > > int > main(void) > { > EXEC SQL CONNECT TO uptimedb AS con1 USER uptime; > > EXEC SQL DECLARE cur CURSOR FOR SELECT * FROM pg_database; > EXEC SQL OPEN cur; > > EXEC SQL WHENEVER NOT FOUND DO BREAK; > > while (1) { > /* Open a cursor and assign descriptor to the cursor */ > EXEC SQL FETCH NEXT FROM cur INTO DESCRIPTOR sqlda1; > > while (1) { > int i; > char name_buf[1024]; > char var_buf[1024]; > > for (i=0 ; isqld ; i++) { > sqlvar_t v = sqlda1->sqlvar[i]; > char *sqldata = v.sqldata; > short sqllen = v.sqllen; > > strncpy(name_buf, v.sqlname.data, v.sqlname.length); > name_buf[v.sqlname.length] = '\0'; > > strncpy(var_buf, sqldata, sqllen); > var_buf[sqllen] = '\0'; > printf("%s = %s, (type:%d)\n", name_buf, var_buf, v.sqltype); > } > printf("\n"); > > if ( sqlda1->desc_next==NULL ) > break; > } > } > EXEC SQL CLOSE cur; > EXEC SQL COMMIT; > EXEC SQL DISCONNECT ALL; > return (0); > } > -------------------------------------------------------------- > [snaga@devwa02 test]$ ./test_desc3 > datname = template1, (type:1) > datdba = 10, (type:1) > encoding = , (type:5) > datistemplate = t, (type:1) > datallowconn = t, (type:1) > datconnlimit = ????, (type:5) > datlastsysoid = 11510, (type:1) > datfrozenxid = 379, (type:1) > dattablespace = 1663, (type:1) > datconfig = , (type:1) > datacl = {=c/uptime,uptime=CTc/uptime}, (type:1) > > datname = template0, (type:1) > datdba = 10, (type:1) > encoding = , (type:5) > datistemplate = t, (type:1) > datallowconn = f, (type:1) > datconnlimit = ????, (type:5) > datlastsysoid = 11510, (type:1) > datfrozenxid = 379, (type:1) > dattablespace = 1663, (type:1) > datconfig = , (type:1) > datacl = {=c/uptime,uptime=CTc/uptime}, (type:1) > > datname = postgres, (type:1) > datdba = 10, (type:1) > encoding = , (type:5) > datistemplate = f, (type:1) > datallowconn = t, (type:1) > datconnlimit = ????, (type:5) > datlastsysoid = 11510, (type:1) > datfrozenxid = 379, (type:1) > dattablespace = 1663, (type:1) > datconfig = , (type:1) > datacl = , (type:1) > > datname = uptimedb, (type:1) > datdba = 10, (type:1) > encoding = , (type:5) > datistemplate = f, (type:1) > datallowconn = t, (type:1) > datconnlimit = ????, (type:5) > datlastsysoid = 11510, (type:1) > datfrozenxid = 379, (type:1) > dattablespace = 1663, (type:1) > datconfig = , (type:1) > datacl = , (type:1) > > datname = testdb, (type:1) > datdba = 10, (type:1) > encoding = , (type:5) > datistemplate = f, (type:1) > datallowconn = t, (type:1) > datconnlimit = ????, (type:5) > datlastsysoid = 11510, (type:1) > datfrozenxid = 379, (type:1) > dattablespace = 1663, (type:1) > datconfig = , (type:1) > datacl = , (type:1) > > [snaga@devwa02 test]$ > -------------------------------------------------------------- > uptimedb=# SELECT * FROM pg_database ; > datname | datdba | encoding | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace | datconfig | datacl > -----------+--------+----------+---------------+--------------+--------------+---------------+--------------+---------------+-----------+------------------------------- > template1 | 10 | 0 | t | t | -1 | 11510 | 379 | 1663 | | {=c/uptime,uptime=CTc/uptime} > template0 | 10 | 0 | t | f | -1 | 11510 | 379 | 1663 | | {=c/uptime,uptime=CTc/uptime} > postgres | 10 | 0 | f | t | -1 | 11510 | 379 | 1663 | | > uptimedb | 10 | 6 | f | t | -1 | 11510 | 379 | 1663 | | > testdb | 10 | 0 | f | t | -1 | 11510 | 379 | 1663 | | > (5 rows) > > uptimedb=# > -------------------------------------------------------------- > -- NAGAYASU Satoshi