X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B292E8BA155 for ; Wed, 16 Feb 2005 12:08:37 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24428-03 for ; Wed, 16 Feb 2005 12:08:29 +0000 (GMT) Received: from svrmail.lasalle.tche.br (mail.lasalle.tche.br [200.132.228.4]) by svr1.postgresql.org (Postfix) with ESMTP id E40728B9CAA for ; Wed, 16 Feb 2005 12:08:27 +0000 (GMT) Received: from localhost (unknown [127.0.0.1]) by svrmail.lasalle.tche.br (Postfix) with ESMTP id 581042BE7A for ; Wed, 16 Feb 2005 10:08:20 -0200 (BRDT) Received: from svrmail.lasalle.tche.br ([127.0.0.1]) by localhost (svrmail.lasalle.tche.br [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 85643-04 for ; Wed, 16 Feb 2005 10:08:18 -0200 (BRDT) Received: from [10.10.1.211] (unknown [10.10.1.211]) by svrmail.lasalle.tche.br (Postfix) with ESMTP id F1A622BCC8 for ; Wed, 16 Feb 2005 10:08:17 -0200 (BRDT) Message-ID: <42134572.7040503@unilasalle.edu.br> Date: Wed, 16 Feb 2005 10:06:58 -0300 From: Rudinei Dias X-Accept-Language: pt-br, pt MIME-Version: 1.0 To: pgsql-interfaces@postgresql.org Subject: Help with returning data type Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by Amavisd-new X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200502/59 X-Sequence-Number: 5304 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!