PQntuples and PQgetvalue problem.

From: zafer yagmuroglu <yagmurogluzafer(at)hotmail(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: PQntuples and PQgetvalue problem.
Date: 2012-10-05 13:15:16
Message-ID: BAY159-W41C5D56FF654129F424EFDA18B0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello,

In my C++ program, i want to partition sql table, there is sample code below. It is working right. the problem is after func called 2 or 3 times in func1, PQntuples results 0 although tablename exist. Also when i disabled PQntuples at if statement, other psql function PQgetvalue(res) return error that is "row number 0 is out of range 0..-1there are a couple function call same as func1(to check tablename ), at func. when i disabled one of them another at PQntuples funcx return 0. i check so may times. it is so weird.
So i think you can help me.
Best regards.
Zafer,

Sample code :

func1{
char cmd[100] = "";
snprintf(cmd,sizeof(cmd),"select tablename from pg_tables where tablename='%s'", tablename);

PGresult *res = PQexec(conn, cmd );

if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
logger.error("PQexec: %s", PQerrorMessage(conn));
PQclear(res);
wexit(1);
}

if (PQntuples(res) == 0)
//
}

func {
PGresult *res;
func1();
res=PQexec(conn,"Select count(*) from persons");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
printf("PQexec: %s", PQerrorMessage(conn));
PQclear(res);
exit(1);
}
if( atoi(PQgetvalue(res,0,0)) != 0)
// some code PQexec()} }

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message zafer yagmuroglu 2012-10-05 13:36:12 FW: PQntuples and PQgetvalue problem.
Previous Message Dimitri Fontaine 2012-10-05 12:48:32 Deparsing DDL command strings