QT Mysql数据库插入问题

djq87823182 2012-01-29 04:06:11
程序能连上数据库,能查询,能删除,但是不能插入,进行插入的时候会报错,错误如下:
Using unsupported buffer type: 64 (parameter: 1) QMYSQL3: Unable to bind value
请问要怎么解决?关键代码如下:

assert(NULL == m_current->parent());
p2p_resource* res = NULL;
if (NULL == (res = m_current->get_res())) {
assert(m_modified);
QString sql = QString("UPDATE ppdb_resources SET res_name='%1',res_desc='%2'").arg(m_main_win.r_ed_res_name->text(), m_main_win.r_ed_res_desc->toPlainText());
QSqlQuery q;
if (q.exec(sql)) {
m_modified = false;
m_main_win.r_bt_if_commit->hide();
m_main_win.r_bt_if_export->show();
if (m_current->childCount() > 0) {
m_main_win.r_bt_sh_export->show();
} else {
m_main_win.r_bt_sh_export->hide();
}
} else {
QMessageBox::information(this, tr("提示"), QString(tr("保存失败")).append(q.lastError().text()));
}
} else {
if (m_modified) {
res->set_name(m_main_win.r_ed_res_name->text());
res->set_desc(m_main_win.r_ed_res_desc->toPlainText());
m_modified = false;
}
QString sql = QString("INSERT INTO ppdb_resources(res_file,res_name,res_desc,res_hash,res_size,res_seed,res_piece,res_stamp) VALUES('%1','%2','%3',?,%4,?,%5,UNIX_TIMESTAMP())").arg(res->get_file(), res->get_name(), res->get_desc()).arg(res->get_file_size()).arg(res->get_piece_count());

//QString sql = QString("INSERT INTO ppdb_resources(res_file,res_name,res_desc,res_hash,res_size,res_seed,res_piece,res_stamp) VALUES('%1','%2','%3',%4,%5,?,%5,UNIX_TIMESTAMP())").arg(res->get_file(), res->get_name(), res->get_desc()).arg(QVariant(QByteArray(res->get_hash(), P_TYPE_LEN_HASH))).arg(res->get_file_size()).arg(res->get_piece_count());
QSqlQuery q;
if (!q.prepare(sql)) {
QMessageBox::information(this, tr("提示"), QString(tr("保存失败")).append(q.lastError().text()));
return;
}
/*
q.bindValue(":hash", res->get_hash());
q.bindValue(":seed", res->get_seed());
*/
q.addBindValue(QVariant(QByteArray(res->get_hash(), P_TYPE_LEN_HASH)));
q.addBindValue(QVariant(QByteArray(res->get_seed(), res->get_seed_size())));


if (q.exec()) {
delete res;
m_current->set_uid(q.lastInsertId().toUInt());
m_current->set_res(NULL);

m_current->setText(1, QObject::tr("已保存"));
p2p_tree_item* tmp = m_current;
m_current = NULL;
m_main_win.r_main_tree->setCurrentItem(tmp);
_on_item_selected();
} else {
QMessageBox::information(this, tr("提示"), QString(tr("保存失败")).append(q.lastError().text()));
}
}
...全文
353 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
p89787259 2012-01-31
  • 打赏
  • 举报
回复
lz 应该是sql的问题,试下我的这个sql:

QString insertSql = "insert into ppdb_resources(res_file,res_name,res_desc,res_hash,res_size,res_seed,res_piece,res_stamp)"
"values ( \"%1\", \"%2\", \"%3\", \"%4\", \"%5\", \"%6\", \"%7\", UNIX_TIMESTAMP());";
QString sql = insertSql.arg(res->get_file())
.arg(res->get_name())
.arg(res->get_desc())
.arg(res->get_hash())
.arg(res->get_file_size())
.arg(res->get_seed())
.arg(res->get_piece_count());
gnimgnot 2012-01-30
  • 打赏
  • 举报
回复
sql参数?

16,199

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧