Qt QSqlQuery bindValue works with ? but not with :placeholders

前端 未结 1 656
一向
一向 2021-01-17 13:50

I\'m working with SQLite, doing insert into table. Folowwing

QSqlQuery testQuery(QString(\"INSERT INTO test(testcol) VALUES(?)\"));
testQuery.bindValue(0, so         


        
相关标签:
1条回答
  • 2021-01-17 14:19

    Please use prepare as the official example:

    QSqlQuery testQuery;
    testQuery.prepare("INSERT INTO test(testcol) VALUES(:val)");
    testQuery.bindValue(":val", someQStringObj);
    testQuery.exec();
    

    The reason for the error is that the query was executed before binding to the corresponding placeholder. You can see the relevant part of the constructor documentation:

    If query is not an empty string, it will be executed.

    0 讨论(0)
提交回复
热议问题