Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

silly doubt in mysql c api program

Posted on 2004-03-22
7
Medium Priority
?
278 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 160 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

916 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