agora inbox for pgsql-interfaces@postgresql.org  
help / color / mirror / Atom feed
From: Satoshi Nagayasu <satoshi.nagayasu@gmail.com>
To: pgsql-interfaces@postgresql.org
Subject: SQLDA question
Date: Tue, 22 Jun 2010 16:57:12 +0900
Message-ID: <4C206CD8.7050801@gmail.com> (raw)

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 ; i<sqlda1->sqld ; 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 <satoshi.nagayasu@gmail.com>



view thread (2+ messages)  latest in thread

Message-ID: <4C206CD8.7050801@gmail.com>
Permalink:  ../4C206CD8.7050801@gmail.com/
Also on:    postgresql.org/message-id/4C206CD8.7050801@gmail.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: satoshi.nagayasu@gmail.com
  Subject: Re: SQLDA question
  In-Reply-To: <4C206CD8.7050801@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox