PDA

View Full Version : Query problem



cpuinthebrain
23rd August 2016, 19:28
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.



QSqlQuery query;
query.prepare("INSERT INTO partners (Company, City, Address, Bulstat, VAT, MOL, Phone, Fax, Email, Note, DateCreated )"
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
query.bindValue(0, company);
query.bindValue(1, city);
query.bindValue(2, address);
query.bindValue(3, bulstat);
query.bindValue(4, vat);
query.bindValue(5, mol);
query.bindValue(6, phone);
query.bindValue(7, fax);
query.bindValue(8, email);
query.bindValue(9, note);
query.bindValue(10, "21-08-2016");
query.exec();

d_stranz
24th August 2016, 05:50
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?)

cpuinthebrain
24th August 2016, 08:09
Here is the screenshot of my SQL DB.
https://s11.postimg.io/qo9jpuf1v/sql.png

I updated the code like this:



QSqlQuery query;
query.prepare("INSERT INTO partners (Company, City, Address, Bulstat, VAT, MOL, Phone, Fax, Email, Note, DateCreated )"
"VALUES (:company, :city, :address, :bulstat, :vat, :mol, :phone, :fax, :email, :note, :date)");
query.bindValue(":company", company);
query.bindValue(":city", city);
query.bindValue(":address", address);
query.bindValue(":bulstat", bulstat);
query.bindValue(":vat", vat);
query.bindValue(":mol", mol);
query.bindValue(":phone", phone);
query.bindValue(":fax", fax);
query.bindValue(":email", email);
query.bindValue(":note", note);
query.bindValue(":date", "21-08-2016");
query.exec();

jefftee
25th August 2016, 07:37
Your scheme and insert don't match, there is no field in your schema named Fax.

cpuinthebrain
25th August 2016, 12:34
I add Fax field and still have some error.

anda_skoa
25th August 2016, 12:47
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,
_

cpuinthebrain
25th August 2016, 12:56
Shame on me!

Fixed

d_stranz
26th August 2016, 00:30
Does your "partners" table have 11 fields?

:confused:

jefftee
26th August 2016, 01:19
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... :)

d_stranz
26th August 2016, 14:58
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...