QT Mysql数据库插入问题
程序能连上数据库,能查询,能删除,但是不能插入,进行插入的时候会报错,错误如下:
Using unsupported buffer type: 64 (parameter: 1) QMYSQL3: Unable to bind value
请问要怎么解决?关键代码如下:
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()));
}
}
...全文
相关推荐
Qt实现MySQL数据库读写
在本文中,我们将深入探讨如何使用Qt框架来实现对MySQL数据库的读写操作。Qt是一个功能强大的跨平台应用程序开发框架,而MySQL则是一款广泛应用的关系型数据库管理系统。
QT连接mysql数据库
如果你有具体的代码或问题,欢迎进一步讨论,以便更深入地理解QT连接MySQL数据库的过程和解决可能出现的问题。
qt mysql定时备份
QT MySQL 定时备份是将MySQL数据库的数据在特定时间点自动保存到本地或者远程服务器的过程,这通常通过编程实现,而QT作为一个强大的跨平台应用程序开发框架,提供了与MySQL数据库交互的API,
QT-Mysql-Blob.zip_mysql blob_qt blob 文件_qt blob类型_qt的blob
熟悉MySQL的BLOB数据类型以及Qt提供的数据库API,可以帮助你有效地处理这些问题,实现稳定、高效的数据库应用。
QT5连接MySQL数据库
("localhost"); // MySQL服务器地址 db.setDatabaseName("my_database"); // 要连接的数据库名 db.setUserName("root"); /


