Results 1 to 2 of 2

Thread: Sqlite , QVariantList and QSqlError("", "Parameter count mismatch", "")

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2015
    Posts
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Sqlite , QVariantList and QSqlError("", "Parameter count mismatch", "")

    I am trying to write to a Sqlite db using the execBatch(QSqlQuery::ValuesAsColumns)) method in order to bind a Qvariantlist of string to the query. I end up getting the dreaded QSqlError("", "Parameter count mismatch", "").

    I have searched and tried all the tips even though most of them were not related to QVariantlist issues.

    I delete the database each time i run the code and recreate it inside Qt with the following code to give me 24 columns

    Qt Code:
    1. QSqlDatabase mydb = QSqlDatabase::addDatabase("QSQLITE");
    2. mydb.setDatabaseName("SomeDb.sqlite");
    3. if (mydb.open())
    4. {
    5. QString q1 = "CREATE TABLE Info(FileName VARCHAR(50)";
    6. for (int i=1; i< 24; i++)
    7. {
    8. q1 = q1 + ",Col" + QString::number(i) + " VARCHAR(50)";
    9. }
    10. q1 = q1 + ")";
    11. QSqlQuery query(q1);
    12. query.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    The creation "looks" okay since I can find the db in firefox db manager with the columns as planned it.

    I then read in a bunch of strings into a QStringList and then convert the QStringList to a QVariantList.
    Qt Code:
    1. QString line;
    2. // some code here to read and validate the line of text. I printed the QStringlist to console and it looks fine.
    3. QStringList fields;
    4. fields = line.split(",");
    5. QList<QVariant> variantlist;
    6. variantlist << file.fileName();
    7. foreach(QString s, fields)
    8. {
    9. variantlist << s;
    10. }
    To copy to clipboard, switch view to plain text mode 

    At this point I should have the QVariantlist populated with the correct data and checking the size results in 24 entries (as expected).

    So then I create a new sqlquery to insert the row into the table, each item in the variant list is for a specific column.

    Qt Code:
    1. QSqlQuery q(mydb);
    2. q.prepare("INSERT INTO Info VALUES (?)");
    3. q.addBindValue(variantlist);
    4. qDebug() << "Bound values: " << q.boundValues();
    5. if (!q.execBatch(QSqlQuery::ValuesAsColumns))
    6. qDebug() << q.lastError();
    To copy to clipboard, switch view to plain text mode 

    and the result of this is as follow:

    items count in variant list 24
    Bound values: QMap((":a", QVariant(QVariantList, (QVariant(QString, "../../data/rws.txt"), QVariant(QString, ".451"), QVariant(QString, " 231"), QVariant(QString, " GECO VMR"), QVariant(QString, "231.48"), QVariant(QString, ".661"), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ".451"), QVariant(QString, ".141"), QVariant(QString, ".141"), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, ""), QVariant(QString, "15")))))
    QSqlError("", "Parameter count mismatch", "")

    Any ideas?
    Last edited by anda_skoa; 21st November 2015 at 16:41.

Similar Threads

  1. Replies: 14
    Last Post: 16th May 2017, 04:51
  2. QSqlError("", "Parameter count mismatch", "")
    By Alberto7 in forum Newbie
    Replies: 2
    Last Post: 9th October 2015, 23:09
  3. Replies: 3
    Last Post: 15th December 2014, 17:24
  4. Replies: 3
    Last Post: 25th August 2009, 14:03
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.