mysql-connector-cpp_sunshine

MySQL Connector/C++

This is a release of MySQL Connector/C++, the C++ interface for communicating with MySQL servers.

For detailed information please visit the official MySQL Connector/C++ documentation.

Licensing

Please refer to files README and LICENSE, available in this repository, and Legal Notices in documentation for further details.

Download & Install

MySQL Connector/C++ can be installed from pre-compiled packages that can be downloaded from the MySQL downloads page.

The process of installing of Connector/C++ from a binary distribution is described in MySQL online manuals

Building from sources

MySQL Connector/C++ can be installed from the source. Please check MySQL online manuals

GitHub Repository

This repository contains the MySQL Connector/C++ source code as per latest released version. You should expect to see the same contents here and within the latest released Connector/C++ package.

Sample Code

#include

#include

using ::std::cout;

using ::std::endl;

using namespace ::mysqlx;

int main(int argc, const char* argv[])

try {

const char *url = (argc > 1 ? argv[1] : "mysqlx://root@127.0.0.1");

cout << "Creating session on " << url

<< " ..." << endl;

Session sess(url);

cout <

Schema sch= sess.getSchema("test");

Collection coll= sch.createCollection("c1", true);

cout <

coll.remove("true").execute();

{

DbDoc doc(R"({ "name": "foo", "age": 1 })");

Result add =

coll.add(doc)

.add(R"({ "name": "bar", "age": 2, "toys": [ "car", "ball" ] })")

.add(R"({ "name": "bar", "age": 2, "toys": [ "car", "ball" ] })")

.add(R"({

"name": "baz",

"age": 3,

"date": { "day": 20, "month": "Apr" }

})")

.add(R"({ "_id": "myuuid-1", "name": "foo", "age": 7 })")

.execute();

std::list ids = add.getGeneratedIds();

for (string id : ids)

cout <

}

cout <

DocResult docs = coll.find("age > 1 and name like 'ba%'").execute();

int i = 0;

for (DbDoc doc : docs)

{

cout <

for (Field fld : doc)

{

cout << " field `" << fld << "`: " <

}

string name = doc["name"];

cout << " name: " << name << endl;

if (doc.hasField("date") && Value::DOCUMENT == doc.fieldType("date"))

{

cout << "- date field" << endl;

DbDoc date = doc["date"];

for (Field fld : date)

{

cout << " date `" << fld << "`: " << date[fld] << endl;

}

string month = doc["date"]["month"];

int day = date["day"];

cout << " month: " << month << endl;

cout << " day: " << day << endl;

}

if (doc.hasField("toys") && Value::ARRAY == doc.fieldType("toys"))

{

cout << "- toys:" << endl;

for (auto toy : doc["toys"])

{

cout << " " << toy << endl;

}

}

cout << endl;

}

cout <

}

catch (const mysqlx::Error &err)

{

cout <

return 1;

}

catch (std::exception &ex)

{

cout <

return 1;

}

catch (const char *ex)

{

cout <

return 1;

}

Documentation

Questions/Bug Reports

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值