logo       

Help with returning data type: msg#00057

Subject: Help with returning data type
Help with returning data type

Hi.

I'm in trouble with data type returns using libpq (PQgetvalue)

see table definition
-  datname name NOT NULL,
-  encoding int4 NOT NULL,
-  datistemplate bool NOT NULL,
-  datallowconn bool NOT NULL,

I codify with this way in C

 static long long_ret;
 static u_long ulong_ret;
 static unsigned char string[SPRINT_MAX_LEN];
 static oid objid[MAX_OID_LEN];
 static struct counter64 c64;
 int i, index;
 char* bytea;

*       // 1 - THIS WORKS (retrieving varchar)
*
strcpy(query_string, "SELECT datname FROM pg_database limit 1 offset 0"); res = PQexec(conn, query_string); if (PQresultStatus(res) != PGRES_TUPLES_OK){
           fprintf(stderr, "SELECT query failed [%s].\n", query_string);
           PQclear(res);
           return;
       }
       i = 0;
       bytea = PQgetvalue(res, i, 0);
       PQclear(res);
       strcpy(string, bytea);
       *var_len = strlen(string);
       return (unsigned char *) string;

*       // 2 - THIS WORKS (retrieving int4)
*
strcpy(query_string, "SELECT encoding FROM pg_database limit 1 offset 0"); res = PQexec(conn, query_string); if (PQresultStatus(res) != PGRES_TUPLES_OK){
           fprintf(stderr, "SELECT query failed [%s].\n", query_string);
           PQclear(res);
           return;
       }
       i = 0;
       bytea = PQgetvalue(res, i, 0);
       index = atoi(bytea);
       PQclear(res);
       switch (index){
       case 0: strcpy(string, "SQL_ASCII"); break;
       case 1: strcpy(string, "EUC_JP"); break;
       ...
       case 33: strcpy(string, "GB18030"); break;
       }
       *var_len = strlen(string);
       return (unsigned char *) string;

*       // 3 - THIS **DONT **WORK (retrieving bool)
*** long_ret = 0; strcpy(query_string, "SELECT datistemplate FROM pg_database limit 1 offset 0"); res = PQexec(conn, query_string); if (PQresultStatus(res) != PGRES_TUPLES_OK){
           fprintf(stderr, "SELECT query failed [%s].\n", query_string);
           PQclear(res);
           return;
       }
       i = 0;
       bytea = PQgetvalue(res, i, 0);
       long_ret = atol(bytea);
return (unsigned char *) &long_ret;

How can I retrieve a bool data type (code 3)?
How can I return for a string C data type (return (unsigned char *) &long_ret;)
and the last question
although working, its correct list code 1 and list code 2?
anybody has code sample to share (mail me)?

thank you for any help, my deadline paper is near and has proposed the open source MIB for postgresql database!
thank you!

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to majordomo@xxxxxxxxxxxxxx)



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe