Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlRelationalTableModel removeRows or deleteRowFromTable?

QSqlRelationalTableModel removeRows or deleteRowFromTable?

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++sql
4 Posts 3 Posters 479 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Snowman
    wrote on 17 Dec 2021, 11:20 last edited by Snowman
    #1

    Hi

    I'm currently developing an application that will be talking to a database of over 300 tables.

    All the tables share a common set of columns one of which holds whether the row is deleted or not. Yes DELETE FROM isn't called, its historic and I don't plan on changing it.

    If I create a class derived from QSqlRelationTableModel or QSqlTableModel, which of removeRows or deleteRowFromTable am I best implementing such that an UPDATE SET happens instead of the delete?

    P J 2 Replies Last reply 17 Dec 2021, 13:12
    0
    • S Snowman
      17 Dec 2021, 11:20

      Hi

      I'm currently developing an application that will be talking to a database of over 300 tables.

      All the tables share a common set of columns one of which holds whether the row is deleted or not. Yes DELETE FROM isn't called, its historic and I don't plan on changing it.

      If I create a class derived from QSqlRelationTableModel or QSqlTableModel, which of removeRows or deleteRowFromTable am I best implementing such that an UPDATE SET happens instead of the delete?

      P Online
      P Online
      Pl45m4
      wrote on 17 Dec 2021, 13:12 last edited by
      #2

      @Snowman said in QSqlRelationalTableModel removeRows or deleteRowFromTable?:

      which of removeRows or deleteRowFromTable am I best implementing such that an UPDATE SET happens instead of the delete?

      removeRow(s) will call deleteRowFromTable at the end.

      • https://doc.qt.io/qt-5/qsqltablemodel.html#deleteRowFromTable

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • S Snowman
        17 Dec 2021, 11:20

        Hi

        I'm currently developing an application that will be talking to a database of over 300 tables.

        All the tables share a common set of columns one of which holds whether the row is deleted or not. Yes DELETE FROM isn't called, its historic and I don't plan on changing it.

        If I create a class derived from QSqlRelationTableModel or QSqlTableModel, which of removeRows or deleteRowFromTable am I best implementing such that an UPDATE SET happens instead of the delete?

        J Offline
        J Offline
        JonB
        wrote on 17 Dec 2021, 13:38 last edited by JonB
        #3

        @Snowman
        As @Pl45m4 has said, deleteRowFromTable() is the low-level method which does the deletion.

        I don't know whether you will have problems. Qt assumes deleting a row will delete it from the database. There must be more to your code than your "update column for deletion instead". For example, your normal "populate table" SELECT command must be something like SELECT from table WHERE deletion_column <> true or similar? What would happen if you try to re-add a row where it already exists but has its deletion flag set --- Qt will expect to do an INSERT, you will need an un-UPDATE.

        Not saying you can't do it, just I don't know how well it will play with Qt's QSqlTableModel assumptions.....

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Snowman
          wrote on 17 Dec 2021, 14:15 last edited by
          #4

          Hi @JonB yes the selects are used as you've described. While waiting for answers I refound QxORM via Inqlude which looks like it has a soft deleted option so may more than do what I require.

          Thanks for the response

          1 Reply Last reply
          1

          4/4

          17 Dec 2021, 14:15

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved