QSqlRelationalTableModel and SubmitAll()
I have a relational table that uses a delegate to provide a drop down. When I change a drop down value and call submitall I get a SQL Server error that says I have an invalid column name.
The view displays all of the data properly so how can I have an invalid column name? Perhaps I need to manually perform the changes to the tables?
Re: QSqlRelationalTableModel and SubmitAll()
Which column name is invalid? How does the primary key for the table look like?
Re: QSqlRelationalTableModel and SubmitAll()
The two columns that are being mapped to other tables appear to be the problem.
So in my case:
.... column n, column n + 1
state_id, user_id
When I set up the relation, I indicate which column from the state table and which column from the user table I want to replace the id values. In this case it's "state_name" and "user_name". Unfortunately SubmitAll() returns false and the error indicates that "state_name" and "user_name" are not valid column names.
Seems a bit weird to me that everything should display just fine but the submit causes problems.
Re: QSqlRelationalTableModel and SubmitAll()
The relational table model can't insert rows to tables other than the "main" table of the relation. Maybe this is the problem in your case? If so, you have to first populate the "related" table and only then change the main table.
Re: QSqlRelationalTableModel and SubmitAll()
I'm not sure if that is the problem. I'm not trying to insert into the related tables, I'm trying to submitall() when I change a value in an existing row. Shouldn't that work?
If it doesn't work that easily, then is there a way to query the model for rows that have had their data changed so that I can manually submit the changes to the related tables?
I appreciate your time Wysota.
Re: QSqlRelationalTableModel and SubmitAll()
What about my question about the primary key of the table?
Re: QSqlRelationalTableModel and SubmitAll()
Quote:
Originally Posted by
kroenecker
Maybe that's the problem, the tables have int non-null columns named "id" but they aren't actually set as primary keys in the tables themselves. Do you think that is the problem?
That's the first thing I would check. The problem you are facing is surely related to the database and not to Qt itself.
Quote:
I've got a related question: Is there a way for me to be able to view the sql statement that was internally built? If I could see that, it might help me understand this a bit better.
Yes, of course. The relational model inherits table model which in turn inherits QSqlQueryModel. So for peeking the select statement you have two choices - either through QSqlQueryModel::query() or QSqlTableModel::selectStatement(). QSqlTableModel::setPrimaryKey(), QSqlTableModel::primaryKey() are also worth having a look at. If you want to inspect the update query, you'll probably have to peek the query log of your SQL server or use QSqlQuery::lastQuery().