MySql Connector/c++8中JSON处理Demo
#include <iostream>
#include <vector>
#include <mysqlx/xdevapi.h>
using std::cout;
using std::endl;
int main(void)
try
{
mysqlx::Session sess("mysqlx://root:mysql@localhost:33060?ssl-mode=disabled");
//参数true表示检测给定的"D_COMPANY"是否存在, 如果不存在则抛出异常
//"D_COMPANY" 为使用 【CREATE DATABASE XXXX】 语法创建的数据库名
mysqlx::Schema db = sess.getSchema("D_COMPANY", true);
//"C_DOCUMENT" 为表名
//true 表示返回与此字符串匹配的已存在的表,不存在则抛出异常
cout << ">> create collection.." << endl;
mysqlx::Collection coll = db.createCollection("C_DOCUMENT", true);
#ifdef INSERT_DOCUMENT
cout << ">> add document.." << endl;
mysqlx::Result ret;
//注意: _id字段是必要的
ret = coll.add(
R"(
{
"_id": "test",
"name": "Awesome 4K",
"resolutions": [{
"width": 1280,
"height": 720
}, {
"width": 1920,
"height": 1080
}, {
"width": 3840,
"height": 2160
}]
}
)").execute();
std::vector<std::string> idList = ret.getGeneratedIds();
cout << ">> print ID..." << endl;
for (std::string str : idList) {
cout << str << endl;
}
#endif
#ifdef DELETE_DOCUMENT
cout << ">> drop document..." << endl;
mysqlx::Result ret = coll.removeOne(std::string("test"));
cout << ">> Affect items: " << ret.getAffectedItemsCount() << endl;
#endif
//得到_id为“test”的json数据
mysqlx::DbDoc doc = coll.getOne(std::string("test"));
if (doc.isNull()) {
cout << "the doc is null." << endl;
return 0;
} else {
cout << R"(">> Get a document with an identifier of "test")" << endl;
}
cout << ">> print document..." << endl;
doc.print(cout);
cout << endl;
if (doc.fieldType("name")
== int(mysqlx::Value::STRING))
{
cout << "name: " << doc["name"].get<std::string>() << endl;
}
if (doc.fieldType("resolutions")
== int(mysqlx::Value::ARRAY))
{
mysqlx::DbDoc resDoc = doc["resolutions"].get<mysqlx::DbDoc>();
if (resDoc.isNull()) {
cout << "res doc is null." << endl;
return -1;
}
cout << "-----------------------" << endl;
resDoc.print(cout);
cout << endl;
}
cout << endl << ">> Done!" << endl;
}
catch(mysqlx::Error &err)
{
cout << "ERROR: " << err << endl;
return -1;
}
MySql Connector/c++8中JSON处理Demo的更多相关文章
- MySql Connector/C++8结果集处理Demo
#include <iostream> #include <exception> #include <mysqlx/xdevapi.h> using std::co ...
- 安装MySQL Connector/C++并将其配置到VS2015中
安装MySQL Connector/C++并将其配置到VS中 1.下载MySQL Connector/C++并安装 在下载地址:https://dev.mysql.com/downloads/conn ...
- MySQL中JSON字段的使用技巧
mysql5.7.8之后开始原生支持json. 在类似mongodb这种nosql数据库中,json存储数据是非常自然的, 在mysql中合理的使用json,能够带来极大的便利 Json字段的使用场景 ...
- vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错
包含头文件 #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/state ...
- 创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL
创建ASP.NET Core MVC应用程序(2)-利用MySQL Connector NET连接到MySQL 用惯.NET的研发人员都习惯性地使用SQLServer作为数据库.然而.NET Core ...
- mysql Connector C++ 操作数据库 vs2012
最近想写一个应用程序,要连接和操作mysql数据库,以前只是用c++ builder 操作过mysql数据库,那是用控件操作的,感觉比较弱智,但是c++ builder vcl控件感觉在多线程里比较坑 ...
- [转]MySQL Connector/C++(一)
http://www.cnblogs.com/dvwei/archive/2013/04/18/3029464.html#undefined#undefined MySQL Connector/C++ ...
- Asp.net中Json的序列化和反序列化(一)
JSON是专门为浏览器中的网页上运行的JavaScript代码而设计的一种数据格式.在网站应用中使用JSON的场景越来越多,本文介绍ASP.NET中JSON的序列化和反序列化,主要对JSON的简单介绍 ...
- mybatis/callablestatement调用存储过程mysql connector产生不必要的元数据查询
INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371dao.ITaskDao.callProce ...
随机推荐
- 对 Vue 的理解(一)
一.什么是 Vue ? 首先,Vue 是一个 MVVM 框架,M -- 模型,就是用来定义驱动的数据,V -- 视图,是经过数据改变后的 html,VM -- 框架视图,就是用来实现双向绑定的中间桥梁 ...
- java常用API之System类
System中代表程序所在系统,提供了对应的一些系统属性信息,和系统操作.System类不能手动创建对象,因为构造方法被private修饰,阻止外界创建对象.System类中的都是static方法,类 ...
- 01常用<meta>总结
meta标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的,它可以用于浏览器(显示内容/重新加载页面),搜索引擎(关键字),或者其他web服务. 一.页面设置 <!- ...
- 运用Edraw为WPF应用程序嵌入Office文档的方法总结
具体描述了运用Edraw Office Viewer Component为WPF应用长须嵌入MS Word,Excel以及Power Point的方法. 打开Visual Studio,并创建一个新的 ...
- show_sql和format_sql
<property name="show_sql">true</property> <property name="hibernate.fo ...
- Java—IO流 文件的编码
文件的编码 package cn.test; import java.io.UnsupportedEncodingException; public class Demo15 { public sta ...
- solidity语言11
函数修饰符 pragma solidity ^0.4.11; contract owned { address owner; // 构造函数 function owned() public { own ...
- winform中 让 程序 自己重启
private void button1_Click(object sender, EventArgs e) { Application.ExitThread(); ...
- SQL Server ->> CLR编程问题汇总
1) CLR不支持C#类方法重载(Method Overload) 今天打算写个枚举目录的C# CLR存储过程,结果发现原来CLR不支持方法重载. Msg 6572, Level 16, State ...
- FileHelpers 用法 z
用FileHelplers导出csv数据: [DelimitedRecord(",")] [IgnoreEmptyLines()] [ConditionalRecord(Recor ...