mySQL C API 多语句

发布于 2024-11-06 00:19:25 字数 310 浏览 0 评论 0原文

所以我正在构建一个连接到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉薄对峙 2024-11-13 00:19:25

从文档中并不清楚该函数可能导致的错误是否被返回,但应该可以使用 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.`

述情 2024-11-13 00:19:25

这些是准备好的陈述吗?如果是这种情况,那么您不能使用 CLIENT_MULTI_STATMENTS。

另外,请注意(来自http://dev. mysql.com/doc/refman/5.5/en/c-api-multiple-queries.html):

处理结果后
第一个声明,有必要
检查是否存在更多结果以及
如果是的话依次处理它们。支持
多结果处理,C API
包括 mysql_more_results() 和
mysql_next_result() 函数。这些
函数用在 a 的末尾
循环迭代只要更多
结果可用。未能
以这种方式处理结果可能会导致
与服务器的连接断开。

无论您是否关心这些值,您都必须仔细检查所有结果。

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:

After handling the result from the
first statement, it is necessary to
check whether more results exist and
process them in turn if so. To support
multiple-result processing, the C API
includes the mysql_more_results() and
mysql_next_result() functions. These
functions are used at the end of a
loop that iterates as long as more
results are available. Failure to
process the result this way may result
in a dropped connection to the server.

You have to walk over all the results, regardless of whether or not you care about the values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文