这是执行查询调用存储过程后封装的获得结果的函数,调用存储过程,select 返回 0或者1,
明明只返回了一个字段,但是我执行一次mysql_store_result,然后释放结果集,
再次执行其他语句时就报错 CR_COMMANDS_OUT_OF_SYNC 
可是已经没有结果集了,为什么还会出这个错呢。
诡异的是mysql_next_result()还返回的0,表示有结果,可是再次调用mysql_store_result返回NULL,什么情况呢- -
最近才在程序中使用mysql的API,可能机制啥的没太了解清楚
叙述的比较啰嗦,求大神们解答一下问题呗,是C的代码有问题还是我的存储过程写的不对- -
谢谢!
int GetResult(STRU_SQL*pSql)
{
        int nRet=0;
        int nRow=0;
        int nField=0;
        if(pSql==NULL)
                return -1;
        //nField=mysql_num_fields(pSql->g_res);
        //printf("%d rows %d field\n",nRow, nField);
        do{
        pSql->g_res=mysql_store_result(pSql->g_conn);
        if(pSql->g_res)
        {
                printf("res have\n");
                nRow=mysql_num_rows(pSql->g_res);
        }
        else
        {
                nRow=0;
        }
        printf("%d rows\n",nRow);
        if(pSql->g_res)
        {
                while(pSql->g_row=mysql_fetch_row(pSql->g_res))
                {
                        //nRet=pSql->g_row[0][0]-48;
                        printf("result:%s\n",pSql->g_row[0]);
                }
                //printf("result:       %s\n",pSql->g_row);
                //nRet=pSql->g_row[0][0]-48;
        }
        if(pSql->g_res)
                mysql_free_result(pSql->g_res);
        pSql->g_res=NULL;
        }while(!mysql_next_result(pSql->g_conn));
        //printf("%d个结果集\n",mysql_next_result(pSql->g_conn));
        return nRet;
}BEGIN
DECLARE result INT;
DECLARE nID int;
CALL sp_existaccount(p_username,result);
# select result;
if(result=1) then
select 1;
ELSE
CALL sp_GetRandID(nID);
insert into user values(nID,NULL,p_sex);
insert into account values(p_username,nID,CURRENT_TIMESTAMP(),NULL,0,p_mobile);
insert into password values(p_username,MD5(p_password));
select 0;
END IF;
END