使用getString成员函数获取表字段数据出错

MySQL Connector++ 使用getString获取表字段数据出错

Linux下一个使用MySQL Connector++ 1.1.0 连接MySQL数据库的程序,在连接数据库获取数据时程序崩溃,
确定数据库中存在记录值,查看Core Dump文件,发现崩溃点发生在调用 MySQL 库的 getString 方法时的那一行,

通过google搜索,发现好一些getString出错的问题,但是多数是Windows下VS编译环境不同造成的,终于发现下面一篇中有和我的问题类似

http://stackoverflow.com/questions/4822958/mysql-c-connector-getstring-doesnt-work-correctly-while-getint-works-perfe


I had a similar problem the program would give a memory exception. Here is what I did to fix it:
std::string version = result->getString( COLUMN_NAME ).c_str();

This didn’t work:
sql::SQLString sString = result->getString( COLUMN_NAME ); <<

我的不正常代码是


std::string value = result->getString( field);

按照上面的方法将代码修改为


std::string value = result->getString( field).c_str();

暂时获取同样的数据没有出错,希望后面也不要出错。
MySQL Connector++ 从版本1.1.4开始编译依赖于BOOST库

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值