SQLDA question
От | Satoshi Nagayasu |
---|---|
Тема | SQLDA question |
Дата | |
Msg-id | 4C206CD8.7050801@gmail.com обсуждение исходный текст |
Ответы |
Re: SQLDA question
|
Список | 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 NEXTFROM 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>
В списке pgsql-interfaces по дате отправления: