January 3, 2011

Jonathan Jonathan
Lab Rat
50 posts

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?

6 replies

January 3, 2011

Mohsen Mohsen
Lab Rat
747 posts

I guess the reason is that your object which is achieved data is no longer available. Have you declared it in a private function?

 Signature 

www.madagon.com

January 3, 2011

Volker Volker
Ant Farmer
5428 posts

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.

January 4, 2011

fcrochik fcrochik
Lab Rat
517 posts

Jonathan: this is what I tried to warn you about on your original thread [developer.qt.nokia.com].

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.

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

January 4, 2011

fcrochik fcrochik
Lab Rat
517 posts

How does you select sql looks like? Have you replaced the start date column with “date(employee.”startDate”) as startDate” ?

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

January 5, 2011

Jonathan Jonathan
Lab Rat
50 posts

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.

January 5, 2011

fcrochik fcrochik
Lab Rat
517 posts

Jonathan wrote:
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.

You are welcome. Glad to hear that it worked.

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

 
  ‹‹ QMediaPlayer / QVideoWidget makes QX11EmbedContainer disappear      [SOLVED] qcombobox and clear() ››

You must log in to post a reply. Not a member yet? Register here!