Re: Stored procedure problem solved
Posted by:
FQ ALI
Date: July 14, 2008 03:03AM
There seems to be not a good way in c API of dealing with stored procedure out parameter.
I succeeded in getting the out parameter, but this not seems to be the best solution. If anybody knows some best way then tell me.
The following is the working code.
-------------------------
#include <mysql.h>
#include <stdio.h>
#include <string.h>
main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "";
char *user = "";
char *password = "";
char *database = "";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, CLIENT_MULTI_RESULTS | CLIENT_MULTI_STATEMENTS)) {
fprintf(stderr, "%s\n", mysql_error(conn));
//exit(0);
}
/* send SQL query */
char * state= "call PROC_NGI_Authentication30( '', '', @ret ); select @ret";
int sta =mysql_real_query(conn, state,strlen(state));
if (sta) {
fprintf(stderr, "%s\n", mysql_error(conn));
// exit(0);
}
else
{
printf("query Executed \n");
}
res = mysql_use_result(conn);
if(res==NULL)
{
printf("ResultSet NULL\n");
}
else
{
printf("Result Set Not NULL\n");
}
//int num=mysql_num_rows(res);
//printf("Number of rowssss %d \n",num);
/* while ((row = mysql_fetch_row(res)) != NULL)
{
printf("Result----------- \n");
printf("%s\n", row[1]);
}
*/
//bool b=mysql_more_results(conn);
mysql_free_result(res);
while(mysql_more_results(conn))
{
int next=mysql_next_result(conn);
printf("More Results %d \n",next);
res = mysql_use_result(conn);
if(res==NULL)
{
printf("ResultSet LOOP NULL\n");
}
else
{
printf("Result Set LOOP Not NULL\n");
}
int num=mysql_num_rows(res);
printf("Number of rowssss %d \n",num);
while ((row = mysql_fetch_row(res)) != NULL)
{
printf("Result----------- \n");
printf("lllllllllll %s\n", row[0]);
}
mysql_free_result(res);
}
//else
//printf("No More Results \n");
//mysql_free_result(res);
mysql_close(conn);
}