【问题标题】:mysql++ query failsmysql++ 查询失败
【发布时间】:2011-07-13 20:23:50
【问题描述】:

我是 mysql++ 的新用户,正在寻找一些指针(双关语)。

问题:我的更新语句失败。

连接已打开。上一个使用连接的语句有效。

我确定我要更新的记录存在。我可以用 mysql 查询工具看到它。 我确定 CustomerId 是正确的。

     // declaration of the customer id
     uint32_t CustomerId;

为什么更新失败?

   mysqlpp::Connection conn( true );
   try
   {
      if ( conn.connect( db_rw.Name, db_rw.Host, db_rw.User, db_rw.Password ) )
      {

         // *snip*  insert code here works fine.

         // this query fails
         mysqlpp::Query query = conn.query( "UPDATE customer SET AccountName=%2q, Active=%3, Password=%1 WHERE CustomerId=%0" );
         query.parse();
         mysqlpp::SQLQueryParms parms;
         parms.push_back( mysqlpp::sql_int( CustomerId ) );
         parms.push_back( mysqlpp::sql_blob( data, sizeof(data) ) ); //<- 16 byte binary blob
         parms.push_back( mysqlpp::sql_varchar( widget.AccountName->text().toAscii().data() ) );  // string
         parms.push_back( mysqlpp::sql_bool( widget.ActiveCheckBox->checkState() == Qt::Checked ? 1 : 0 ) );  // 
         mysqlpp::SimpleResult res = query.execute( parms );
      }
   }

如果我关闭连接的异常,它会静默失败(result.info() 方法不返回任何内容)。

如果我在尝试转换为字符串时打开异常 seg faults:

std::string Query::str(SQLQueryParms& p)
{
    if (!parse_elems_.empty()) {
        proc(p);
    }

    return sbuffer_.str();
}

【问题讨论】:

  • 问题似乎是二进制 blob。是否有 ssqls 修饰符对二进制数据进行十六进制编码?

标签: c++ mysql++


【解决方案1】:

Warren 在邮件列表中击败了我,但为了后代:

BLOB 数据 (Password) 需要被引用和转义。

使用 SSQLS 而不是模板化查询会自动处理此问题。

http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#id2776204

【讨论】:

  • 啧啧交叉张贴。感谢您在此处反映答案,克里斯。
【解决方案2】:

有几个问题。

库没有正确转义二进制数据。

如果与连接关联的用户没有更新权限,则库将崩溃而不是抛出异常。

【讨论】:

    猜你喜欢
    • 2016-06-21
    • 2014-11-01
    • 2019-09-27
    • 1970-01-01
    • 2013-11-20
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    相关资源
    最近更新 更多