Roby
Roby

Reputation: 2061

c++ mysql connector check resultset is empty

im using the MySQL Connector C++ library and want to check if a query is empty. Ive trief it like this:

  res = stmt->executeQuery("select max(date) from tab");
   if(res->next() == false )
     printf("empty! =? %s\n",  res->getString(1).c_str() );

this wont work. The table is empty and the if statement is always true.

Upvotes: 0

Views: 746

Answers (1)

VMai
VMai

Reputation: 10336

Your query returns without HAVING clause a row, as is usual by using aggregate functions:

Use

SELECT MAX(date) FROM tab HAVING MAX(date) IS NOT NULL;

instead.

Demo

Upvotes: 2

Related Questions