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 ...
随机推荐
- VMware 安装提示缺少MicrosoftRuntime DLL 问题解决办法
VMware 安装提示缺少MicrosoftRuntime DLL 问题解决办法 刚刚安装VMware失败了试了好多办法,在这总结一下. 下面是程序的截图 这是报错信息 网上的解决方法: 当出现安装失 ...
- 隐藏 google 地图 Logo 隐藏 百度 地图 Logo
Google 地图 var isFirstLoad=true; //地图瓦片加载完成之后的回调 google.maps.event.addListener(map, 'tilesloaded', fu ...
- C语言指针的陷阱
C语言指针的陷阱 分类: C/Cpp 转自:http://blog.csdn.net/porscheyin/article/details/3461670 “C语言诡异离奇,陷阱重重,却获得了巨大 ...
- idea 新建文件夹目录问题解决
选中工程,设置,去掉选项“Compact Empty Middle Packages” .
- solidity语言8
输入参数 pragma solidity ^0.4.16; contract Simple { function taker(uint _a, uint _b) public pure { // do ...
- 国家与大洲对应关系json数据
[ { "continent_cname": "欧洲", "continent_name": "EU", "c ...
- 基于配置的Spring AOP
前面几篇学习了Spring的依赖注入,这篇开始学习另一个核心功能——面向切面编程AOP. 通过本文,你可以了解到: 1 Spring xml规范 2 通过配置文件实现面向切面编程 3 对比与传统AOP ...
- web中的cookie管理
本篇是以JSP为背景介绍,但是在web开发中也是相同的原理. 什么是cookie 由于http是一种无状态的协议,因此服务器收到请求后,只会当做一次新的请求.即便你重复发送了1000次同样的请求,这1 ...
- tp5.0:替换修改js、css等样式文件路径
首先, 我们要知道,TP5已经不支持绝对路径访问样式文件啦!所以我们不必去花时间去找使用$_SERVER来获取 手册位置:模板->内置标签->资源文件加载 方法一: 过程: 1.首先在模块 ...
- C语言 Include指令(引用头文件)
#include "one.h" #include "two.h" int main(int argc, const char * argv[]) { one( ...