mySQL C API 多语句
所以我正在构建一个连接到 mySQL 数据库的 C 程序。一切都很完美。然后,为了节省查询数量,我决定一次执行 10 条语句。我在连接中设置了“CLIENT_MULTI_STATMENTS”标志,并用分号分隔我的语句。
当我执行第一批 10 条语句时,它成功并且 mysql_real_query() 返回 0。
但是,当我尝试第二批时,它返回“1”并且不起作用。我无法找到这个“1”错误代码的含义,所以我希望有人以前遇到过这个问题。
请注意,这些都是 UPDATE 语句,因此我不需要结果集,它只是对 mysql_real_query() 的几次直接调用。
So I'm building a C program that connects to a mySQL database. Everything worked perfectly. Then, to save on number of queries, I decided that I would like to execute 10 statements at a time. I set the "CLIENT_MULTI_STATEMENTS" flag in the connection, and separated my statements by semicolons.
When I execute the first batch of 10 statements, it succeeds and mysql_real_query() returns a 0.
When I try the second batch though, it returns a "1" and doesn't work. Nowhere can I find what this "1" error code means, so I was hoping someone may have run into this problem before.
Please note that these are all UPDATE statements, and so I have no need for result sets, it's just several straight-up calls to mysql_real_query().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从文档中并不清楚该函数可能导致的错误是否被返回,但应该可以使用 mysql_error() 获得实际的错误。
我的猜测是,无论您是否对结果集感兴趣,您仍然必须循环遍历结果集。
It's not clear from the documentation whether the errors this function can cause are returned or not, but it should be possible to obtain the actual error using mysql_error().
My guess is that you still have to loop through the result sets whether you're interested in them or not.`
这些是准备好的陈述吗?如果是这种情况,那么您不能使用 CLIENT_MULTI_STATMENTS。
另外,请注意(来自http://dev. mysql.com/doc/refman/5.5/en/c-api-multiple-queries.html):
无论您是否关心这些值,您都必须仔细检查所有结果。
Are these prepared statements? If that's the case then you can't use CLIENT_MULTI_STATEMENTS.
Also, note (from http://dev.mysql.com/doc/refman/5.5/en/c-api-multiple-queries.html) that:
You have to walk over all the results, regardless of whether or not you care about the values.