Results 1 to 6 of 6

Thread: Parameter count mismatch in create table statement

  1. #1
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Parameter count mismatch in create table statement

    Hi all! I have the following code to manipulate a sqlite3 database:

    Qt Code:
    1. const QString SQL_INSERT_LANGUAGE =
    2. "INSERT INTO languages VALUES ("
    3. "null, :language, :abbreviation"
    4. ")";
    5.  
    6. const QString SQL_CREATE_TABLE_WORD =
    7. "CREATE TABLE :table ("
    8. "word VARCHAR UNIQUE, "
    9. "a INT, b INT, c INT, d INT, e INT, f INT, g INT, h INT, "
    10. "i INT, j INT, k INT, l INT, m INT, n INT, o INT, p INT, "
    11. "q INT, r INT, s INT, t INT, u INT, v INT, w INT, x INT, "
    12. "y INT, z INT, "
    13. "len INT"
    14. ")";
    15.  
    16. bool DB::addLanguage(const QVariant & language, const QVariant & abbreviation)
    17. {
    18. QSqlQuery query((*mDatabase));
    19.  
    20. query.prepare(SQL_INSERT_LANGUAGE);
    21. query.bindValue(":language", language);
    22. query.bindValue(":abbreviation", abbreviation);
    23.  
    24. if (query.exec() == false) {
    25. qDebug() << "ERROR 1 = " << query.lastError();
    26.  
    27. return false;
    28. }
    29.  
    30.  
    31. query.prepare(SQL_CREATE_TABLE_WORD);
    32. query.bindValue(":table", abbreviation);
    33.  
    34. if (query.exec() == false) { // The error is in this query
    35. qDebug() << "ERROR 2 = " << query.lastError();
    36. qDebug() << "SQL = " << query.executedQuery();
    37.  
    38. return false;
    39. }
    40.  
    41. return true;
    42. }
    To copy to clipboard, switch view to plain text mode 

    The first query executes with no problem. But when the second one is executed it give me the "Parameter count mismatch".

    Please, can someone help me???

    Thanks!!!

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Parameter count mismatch in create table statement

    Did you try to run the same query from the sqlite3 terminal? What are the errors?
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Re: Parameter count mismatch in create table statement

    In the sqlite3 terminal it works correctly. I think the problem is in the parameter binding.

  4. #4
    Join Date
    Nov 2009
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Parameter count mismatch in create table statement

    Hi,

    Are you sure that prepare reset bound values ?

    Perhaps could you try to 'clear' the query before to 'prepare' it for the second time.

    Fred.

  5. #5
    Join Date
    Oct 2008
    Location
    Brasil - São Paulo - Marília
    Posts
    28
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    3

    Default Re: Parameter count mismatch in create table statement

    I have cleared the query but it give me the same error.

    I think now that the problem is that the "binding placeholder" is the table name in que Sql statement. I think it only work if you try to bind a parameter.

  6. #6
    Join Date
    Dec 2010
    Posts
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Parameter count mismatch in create table statement

    Quote Originally Posted by croscato View Post
    I think it only work if you try to bind a parameter.
    That's the case.

Tags for this Thread

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.