PDA

View Full Version : QSqlRelationalTablemodel does not update use wrong column



Carel Grosmann
24th October 2010, 12:44
I use an QTableView and a Qrelationaltablemodel
Further i use a MYSQL view (so not a table)
QSqlRelation rel("tablename", "tableid", "name");
model->setRelation(1,rel);
When i use a mysql table there is no problem, but with a mysqlview i cannot update
and i get the message:
Unable to execute statement:
"[MySQL][ODBC 5.1 Driver][mysqld-5.1.48-community]Unknown column 'name' in 'where clause'"

Is there a way to change the Updatequery??

Kind regards
Carel

ChrisW67
24th October 2010, 23:08
I think this is what you mean. When you use:


QSqlRelation rel("tablename", "tableid", "name");
model->setRelation(1,rel);

update through 'model' works, and:


QSqlRelation rel("viewname", "tableid", "name");
model->setRelation(1,rel);
it does not, giving:


Unable to execute statement:
"[MySQL][ODBC 5.1 Driver][mysqld-5.1.48-community]Unknown column 'name' in 'where clause'"

Including the 'name' column in your view would be the obvious thing to do first.

Carel Grosmann
26th October 2010, 12:38
Chris,

Thank you for your quick replay.
I had the wrong perception that views always can be updated.
That seems to be wrong.
I have now solved my problem by hiding columns and using QHeaderView and changeing columns.

Thanks
Carel