Link to home
Start Free TrialLog in
Avatar of msanoop
msanoop

asked on

silly doubt in mysql c api program

Hi friends,
      First of all thanks for everyone who had helpe me in writing the program using mysql api. I have completed almosy every part. Now one part remains. How can I capture the case of an empty result set returned by the "SELECT query" to show the info " INFO:: EMPTY result set" back to the user. I am using the below query to retreive the rows...I tried mysql_fetch_row, and mysql_field_count function, but can't capture an empty result set.


t=mysql_real_query(mysql,query,(unsigned int) strlen(query));
   if (t)
   {
      printf("Error making query: %s\n",
              mysql_error(mysql));
   }
   else printf("Query made...\n");
   res=mysql_use_result(mysql);
   for(r=0;r<=mysql_field_count(mysql);r++){
           row=mysql_fetch_row(res);
           if(row<0) break;
           for(t=0;t<mysql_num_fields(res);t++){
                   printf("%s ",row[t]);
           }
           printf("\n");
   }

regards

NP
ASKER CERTIFIED SOLUTION
Avatar of joele23
joele23

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>I tried mysql_fetch_row, and mysql_field_count function, but can't capture an empty result set.

mysql_field_count will return the no .of columns in the row.

For ur problem,u need the no. of rows.which would be 0 when an empty set is returned.

try using mysql_num_rows to retrieve the no. of rows.

Also,what u could do,is move to the next record in the set.
If it is NULL,then this set is either one with one record or an empty recordset.

All u have to do is check how to differentiate b/w the set with one record and an empty set.