MYSQL C API : CLIENT_MULTI_STATEMENTS 选项
#include <iostream>
#include <mysql.h>
#include <string> #include <assert.h> int main()
{
MYSQL *ms_conn = mysql_init(NULL);
if (ms_conn == NULL)
{
std::cout << "Error: mysql_init failed." << std::endl;
return ;
}
std::cout << "Info: mysql_init success." << std::endl; // 参数CLIENT_MULTI_STATEMENTS 指定一次query 可以执行多条SQL
MYSQL *ms_temp = NULL;
ms_temp = mysql_real_connect(ms_conn, "localhost", "root", "123456sx",
"suyh", , NULL, CLIENT_MULTI_STATEMENTS);
if (ms_temp == NULL)
{
std::cout << "Error: mysql_real_connect() failed." << std::endl;
std::cout << mysql_error(ms_conn) << std::endl;
mysql_close(ms_conn), ms_conn = NULL;
return ;
}
std::cout << "Info: mysql_real_connect() succect." << std::endl; std::string str_sqls = "";
str_sqls += "SELECT id, account, sex, level, powers FROM player_data WHERE id = 100000";
str_sqls += ";";
str_sqls += "SELECT id, account, sex, level, powers FROM player_data WHERE id = 100001";
str_sqls += ";";
str_sqls += "SELECT id, account, sex, level, powers FROM player_data WHERE id = 100002"; int res = ;
res = mysql_real_query(ms_conn, str_sqls.c_str(), str_sqls.size());
if (res != )
{
std::cout << "Info: query failed, sql: " << str_sqls.c_str() << std::endl;
std::cout << mysql_error(ms_conn) << std::endl;
}
else
{
std::cout << "Info: query success." << std::endl;
std::cout << std::endl; // CLIENT_MULTI_STATEMENTS 指定该选项需要mysql_next_result() 函数来获取下一条结果集
// 如果结果集未取完,则不能进行query 操作。
do
{
MYSQL_RES *ms_res = mysql_store_result(ms_conn);
assert(ms_res != NULL); unsigned int field_num = mysql_num_fields(ms_res);
std::cout << "fileds number is " << field_num << std::endl; MYSQL_FIELD* field_info = mysql_fetch_field(ms_res);
assert(field_info != NULL); MYSQL_ROW row_data = NULL;
while ()
{
row_data = mysql_fetch_row(ms_res);
if (row_data == NULL)
break; unsigned long *field_lens = mysql_fetch_lengths(ms_res);
assert(field_lens != NULL);
for (int i = ; i < field_num; ++i)
{
if (field_info[i].type == MYSQL_TYPE_BLOB)
{
std::cout << "current filed type is BLOB." << std::endl;
continue;
} if (row_data[i] == NULL)
{
std::cout << "field_lens[" << i << "] = " << field_lens[i]
<< ", value is NULL." << std::endl;
}
else
{
std::cout << "field_lens[" << i << "] = " << field_lens[i]
<< ", value is " << row_data[i] << std::endl;
}
}
} mysql_free_result(ms_res), ms_res = NULL; std::cout << "#######################################" << std::endl;
} while (mysql_next_result(ms_conn) == );
} mysql_close(ms_conn), ms_conn = NULL;
return ;
}
MYSQL C API : CLIENT_MULTI_STATEMENTS 选项的更多相关文章
- c++使用mysql的api连接相关问题
记录一下自己使用中的相关问题,方便有相同问题的同学解决. 关于在VS中的各种配置.看这里.只是须要注意一下,我如今用的mysql版本号是5.6的,已经没有[MySQL Server \lib\opt] ...
- MySQL C API概述
以下列表总结了C API中可用的功能.有关更多详细信息,请参见 第27.8.7节“C API函数描述”中的说明. my_init():在线程安全程序中初始化全局变量和线程处理程序 mysql_affe ...
- MySql接口API函数综述
C API函数概述 函数 描述 mysql_affected_rows() 返回上次UPDATE.DELETE或INSERT查询更改/删除/插入的行数. mysql_autocommit() 切换 a ...
- PHP数据库操作:从MySQL原生API到PDO
本文将举详细例子向大家展示PHP是如何使用MySQL原生API.MySQLi面向过程.MySQLi面向对象.PDO操作MySQL数据库的. 为了后面的测试,先建立数据库表test.包含表名user,s ...
- mysql C API 字符串玩转备份调优
- The MySQL C API 编程实例
在网上找了一些MYSQL C API编程的文章,看了后认为还是写的不够充分,依据自己经验写了这篇<The MySQL C API 编程实例>,希望对须要调用到MYSQL的C的API的朋友有 ...
- MySQL Backup mysqldump 常用选项与主要用法
The mysqldump client utility performs logical backups, producing a set of SQL statements that can be ...
- MySQL原生API、MySQLi面向过程、MySQLi面向对象、PDO操作MySQL
[转载]http://www.cnblogs.com/52fhy/p/5352304.html 本文将举详细例子向大家展示PHP是如何使用MySQL原生API.MySQLi面向过程.MySQLi面向对 ...
- MySQL C API(23)
C API 提供了对 MySQL c/s 模型的底层访问.C API 代码在 mysqlclient 库中实现.可以从该库中引用到的变量及含义: 环境变量 含义 MYSQL_UNIX_PORT 本地连 ...
随机推荐
- 使用OpenFileDialog会更改默认程序目录
这个问题可能只有在特定的程序中会发现:当我们在程序中使用相对路径时是依赖于当前目录的.所以在使用类似代码: XElement rootNode = XElement.Load(@"zips/ ...
- [强连通分量] POJ 2762 Going from u to v or from v to u?
Going from u to v or from v to u? Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17089 ...
- 一些iOS心得
ARC 1,arc是什么? automatic referece counting mrc mannualiOS5 之后出来的技术// 2,arc的原理是什么?// 在程序编译的时候,系统帮我 ...
- File缓存
/** * 保存对象 * @param ser * @param file * @throws IOException */ public b ...
- Deprecated: Function split() is deprecated in ... 解决办法
本地测试的程序上传到服务器出现很多错误,Deprecated: Function split() is deprecated 查了原因是因为PHP的版本不同所导致的,本身程序开发的时候用的是PHP5 ...
- JS三元
((productDatas[i].Img.indexOf("http") == -1) ? ("/upload/190-160/" + productData ...
- hessionproxy
from pyhessian.client import HessianProxy if __name__ == '__main__': params = {"a": " ...
- TopCoder----卖柠檬
1. 题目描述 Problem Statement You are playing a game called Slime Tycoon.You will be selling Slimonade ...
- inline-block
在CSS中,块级对象元素会单独占一行显示,多个block元素会各自新起一行,并且可以设置width,height属性:而内联对象元素前后不会产生换行,一系列inline元素都在一行内显示,直到该行排满 ...
- Svn服务器的安装和配置
1.安装svn服务器端软件 从镜像服务器或者YUM源下载安装SVN服务器软件:yum install subversion mkdir /usr/local/svn //创建SVN安装目录 c ...