我是mysql++的一个新用户,正在寻找一些指针(双关意)。
问题:我的update语句失败。
连接是打开的。使用该连接的前一条语句工作。
我确信我要更新的记录是存在的。我可以通过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();
}发布于 2011-07-14 18:12:18
有几个问题。
库不能正确地转义二进制数据。
如果与连接关联的用户没有update权限,则库将崩溃,而不是引发异常。
发布于 2011-07-13 20:47:59
沃伦在邮件列表上抢先回答了我的问题,但为了子孙后代:
需要引用和转义BLOB数据(Password)。
使用SSQLS代替模板查询将自动处理此问题。
http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#id2776204
https://stackoverflow.com/questions/6685148
复制相似问题