The grammar looks right. Maybe you should try to add your database to the query declaration so the query knows which is the default database?
The grammar looks right. Maybe you should try to add your database to the query declaration so the query knows which is the default database?
Hi Unix777,
I make a sample using postgresql, hope this can help you
Qt Code:
if (!db.isOpen()) db.open(); db.close();To copy to clipboard, switch view to plain text mode
Regards,
Mardi
As Mardi's example shows,
is not a valid SQL statement, it should read :Qt Code:
query.prepare("UPDATE SET clients ClientName=:name, ClientCity=:city, ClientAddress=:address, ClientMol=:mol, ClientEik=:eik, ClientVat=:vat, ClientTel=:tel, ClientMail=:mail WHERE ROWID=:rowid");To copy to clipboard, switch view to plain text mode
Do NOT build SQL by pasting strings as Mardi suggests. Using bindValue() is, by far, the better and safer option.
At first thank you to both of you!
I've changed the code to:
Qt Code:
QSqlQuery query; query.prepare("UPDATE clients SET ClientName=:name, ClientCity=:city, ClientAddress=:address, ClientMol=:mol, ClientEik=:eik, ClientVat=:vat, ClientTel=:tel, ClientMail=:mail WHERE ROWID=:rowid"); query.bindValue(":name", ui->lineEdit_name->text()); query.bindValue(":city", ui->lineEdit_city->text()); query.bindValue(":address", ui->lineEdit_address->text()); query.bindValue(":mol", ui->lineEdit_mol->text()); query.bindValue(":eik", ui->lineEdit_eik->text()); query.bindValue(":vat", ui->lineEdit_vat->text()); query.bindValue(":tel", ui->lineEdit_tel->text()); query.bindValue(":mail", ui->lineEdit_mail->text()); query.exec();To copy to clipboard, switch view to plain text mode
But still nothing happens.The db is declared in main function and this is not the problem, because INSERT function works on same way!
Another suggestions?
Because the glass ball is now free :
1. Why are binding to :rowid text value not number ? What is a type of rowid column in database ?
2. What is a result of query.exec() (true or false).
3. If false what is a result of query.lastError().
With this code i got "Success!" but nothing happens again!
In accordance with sqlite documentation ROWID should be a int.
Qt Code:
QSqlQuery query; query.prepare("UPDATE clients SET ClientName=:name, ClientCity=:city, ClientAddress=:address, ClientMol=:mol, ClientEik=:eik, ClientVat=:vat, ClientTel=:tel, ClientMail=:mail WHERE ROWID=:rowid"); query.bindValue(":name", ui->lineEdit_name->text()); query.bindValue(":city", ui->lineEdit_city->text()); query.bindValue(":address", ui->lineEdit_address->text()); query.bindValue(":mol", ui->lineEdit_mol->text()); query.bindValue(":eik", ui->lineEdit_eik->text()); query.bindValue(":vat", ui->lineEdit_vat->text()); query.bindValue(":tel", ui->lineEdit_tel->text()); query.bindValue(":mail", ui->lineEdit_mail->text()); query.bindValue(":rowid", rowid); if (query.exec()) { emit updateTable(); } else { } this->close();To copy to clipboard, switch view to plain text mode
It just means that the SQL statement is correct formally. What is the value of the variable rowid ? There has to be a record in the table with the corresponding rowid ?
The SQLite editor i use SQLiteStudio doesn't show ROWID. In the program row id is an int.But in another parts i use QString to insert it in the query.
Where did you get the value of rowid?
there is a member function that set it.And i pass it after creating the object.The rowid int works i test it with QMessage, it display exactly what i select.
If "nothing is happening" then either;
- the rowid is does not correspond to any row in the table, or
- the row already contained the data you were updating it to and therefore has no net change.
ROWID is an internal row identifier provided by Sqlite. It is a 64-bit integer allocated by Sqlite (not you). The only reasonable source for a rowid is from an existing row in the same Sqlite table.
I have changed everything.In accordance with documentation here http://stackoverflow.com/questions/5...em-with-python
i add id int and i give NULL for every record.On this way it auto-increment every next record.What happens - everything work except the UPDATE statement.
It gives me: " Parameter count mismatch"!
Qt Code:
QSqlQuery query; query.prepare("UPDATE clients SET (ClientName, ClientCity, ClientAddress, ClientMol, ClientEik, ClientVat, ClientTel, ClientMail) WHERE id="+row+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); query.addBindValue(ui->lineEdit_name->text()); query.addBindValue(ui->lineEdit_city->text()); query.addBindValue(ui->lineEdit_address->text()); query.addBindValue(ui->lineEdit_mol->text()); query.addBindValue(ui->lineEdit_eik->text()); query.addBindValue(ui->lineEdit_vat->text()); query.addBindValue(ui->lineEdit_tel->text()); query.addBindValue(ui->lineEdit_mail->text()); this->close(); if (query.exec()) { emit updateTable(); } else { } this->close();To copy to clipboard, switch view to plain text mode
I would like to test it with some exact number of row, for example i want to update row 1 only to see whether it works.Unfortunately i don't know the syntax to do it.
Bookmarks