1

我是 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() 方法不返回任何内容)。

如果我在尝试转换为字符串时打开它的异常段错误:

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

    return sbuffer_.str();
}
4

2 回答 2

1

有几个问题。

该库无法正确转义二进制数据。

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

于 2011-07-14T18:12:18.150 回答
1

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

BLOBdata ( Password) 需要被引用和转义。

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

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

于 2011-07-13T20:47:59.797 回答