Solved

silly doubt in mysql c api program

Posted on 2004-03-22
7
256 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:msanoop
  • 3
7 Comments
 
LVL 2

Accepted Solution

by:
joele23 earned 40 total points
ID: 10651572
if you used mysql_store_result instead of mysql_use_result
you could then call mysql_num_rows and this will give you the
total number of rows returned by the query including 0 for the NULL set
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10659588
>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.

0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10659677
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.
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10677920
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question