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..-1
there 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()
}
}