QSqlQuery返回以某些数字开头的单词的异常

时间:2017-04-15 20:21:36

标签: c++ qt sqlite exception qsqlquery

我有这段代码:

foreach (QString TheKeyword, KeywordsList) {
    if (!TheKeyword.isEmpty())
    {
        TheKeyword.replace("'","''").replace("[", "[[]");

        QString sQuery = QString("UPDATE news SET deleted = '1' WHERE %1 like '%%2%' AND Id IN(%3) AND deleted = '0'")
                            .arg(TheColumn)
                            .arg(TheKeyword)
                            .arg(TheIDs);

        QSqlQuery TheQuery(TheDB);
        TheQuery.prepare(sQuery);
        TheQuery.exec();

        if (TheQuery.lastError().isValid())
        {
            qDebug() << TheQuery.lastError() << "   -   " << TheKeyword;
        }
    }
}

例如,&#34; KeywordsList &#34;包含这个单词的列表(&#34; KeywordsList&#34;是一个QStringList):

1Tap
World
A man from Mars
2 Battery
2Do
1CLICK
01 Net
2 Bananas
4 Bananas
system app remover

我的代码返回此错误:

QSqlError("", "Unable to fetch row", "No query")    -    "1Tap"
QSqlError("", "Unable to fetch row", "No query")    -    "2 Battery"
QSqlError("", "Unable to fetch row", "No query")    -    "2Do"
QSqlError("", "Unable to fetch row", "No query")    -    "1CLICK"
QSqlError("", "Unable to fetch row", "No query")    -    "01 Net"
QSqlError("", "Unable to fetch row", "No query")    -    "2 Bananas"

所以,我发现问题只有关键字开始,其中&#39; 0 &#39;&#39; 1 &#39;或&#39; 2 &#39;

我尝试使用 bindValue ,但没有成功。

谢谢。

0 个答案:

没有答案