mysql - 在 C 中第二次调用存储过程时命令不同步 MySQL
问题描述
我使用 mySQL 创建了一个数据库,现在我需要启动我创建的存储过程,编写一个基本的 C 客户端,它要求一个命令,并调用存储过程。
特别是,在登录后,虽然我没有输入“10”来注销,但我的程序会询问我想调用哪个 SP。那是我的代码:
void root_logged ()
{
while (true)
{
scanf ("%i",&cmd2);
if (cmd2 == 2)
{
show_exams();
}
else if (cmd2 == 10)
{
do_logout();
break;
}
}
}
void show_exams ()
{
strcpy(query,"call show_exams()"); //call mySQL SP
mysql_query (conn,query);
result = mysql_store_result(conn);
if (result == NULL)
{
finish_with_error(conn, "errore");
}
printf ("check 2:\n");
num_fields = mysql_num_fields(result);
printf ("check 3 \n");
while ((row = mysql_fetch_row(result)))
{
for(int i = 0; i < num_fields; i++)
{
if (i == 0)
{
while(field = mysql_fetch_field(result))
{
printf( "| %s ", field->name);
}
printf("\n");
}
printf(" %s ", row[i] ? row[i] : "NULL");
}
printf ("\n");
}
mysql_free_result(result);
}
如果我在登录后第一次输入“2”,它会正确显示整个表格“考试”,其中存储了所有数据。
结果之后,程序要求另一个命令。如果我再次输入 2 (或除 10 之外的任何其他 cmd 以注销),它会给我这个错误。
命令不同步;你现在不能运行这个命令
任何想法?我认为问题在于它about mysql_store_result()
没有mysql_free_result()
正确使用
解决方案
推荐阅读
- flutter - 如何从 Flutter 插件调用代码?
- pandas - 如何将 Pandas 数据框直接上传到 BigQuery?
- apt - deb包解压到文件夹时如何安装
- rxjs - RxJS 从 mergeMap 返回值数组
- javascript - React 传单:Array.map 函数未将 Marker 组件渲染到 Map
- docker - Docker 网络,从 windows 主机连接到 linux 容器
- javascript - JQuery datepicker验证问题
- javascript - 当 document.hidden 为 true 时,Chrome 中不会触发滚动事件。任何解决方法?
- python - 通过创建字典替换单词
- reactjs - 反应,增量全局变量不按预期工作