在c ++项目中使用mysql_query进行多个查询 [英] multiple queries with mysql_query in a c++ project

查看:489
本文介绍了在c ++项目中使用mysql_query进行多个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,这不适用于mysql_query.

So, this will not work with mysql_query.

我严格使用c ++,并且不使用php.

I am strictly working with c++ and I am not using php.

我希望执行此双重查询,以便在并发用户创建ID的交易系统中,我将始终具有唯一ID.

I want this double query to be executed so that I will always have a unique ID in a transaction system with concurrent users creating IDs.

mysql_query(connection, \
"INSERT INTO User() VALUES ();  SELECT LAST_INSERT_ID(); ");

它可以完美地在MySql数据库中运行,但是我需要将其添加到Eclipse(我正在使用Ubuntu 12.04 LTS).

It works in MySql DataBase perfectly, but I need to add it to Eclipse( I am using Ubuntu 12.04 LTS).

我的应用程序很大,如果可能的话,我不想更改为mysqli,但是如果没有其他方法,那就没问题了.

My application is quite big and I would not like to change to mysqli, if this is possible but if there is no other way it will be ok.

您能帮我吗?预先感谢.

Can you help me with this? Thanks in advance.

推荐答案

根据MySQL C API文档:

According to the MySQL C API documentation:

MySQL 5.6还支持执行包含多个字符串 用分号(;")字符分隔的语句.此功能是 通过连接时指定的特殊选项启用 通过mysql_real_connect()或通过以下方式连接到服务器 调用`mysql_set_server_option().

MySQL 5.6 also supports the execution of a string containing multiple statements separated by semicolon (";") characters. This capability is enabled by special options that are specified either when you connect to the server with mysql_real_connect() or after connecting by calling` mysql_set_server_option().

并且:

CLIENT_MULTI_STATEMENTS启用mysql_query()和mysql_real_query() 执行包含多个分开的语句的语句字符串 通过分号.此选项还启用CLIENT_MULTI_RESULTS 隐式地,因此将CLIENT_MULTI_STATEMENTS的标志参数标记为 mysql_real_connect()等效于 CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS.那是, CLIENT_MULTI_STATEMENTS足以启用多语句 执行和所有多结果处理.

CLIENT_MULTI_STATEMENTS enables mysql_query() and mysql_real_query() to execute statement strings containing multiple statements separated by semicolons. This option also enables CLIENT_MULTI_RESULTS implicitly, so a flags argument of CLIENT_MULTI_STATEMENTS to mysql_real_connect() is equivalent to an argument of CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS. That is, CLIENT_MULTI_STATEMENTS is sufficient to enable multiple-statement execution and all multiple-result processing.

因此,假设您使用mysql_real_connect设置了一些不同的mysql连接,则可以在单个mysql_query()调用中提供多个语句,并用分号分隔. 您需要将以下标志作为最后一个参数传递:CLIENT_MULTI_STATEMENTS,其文档说:

So, you can supply several statements in a single mysql_query() call, separated by a semicolon, assuming you set up your mysql connection a bit differently, using mysql_real_connect. You need to pass the following flag as the last argument: CLIENT_MULTI_STATEMENTS, whose documentation says:

告诉服务器客户端可以在一个服务器中发送多个语句 单个字符串(用;"分隔).如果未设置此标志, 多语句执行被禁用.请参阅此后的注释 表格以获取有关此标志的更多信息.

Tell the server that the client may send multiple statements in a single string (separated by ";"). If this flag is not set, multiple-statement execution is disabled. See the note following this table for more information about this flag.

请参见 C API对多语句执行的支持 22.8.7.53. mysql_real_connect()了解详细信息.

See C API Support for Multiple Statement Execution and 22.8.7.53. mysql_real_connect() for mroe details.

这篇关于在c ++项目中使用mysql_query进行多个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆