Solved

silly doubt in mysql c api program

Posted on 2004-03-22
7
248 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now