Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[INTERFACES] SQLDA question

0 views
Skip to first unread message

Satoshi Nagayasu

unread,
Jun 22, 2010, 3:57:12 AM6/22/10
to
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....@gmail.com>

--
Sent via pgsql-interfaces mailing list (pgsql-in...@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-interfaces

Satoshi Nagayasu

unread,
Jun 22, 2010, 9:36:50 PM6/22/10
to
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,

0 new messages