Solved

silly doubt in mysql c api program

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

840 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