mysql++读写BLOB数据

news/2024/7/3 1:43:14

mysql++读写BLOB数据

1、使用sql_create_n宏函数,建立数据库表字段与对象。
   #define sql_create_2(NAME, CMP, CONTR, T1, I1, T2, I2) \
        sql_create_complete_2(NAME, CMP, CONTR, T1, I1, #I1, T2, I2, #I2) \
        //NAME:表名;CMP:比较函数;CONTR:构造函数;T1:字段类型;I1:字段名;T2:字段类型;I2:字段名
2、写数据
  1)获取Query
  2)inset 插入上面定义对象得实例
  3)execute执行
3、读数据
  1)获取Query
  2)执行sql,query.store()
  3)获取数据,将数据赋值到对象实例中。
        mysqlpp::Query query = pConn->query();
        query << szSql;
        mysqlpp::StoreQueryResult res = query.store();
        t_electronicWaybill waybill = res[0];        //查询一条记录

完整代码


#include <mysql++.h>
#include <ssqls.h>
sql_create_5(t_electronicWaybill,
1,2,
mysqlpp::sql_int, id,
mysqlpp::sql_int_unsigned, device_id,
mysqlpp::sql_blob_null, waybill_data,
mysqlpp::sql_int, waybill_datasize,
mysqlpp::sql_datetime, currenttime)
//插入运单
bool InsertElectronicWaybill(unsigned int nDeviceId, char *pData, int nDataSize, char *pCurrentTime)
{
bool bSuccess = false;
mysqlpp::Connection* pConn = GetConnection(); //从连接池中获取一个连接
if (pConn == NULL)
{
return false;
}
t_electronicWaybill waybill;
waybill.waybill_data.data.assign(pData,nDataSize);
waybill.waybill_datasize = nDataSize;
waybill.device_id = nDeviceId;
waybill.id = 0;
int nYear = 0, nMonth = 0, nDay = 0, nHour = 0, nMinute = 0, nSecond = 0;
try {
sscanf(pCurrentTime, "%d-%d-%d %d:%d:%d",&nYear,&nMonth,&nDay,&nHour,&nMinute,&nSecond);
}
catch(...){
}
mysqlpp::DateTime *pDateTimeTemp = new mysqlpp::DateTime(nYear,nMonth,nDay,nHour,nMinute,nSecond);
waybill.currenttime = *pDateTimeTemp;
mysqlpp::Query query = pConn->query();
query.insert(waybill);
mysqlpp::SimpleResult res;
try {
res = query.execute();
bSuccess = true;
}
catch (mysqlpp::Exception & ex)
{
OutputDebugString(ex.what());
}
if (pDateTimeTemp != NULL)
{
delete pDateTimeTemp;
}
ReleaseConnection(pConn); //释放连接
return bSuccess;
}
//查询运单
bool QueryElectronicWaybill(unsigned int uiRecordId, unsigned int & nDeviceId, char *pData, int & nDataSize, char *pCurrentTime)
{
bool bSuccess = false;
mysqlpp::Connection* pConn = GetConnection(); //从连接池中获取一个连接
if (pConn == NULL)
{
return false;
}
char szSql[256] = { 0 };
sprintf_s(szSql, "select * from t_electronicWaybill where id = %u", uiRecordId);
try {
mysqlpp::Query query = pConn->query();
query << szSql;
mysqlpp::StoreQueryResult res = query.store();
t_electronicWaybill waybill = res[0];
memcpy(pData, waybill.waybill_data.data, waybill.waybill_data.data.length());
nDataSize = waybill.waybill_datasize;
nDeviceId = waybill.device_id;
if (pCurrentTime != NULL)
{
sprintf_s(pCurrentTime, 23, "%04d-%02d-%02d %02d:%02d:%02d", waybill.currenttime.year(), waybill.currenttime.month(),
waybill.currenttime.day(), waybill.currenttime.hour(), waybill.currenttime.minute(), waybill.currenttime.second());
}
}
catch (mysqlpp::Exception & ex)
{
OutputDebugString(ex.what());
}
ReleaseConnection(pConn); //释放连接
return bSuccess;
}

Navicat for MySQL 查看BLOB字段内容
https://blog.csdn.net/lwei_998/article/details/41871329

原文地址 https://blog.csdn.net/byxdaz/article/details/81413715

http://lihuaxi.xjx100.cn/news/236506.html

相关文章

Hibernate学习(九)———— 二级缓存和事务级别详讲

序言 这算是hibernate的最后一篇文章了&#xff0c;下一系列会讲解Struts2的东西&#xff0c;然后说完Struts2&#xff0c;在到Spring&#xff0c;然后在写一个SSH如何整合的案例。之后就会在去讲SSM&#xff0c;在之后我自己的个人博客应该也差不多可以做出来了。基本上先这样…

最大斑块指数怎么算_教你一个看血管硬化指数的精准公式!

随着生理年龄的增长&#xff0c;胆固醇、甘油三酯等成分在血管壁上越积越多&#xff0c;血管壁的柔韧性降低&#xff0c;血管硬化&#xff0c;血液流动受阻&#xff0c;最终因缺血而引起心脑血管疾病。这就是人到中老年后易与冠心病、脑中风等心脑血管病结缘的症结所在。如果你…

python爬虫知识点总结(二十三)Scrapy中Download Middleware的用法

待更新转载于:https://www.cnblogs.com/cthon/p/9424551.html

别得意,你只是假装收藏了而已

今天分享我在看罗振宇的《2018 时间的朋友》演讲视频记下的一些思考。跨年演讲中有过这样的一个来自印象笔记的片段&#xff0c;列举了几组对比来说明&#xff1a; 『你在朋友圈里又佛又丧&#xff0c;你在收藏夹里偷偷地积极向上。』 扎心了&#xff0c;这不就是说我吗&#x…

mysql 无法登陆_MySQL root用户无法登录原因及解决办法

MySQL root密码正确&#xff0c;却怎么也bai无法du从本地登录MySQL登录提示ERROR 1045 (28000): Access denied for user rootlocalhost (using password: YES)可能原因是mysql库中bai的user表缺少一个root指向host&#xff1a;localhost的数据项&#xff0c;只有一个root指向h…

dede 后台 mysql_织梦dedecms使用Mysql8.0无法登录后台的解决办法

1//只允许用户名和密码用0-9,a-z,A-Z,,_,.,-这些字符2$this->userName preg_replace("/[^0-9a-zA-Z_!\.-]/", , $username);3$this->userPwd preg_replace("/[^0-9a-zA-Z_!\.-]/", , $userpwd);4$pwd substr(md5($this->userPwd), 5, 20);56$d…

女性护理品牌Honeymate获8000万A+轮融资,将与美图公司深度合作

8月5日消息&#xff0c;女性护理品牌“美则Honeymate”于今年7月获美图公司8000万A轮战略融资&#xff0c;资金主要用于品牌扩张以及用户体系、会员体系的建立&#xff0c;也将与美图公司深度合作&#xff0c;为美图超5亿用户创造更多价值。 美则Honeymate&#xff08;深圳市护…

JAVA方法中的参数用final来修饰的效果

很多人都说在JAVA中用final来修饰方法参数的原因是防止方法参数在调用时被篡改&#xff0c;其实也就是这个原因&#xff0c;但理解起来可能会有歧义&#xff0c;我们需要注意的是&#xff0c;在final修饰的方法参数中&#xff0c;如果修饰的是基本类型&#xff0c;那么在这个方…