Results 1 to 3 of 3

Thread: Batch update fails with QSqlQuery

  1. #1
    Join Date
    Jun 2007
    Posts
    24
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy Batch update fails with QSqlQuery

    Qt version: 4.3.0
    Platform: Win, MacOS, Linux
    DB Engine: SqLite

    The below batch update returns with "Parameter count mismatch" error.

    QSqlQuery query1(Db);
    query1.prepare("UPDATE TEST_TABLE SET (COL1, COL2) VALUES(?, ?) WHERE ID IN (3, 4)");

    QVariantList qvParam1, qvParam2;
    qvlParam1.push_back(300);
    qvlParam1.push_back(300);

    qvlParam2.push_back(1);
    qvlParam2.push_back(1);

    query1.addBindValue(qvParam1);
    query1.addBindValue(qvlParam2);
    if (!query1.execBatch())
    {
    qDebug() << "Failed to batch update" << query1.lastError();
    assert(0);
    return false;
    }

    Whereas a query like this works just fine in batch execution.
    "INSERT INTO TEST_TABLE(COL1, COL2) VALUES(?, ?)"

    Please help.

  2. #2
    Join Date
    Oct 2006
    Posts
    42
    Thanks
    1
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Batch update fails with QSqlQuery

    What does the call to prepare() return?

    I think you probably would want to change the SQL statement to the following:

    Qt Code:
    1. UPDATE TEST_TABLE SET COL1 = ?, COL2 = ? WHERE ID = ?
    To copy to clipboard, switch view to plain text mode 

    and bind a list of IDs as the third parameter.

  3. The following user says thank you to mm78 for this useful post:

    William Wilson (20th July 2007)

  4. #3
    Join Date
    Jun 2007
    Posts
    24
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Batch update fails with QSqlQuery

    Thank you.
    The following query worked.
    UPDATE TEST_TABLE SET COL1 = ?, COL2 = ? WHERE ID IN (3, 4)

Similar Threads

  1. Problems with QSqlQuery update
    By whoops.slo in forum Qt Programming
    Replies: 4
    Last Post: 28th August 2006, 07:17

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.