mysql++使用
2024-10-15 19:01:22
Mysql++是官方发布的、一个为MySQL设计的C++语言的API。Mysql++为Mysql的C-Api的再次封装,它用STL(Standard Template Language)开发并编写,并为C++开发者提供像操作STL容器一样方便的操作数据库的一套机制。其官方API介绍:MySQL++ Reference Manual
与JDBC一样,先建立连接Connection,创建Query,执行操作获得结果。
SimpleResult Query::store()进行更新、删除、创建等操作,SimpleResult代表执行状态,查询是否成功、影响了多少行。
StoreQueryResult Query::store():最常用。StoreQueryResult继承vector<mysqlpp::Row>,Row类似于vector<string>,表示一行中各列的数据。使用可以result[1][4]或result[2]["price"]。
UseQueryResult Query::use(),大结果查询,UserQueryResult是iterator,一次只能获得一个行结果,不停地next直到结束为止。
简单示例
#include <mysql++.h>
// Connect to the sample database.
mysqlpp::Connection conn(false);
if (conn.connect(db, server, user, pass)) {
// Retrieve a subset of the sample stock table set up by resetdb
// and display it.
mysqlpp::Query query = conn.query("select item from stock");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout << "We have:" << endl;
for (size_t i = ; i < res.num_rows(); ++i) {
cout << '\t' << res[i][] << endl;
}
}
else {
cerr << "Failed to get item list: " << query.error() << endl;
return ;
}
return ;
}
else {
cerr << "DB connection failed: " << conn.error() << endl;
return ;
}
最新文章
- Security configuration of SSH login entry - enterprise security practice
- Oracle数据库(2)
- Boost的自动链接功能
- OpenCMS integration with Spring MVC--reference
- C#如何在panl控件上添加Form窗体
- JS中Array数组的三大属性用法
- JS声明对象时属性名加引号与不加引号的问题
- .Net Core Web/Console 下使用Nlog
- Educational Codeforces Round 62
- [转]Cordova Android 返回键拦截(backbutton)和退出(再点击一次跳出)
- 将MySQL数据库转移到SqlServer2008数据库
- Nginx使用rewrite重新定向
- Django(ORM查询2)
- 科普贴 | 数字钱包MetaMask安装使用详解,活用MetaMask轻松驾驭以太坊
- js-小数计算问题
- 15.3.14 DP练习2
- Python:dict字典
- C语言-求最大值
- scp -P 非22端口拷贝
- 同步与异步区别,Invoke与BeginInoke的区别
热门文章
- 【RF库Collections测试】Remove From Dictionary
- Effective C++ —— 构造/析构/赋值运算(二)
- cstring、string、wstring、int、char*、tchar、 int、dword等相互转换代码输出测试
- combobox组合框
- linux系统查看IP地址,不显示IP地址或者只显示127.0.0.1
- SpringMvc 400 Bad Request解决方法
- c++11——改进容器性能
- redis 之初体验(window)
- 腾讯云CMQ消息队列在Linux环境下的使用
- Ubuntu远程登录服务器--ssh的安装和配置