how to get result set from calling procedure?
how to get result set from calling procedure?
am 15.08.2006 11:39:40 von Gary li
Hi,all
I am using Mysql 5.0 But I get an error message for calling procedure
with mysql_query().
My program is shown below:
Thank & Regard.
Gary.
#define W32_LEAN_AND_MEAN
#include
#include
#include
#include
int main(int argc, char** argv)
{
MYSQL* sqlid = mysql_init(0);
if (!mysql_real_connect(sqlid, "localhost", "test", "test", "test", 0,
0, CLIENT_MULTI_STATEMENTS)) {
printf("%s\n", mysql_error(sqlid));
mysql_close(sqlid);
return -1;
}
sqlid->reconnect = 1;
std::string proc = "call pro_ins_department(10, 'test',
'testprocedure')";
if (0 != mysql_query(sqlid, proc.c_str())) {
printf("operator failed:%d %s\n", mysql_errno(sqlid),
mysql_error(sqlid));
} else {
MYSQL_RES * rs = mysql_store_result (sqlid);
MYSQL_ROW row = mysql_fetch_row(rs);
unsigned __int64 id = (unsigned __int64)atoi(row[0]);
printf("get id:id=%d\n", id);
}
mysql_close(sqlid);
return 0;
}
Re: how to get result set from calling procedure?
am 15.08.2006 16:04:52 von larko
Gary li wrote:
> Hi,all
> I am using Mysql 5.0 But I get an error message for calling procedure
> with mysql_query().
> My program is shown below:
> Thank & Regard.
> Gary.
>
> #define W32_LEAN_AND_MEAN
> #include
> #include
> #include
> #include
>
> int main(int argc, char** argv)
> {
> MYSQL* sqlid = mysql_init(0);
> if (!mysql_real_connect(sqlid, "localhost", "test", "test", "test", 0,
> 0, CLIENT_MULTI_STATEMENTS)) {
> printf("%s\n", mysql_error(sqlid));
> mysql_close(sqlid);
> return -1;
> }
> sqlid->reconnect = 1;
> std::string proc = "call pro_ins_department(10, 'test',
> 'testprocedure')";
> if (0 != mysql_query(sqlid, proc.c_str())) {
> printf("operator failed:%d %s\n", mysql_errno(sqlid),
> mysql_error(sqlid));
> } else {
> MYSQL_RES * rs = mysql_store_result (sqlid);
> MYSQL_ROW row = mysql_fetch_row(rs);
> unsigned __int64 id = (unsigned __int64)atoi(row[0]);
> printf("get id:id=%d\n", id);
> }
> mysql_close(sqlid);
> return 0;
> }
>
you have to make sure that you the username you're using has execute
privileges on that stored procedure in the database you're connecting
to. otherwise, it looks ok to me.
Re: how to get result set from calling procedure?
am 15.08.2006 17:28:11 von Gary li
But It's still the same error for using root username.
lark åéï¼=9A
> Gary li wrote:
> > Hi,all
> > I am using Mysql 5.0 But I get an error message for calling procedure
> > with mysql_query().
> > My program is shown below:
> > Thank & Regard.
> > Gary.
> >
> > #define W32_LEAN_AND_MEAN
> > #include
> > #include
> > #include
> > #include
> >
> > int main(int argc, char** argv)
> > {
> > MYSQL* sqlid =3D mysql_init(0);
> > if (!mysql_real_connect(sqlid, "localhost", "test", "test", "test", 0,
> > 0, CLIENT_MULTI_STATEMENTS)) {
> > printf("%s\n", mysql_error(sqlid));
> > mysql_close(sqlid);
> > return -1;
> > }
> > sqlid->reconnect =3D 1;
> > std::string proc =3D "call pro_ins_department(10, 'test',
> > 'testprocedure')";
> > if (0 !=3D mysql_query(sqlid, proc.c_str())) {
> > printf("operator failed:%d %s\n", mysql_errno(sqlid),
> > mysql_error(sqlid));
> > } else {
> > MYSQL_RES * rs =3D mysql_store_result (sqlid);
> > MYSQL_ROW row =3D mysql_fetch_row(rs);
> > unsigned __int64 id =3D (unsigned __int64)atoi(row[0]);
> > printf("get id:id=3D%d\n", id);
> > }
> > mysql_close(sqlid);
> > return 0;
> > }
> >
> you have to make sure that you the username you're using has execute
> privileges on that stored procedure in the database you're connecting
> to. otherwise, it looks ok to me.