Results 1 to 10 of 10

Thread: Query problem

  1. #1
    Join Date
    Sep 2012
    Posts
    44
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Query problem

    I can't find what i make wrong, but i got always this error:

    SqLite error: " Parameter count mismatch" , SqLite error code: -1

    I double check everything.

    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("INSERT INTO partners (Company, City, Address, Bulstat, VAT, MOL, Phone, Fax, Email, Note, DateCreated )"
    3. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    4. query.bindValue(0, company);
    5. query.bindValue(1, city);
    6. query.bindValue(2, address);
    7. query.bindValue(3, bulstat);
    8. query.bindValue(4, vat);
    9. query.bindValue(5, mol);
    10. query.bindValue(6, phone);
    11. query.bindValue(7, fax);
    12. query.bindValue(8, email);
    13. query.bindValue(9, note);
    14. query.bindValue(10, "21-08-2016");
    15. query.exec();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Query problem

    The SQL looks OK.

    Does your "partners" table have 11 fields? If it has more, are the extra ones optional? Do the variable types in your bindValue() statements (and the resulting QVariant types) match the field types in the database? (The "DateCreated" field in particular?)
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Sep 2012
    Posts
    44
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Query problem

    Here is the screenshot of my SQL DB.
    https://s11.postimg.io/qo9jpuf1v/sql.png

    I updated the code like this:

    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("INSERT INTO partners (Company, City, Address, Bulstat, VAT, MOL, Phone, Fax, Email, Note, DateCreated )"
    3. "VALUES (:company, :city, :address, :bulstat, :vat, :mol, :phone, :fax, :email, :note, :date)");
    4. query.bindValue(":company", company);
    5. query.bindValue(":city", city);
    6. query.bindValue(":address", address);
    7. query.bindValue(":bulstat", bulstat);
    8. query.bindValue(":vat", vat);
    9. query.bindValue(":mol", mol);
    10. query.bindValue(":phone", phone);
    11. query.bindValue(":fax", fax);
    12. query.bindValue(":email", email);
    13. query.bindValue(":note", note);
    14. query.bindValue(":date", "21-08-2016");
    15. query.exec();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: Query problem

    Your scheme and insert don't match, there is no field in your schema named Fax.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  5. #5
    Join Date
    Sep 2012
    Posts
    44
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Query problem

    I add Fax field and still have some error.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Query problem

    Maybe because "note" is also missing?

    Did you even count the fields in the schema and the query?

    Your query has 11, your schema has 9 (10 if you have added Fax now)

    Cheers,
    _

  7. #7
    Join Date
    Sep 2012
    Posts
    44
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Query problem

    Shame on me!

    Fixed

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Query problem

    Does your "partners" table have 11 fields?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  9. #9
    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: Query problem

    Quote Originally Posted by anda_skoa View Post
    Maybe because "note" is also missing?
    heh, I stopped looking after I found a field in the query that wasn't in the schema... Never dreamed there would be more than one...
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Query problem

    I was on holiday in Canada last week. My partner and I were in the car, which we stopped at the side of the road to watch two cute grizzly bear cubs playing in the woods nearby. My partner, leaning out the open window to take as many photos as she could, didn't notice that the huge mama bear was only about 3 m away, watching her.

    The moral? Don't focus only on the details - sometimes you need to see the whole picture...
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  11. The following user says thank you to d_stranz for this useful post:

    jefftee (27th August 2016)

Similar Threads

  1. Replies: 7
    Last Post: 16th April 2015, 18:11
  2. sql query problem
    By unix7777 in forum Newbie
    Replies: 10
    Last Post: 29th August 2012, 22:04
  3. Problem Executing Query from QT
    By pranavpunjabi in forum Qt Programming
    Replies: 5
    Last Post: 20th May 2011, 12:24
  4. Sql Query Problem
    By MrShahi in forum Qt Programming
    Replies: 6
    Last Post: 30th May 2008, 10:16

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.