Results 1 to 3 of 3

Thread: [Solved]Count parameter mismatch on QSqlQuery::exec()

  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default [Solved]Count parameter mismatch on QSqlQuery::exec()

    So I just gone through regular expressions to understand them properly so I can use those to to split strings but I am having a bit of a step-back.
    Here is the content of the function which does the job:

    Qt Code:
    1. QSqlQuery adaug;
    2. QRegExp rx("(\\d+),(.+)$");
    3. int pos=0;
    4. QString sirncateg="";
    5. int nrccateg=0;
    6. adaug.prepare("insert into categProd(codcat,numecateg,dataadaugare,datamodificare) "
    7. "values(?,?,datetime('now','localtime'),datetime('now','localtime'))");
    8. //adaug.exec("begin");
    9. for(int i=0; i<strl.size(); i++){
    10.  
    11. while((pos=rx.indexIn(strl[i],pos))!=-1){
    12. nrccateg=rx.cap(1).toInt();
    13. sirncateg=rx.cap(2).toLower();
    14. pos+=rx.matchedLength();
    15. }
    16.  
    17. adaug.bindValue(0,nrccateg);
    18. adaug.bindValue(1,sirncateg);
    19. adaug.exec();
    20. pos=0;
    21. if(adaug.lastError().isValid()==true){
    22. QMessageBox::critical(this,"Eroare",adaug.lastError().text());
    23. break;
    24. }
    25. }
    26. if(adaug.lastError().isValid()==false){
    27. //adaug.exec("commit");
    28. QMessageBox::information(this,"Succes","Categoriile au fost importate cu succes.");
    29. }
    To copy to clipboard, switch view to plain text mode 

    This code works good, but if I uncomment adaug.exec("begin") and adaug.exec("commit") I the following error: "Parameter count mismatch".
    The lines are from a csv file containing: a number, a comma, and a string.
    The QRegExp I use to catch the numbers(which are IDs) and the strings after the comma and insert them in the sqlite database, not using QString::split("delimiter") because the strings can contain commas also.
    Anyone sees what am I doing wrong? Is it the regex
    Last edited by adutzu89; 13th March 2015 at 15:50. Reason: solved it

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Count parameter mismatch on QSqlQuery::exec()

    You are preparing the SQL statement in line 6, but then you do execute a different query in line 8. Since you are using the same QSqlQuery, my guess is that the begin query is wiping out the fact that you had prepared the query, etc.

    Either do your begin/commit with the QSqlDatabase instance, of move the prepare statement between the begin/commit statements (but outside of loop obviously).

    Hope that helps.

    P.S. I didn't even look at your regex. You are assuming that you're not finding data or finding the wrong data for bindValue, but I suspect your problem is inherently different than the data you're using for bindValue.

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

    adutzu89 (13th March 2015)

  4. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Count parameter mismatch on QSqlQuery::exec()

    Thanks, indeed the issue is the location where I've put the prepared statement, don't know why I didn't seen it. I even checked on some older code where I had begin/commit and even though there I've used it correctly I didn't seen differences beetween that and the way I set up my prepared query here.

Similar Threads

  1. Replies: 14
    Last Post: 16th May 2017, 03:51
  2. QT5 and SQLLite: Parameter count mismatch upon Insert
    By skruffynerherder in forum Qt Programming
    Replies: 9
    Last Post: 10th October 2014, 01:34
  3. Replies: 6
    Last Post: 13th June 2014, 06:54
  4. Sql problem - parameter mismatch count
    By Marina K. in forum Qt Programming
    Replies: 1
    Last Post: 20th June 2011, 18:27
  5. Parameter count mismatch in create table statement
    By croscato in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2011, 09:38

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.