Results 1 to 8 of 8

Thread: QSqlRelationalTableModel and SubmitAll()

  1. #1
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel and SubmitAll()

    Which column name is invalid? How does the primary key for the table look like?

  3. #3
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  5. #5
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel and SubmitAll()

    What about my question about the primary key of the table?

  7. #7
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default

    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?

    Oh and each table has a column named "id".

    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.
    Last edited by wysota; 22nd January 2008 at 16:47. Reason: Posts merged

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlRelationalTableModel and SubmitAll()

    Quote Originally Posted by kroenecker View Post
    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.

    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().

Similar Threads

  1. QSqlTableModel submitAll access query
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 27th April 2007, 09:04
  2. submitAll() : database error
    By locus in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2007, 06:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.