Can't save data with customised SQLRelationalTableModel
I've created a subclass of SQLRelationalTableModel and overridden selectStatement(). This is so that I can modify the select statement to convert integers to dates (I'm using SQLite).
This works fine, and it appears that I can update the view (QTableView) correctly
Unfortunately when I call submitAll() on my model I get the error "no such column: startDate) Unable to execute statement".
The column in question is "employee.startDate". How can I see the SQL statement that will be used to update my database? And how can I then modify it if necessary?
I guess the reason is that your object which is achieved data is no longer available. Have you declared it in a private function?
Probable this is because your select query creates a new column with the converted date and a column alias, so the original column is missing from the query, or something like that.
Jonathan: this is what I tried to warn you about on your "original thread":http://developer.qt.nokia.com/forums/viewthread/2862/.
You may want to look into the source for the QSQLRelationTableModel to see how it works. I assume it can get the column name if you a query or may have issues dealing with different data types.
How does you select sql looks like? Have you replaced the start date column with "date(employee.”startDate”) as startDate" ?
Thanks fcrochik, you've highlighted my mistake. Originally I just replaced "startDate" with "date(employee."startDate")".
Replacing it with “date(employee.”startDate”) as startDate” cures the problem.
[quote author="Jonathan" date="1294216603"]Thanks fcrochik, you've highlighted my mistake. Originally I just replaced "startDate" with "date(employee."startDate")".
Replacing it with “date(employee.”startDate”) as startDate” cures the problem.[/quote]
You are welcome. Glad to hear that it worked.