From: | Satoshi Nagayasu <satoshi(dot)nagayasu(at)gmail(dot)com> |
---|---|
To: | pgsql-interfaces(at)postgresql(dot)org |
Subject: | SQLDA question |
Date: | 2010-06-22 07:57:12 |
Message-ID: | 4C206CD8.7050801@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
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(at)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(at)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(dot)nagayasu(at)gmail(dot)com>
From | Date | Subject | |
---|---|---|---|
Next Message | Satoshi Nagayasu | 2010-06-23 01:36:50 | Re: SQLDA question |
Previous Message | Tom Lane | 2010-06-20 15:11:29 | Re: Initial database size on disk |