PQntuples and PQgetvalue problem. - Mailing list pgsql-hackers

From zafer yagmuroglu
Subject PQntuples and PQgetvalue problem.
Date
Msg-id BAY159-W41C5D56FF654129F424EFDA18B0@phx.gbl
Whole thread Raw
Responses Re: PQntuples and PQgetvalue problem.  (Robert Haas <robertmhaas@gmail.com>)
List 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..-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()
}
    }

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: more suitable messages for analyze on hot standby.
Next
From: Tomonari Katsumata
Date:
Subject: error message is not proper for analyze on standby.