gpt4 book ai didi

c++ - mysql++查询失败

转载 作者:行者123 更新时间:2023-11-30 04:33:37 25 4
gpt4 key购买 nike

我是 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();
}

最佳答案

Warren 抢在我之前在邮件列表中给出了答案,但为了后代:

BLOB 数据(密码)需要引用和转义。

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

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

关于c++ - mysql++查询失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6685148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com