473,395 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help in executing Joins using C API for Mysql

Hi,

I am executing the following query

Expand|Select|Wrap|Line Numbers
  1. select * from mgroup m RIGHT JOIN cgroup c on (c.m_id=m.gid) where m.owner='priya' and c.user='appu'; 
Then i get the following result

+------+---------+-------+------+------+
| gid | grpname | owner | m_id | user |
+------+---------+-------+------+------+
| 3 | family | priya | 3 | appu |
+------+---------+-------+------+------+


However if i write the same query using C API, it gives me output as
"0 rows returned"

C Code snippet:

Expand|Select|Wrap|Line Numbers
  1. sprintf(stmt_buf,"select * from mgroup m RIGHT JOIN cgroup c on (c.m_id=m.gid) where m.owner='%s' and c.user='%s'",dbrecowner,dbrecuser);
  2.  
  3.         if (mysql_query(conn,stmt_buf))
  4.         {
  5.                 fprintf(stderr, "%s\n", mysql_error(conn));
  6.                 return 0;
  7.         }
  8.  
  9.         res = mysql_store_result(conn);
  10.  
  11.         if(res == NULL)
  12.         {
  13.                 return 0;
  14.         }
  15.         else
  16.         {
  17.                 /* process result set, and then deallocate it */
  18.                 process_result_set (conn, res);
  19.         }
  20. ....
  21. ...
  22. }
  23.  
  24. void process_result_set (MYSQL *conn, MYSQL_RES *res_set)
  25. {
  26.  
  27. unsigned int i;
  28. while ((row = mysql_fetch_row (res_set)) != NULL)
  29. {
  30.         for (i = 0; i <= mysql_num_fields (res_set); i++)
  31.         {
  32.         if (i > 0)
  33.         fputc ('\t', stdout);
  34.         printf ("%s", row[i] != NULL ? row[i] : "NULL");
  35.         }
  36. fputc ('\n', stdout);
  37. }
  38. if (mysql_errno (conn) != 0)
  39. fprintf(stderr, "%s\n",conn, mysql_errno (conn));
  40. else
  41. printf ("%lu rows returned\n",
  42. (unsigned long) mysql_num_rows (res_set));
  43.  
  44. }

Please provide ur suggestions.
Thanks in advance

~Priya
Dec 5 '07 #1
3 1043
mwasif
802 Expert 512MB
This is not possible that the same query generates different results. To identify the problem make sure that you are connected to the correct database. Print the query in your code before sending it to MySQL. This will make sure you are executing the correct query.
Dec 5 '07 #2
This is not possible that the same query generates different results. To identify the problem make sure that you are connected to the correct database. Print the query in your code before sending it to MySQL. This will make sure you are executing the correct query.
Ya i verified that i m connected to same database.
My all other queries such as add, search is working fine.
Only the query with a Right Join isnt working..

Please could you suggest where i m going wrong

Thanks in advance
Dec 5 '07 #3
The Join query worked successfully using the above method.
Dec 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ralph Freshour | last post by:
I am having a hard time with joins - my following code displays: ..member_name .gender instead of the actual data - I've been reading through my PHP and MySQL manuals - the MySQL manual tells...
0
by: | last post by:
As we're on this topic in another thread right now: Say I have a SELECT query from more than one table and with some = conditions, does it matter in what order I enter the tables in the FROM =...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
0
by: Morten Gulbrandsen | last post by:
Hello, starting from some software database spesification, defined in some Enhanced entity relationship diagram, resulting in all kinds of relationships, 1:1 1:Many Many:1
0
by: Vijay | last post by:
Hello friends, I have a problem with one of the JOIN query here. Below is a brief description of the problem. tablename : test RecordId EffectiveDate othertableid value -------- ...
0
by: Eric B. | last post by:
Hi, I'm somewhat new to MySql. I've been using it for a while, but pretty much out of the box setup, and am starting to suffer heavily with my larger tables. I have a table with 5,000,000+...
5
by: Mattias Nordstrom | last post by:
Hi. I have a query that looks like this: SELECT user_id, user_given_names, user_surname, user_cast FROM users WHERE user_id NOT IN (SELECT user_id FROM linkage WHERE group_id=1) ORDER BY...
1
by: deepak.rao | last post by:
Hi, I have to run the following statement in MySQL. (The script is generated from oracle). ************* SELECT t1.c1, t2.c2, t3.c3 from t1, t2, t3 where t1.flag = 1 and (t1.cx = t2.cx(+)...
2
by: steve | last post by:
Hi, I want to share my experience with you. If you have large tables, and you are doing joins, be extra careful that the keys in the joins have exactly the same size (and type). Don’t mix...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.