MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 15th, 2005, 09:41 AM
CraigMcI CraigMcI is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 7 CraigMcI User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 12 m 49 sec
Reputation Power: 0
C Api and Stored Procedures (returning a resultSet)

Hey all,

i've been looking into using stored proecdures, and have got some up and running correctly from the command line,
i need to use them from within a c program using the c api.
i have the c api set up correctly, and connect to the db and can run queries fine.
but if i change my query to calling a stored procedure it doesn't work:

"mysql_real_query( mysql, query, strlen(query) )",
query = "CALL myStoredProc(21);"

can the c api even call a stored proc? i thought this would be okay as running a query is running a mysql query, and i assume this will execute any mysql statement.

however my stored proc ALWAYS returns 0 rows affected.

the help docs have something called prepared statements - though i think these are different from precompiled stored procs.

any help/advice is appreciated, cheers,
Craig

Reply With Quote
  #2  
Old February 15th, 2005, 10:04 AM
CraigMcI CraigMcI is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 7 CraigMcI User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 12 m 49 sec
Reputation Power: 0
okay,
the stored proc is being called,
but the error returned is:
SELECT statments in stored procedures must have INTO

this seems to mean i can only retreive ONE row at a time.

how can i retreive full result sets?

cursors?(being fairly noobish to mysql, i have never used these - heard they are slow though, is this the case?)

Reply With Quote
  #3  
Old February 15th, 2005, 09:56 PM
HarrisonF HarrisonF is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: Binghamton, NY
Posts: 536 HarrisonF User rank is Sergeant (500 - 2000 Reputation Level)HarrisonF User rank is Sergeant (500 - 2000 Reputation Level)HarrisonF User rank is Sergeant (500 - 2000 Reputation Level)HarrisonF User rank is Sergeant (500 - 2000 Reputation Level)HarrisonF User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 15 h 35 m 55 sec
Reputation Power: 24
In order to return result sets from a stored procedure you need to make sure that you set CLIENT_MULTI_RESULTS in your mysql_real_connect call. That is because if a stored procedure is returning stuff from a SELECT (rather than INTO a variable) then it might return multiple result sets.

If you do that, and use the multiple result set handling you should be fine. See http://dev.mysql.com/doc/mysql/en/c-api-multiple-queries.html for more info.
__________________
Harrison C. Fisk, Senior Support Engineer
MySQL AB, www.mysql.com
Author: MySQL Clustering

Reply With Quote
  #4  
Old February 16th, 2005, 08:14 AM
CraigMcI CraigMcI is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 7 CraigMcI User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 12 m 49 sec
Reputation Power: 0
Thumbs up

hey harrison,
that worked great - exactly what i wanted.

i would think that returning multiple result sets from a stored procedure using the c api would be a well documented thing, but i've been at this a day or two at this stage.

even the link you posted about multiple statement execution isn't exactly what i was looking for (though the CLIENT_MULTI_RESULTS was, thanks).

Ignoring the c-api thing for a minute,
from reading documentation i think that its not even obvious that you CAN return a result set from a stored procedure - in fact i posted in one or two other forums and was told i couldn't return more than one row at a time from a stored procedure, and then only by explicitly stating a matching param for each field, in the CREATE PROCEDURE name (OUT field1 INT, OUT field2 VARCHAR(100), etc...).

having said that the first post at the bottom of the stored procedures section in the online manual says you can:
http://dev.mysql.com/doc/mysql/en/stored-procedures.html
i just couldn't figure out how to 'select' and use the resultset.

thanks again harrison!
Craig

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > C Api and Stored Procedures

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap