如何正确地将blob数据插入表中

问题描述 投票:0回答:1

我尝试在表中写入数据数组,但是我收到错误“参数计数不匹配”

auto query = new QSqlQuery(db);


request = QString("INSERT INTO items(id, type, data) VALUES"
                          "('%0', '%1', :bytes)").
                            arg(id).
                            arg(static_cast<int>(type));

// request: INSERT INTO items(id, type, data) VALUES('0', '512', :bytes)
query->prepare(request)); // ok
query->bindValue(":bytes", bytes); // bytes is qbytearray with data
query->exec(request) // error  Parameter count mismatch
  • 操作系统:ubuntu 18.04
  • Qt:5.12.3,5.9.7 如何正确写入数据?
qt sqlite
1个回答
0
投票

错误是我将原始请求提供给函数参数,它替换了执行“bindValue”函数的请求。

Need to replace

query->exec(request);

by

query->exec();
© www.soinside.com 2019 - 2024. All rights reserved.