【问题标题】:QSql Parameter count mismatchQSql 参数计数不匹配
【发布时间】:2016-10-13 13:58:06
【问题描述】:

我正在使用带有 sqlite 的 QtSql,问题是:

QSqlQuery query;
query.prepare("SELECT * FROM [main].[items] WHERE barcode = ? OR name = ? ");
query.addBindValue(ui->Numberinput->text());
query.addBindValue(ui->search_item->text());
query.exec();
query.first();
qDebug() << query.lastError().text();

我收到“参数计数不匹配”

【问题讨论】:

    标签: c++ qt sqlite


    【解决方案1】:

    @hskoglund 在 Qt 论坛中的解决方案 https://forum.qt.io/topic/72260/qsqlquery-select-statment/5 >

    QString s = QString("SELECT * FROM [main].[items] WHERE barcode = '%1' OR name = '%2'").arg(ui->Numberinput->text()).arg(ui->search_item->text());
    

    QSqlQuery 查询;

    【讨论】:

    • 不要这样做。它容易受到 sql 注入的影响。使用 prepare 和 bindValue
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 2017-12-31
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多