Uploaded image for project: 'Torque'
  1. Torque
  2. TORQUE-112

Delete via Join deletes all records in the table

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.3
    • Fix Version/s: 4.0-beta1
    • Component/s: Runtime
    • Labels:
      None
    • Environment:
      mysql, at least, though I suspect this bug is not database-specific.

      Description

      When I delete using a criteria that contains a join, instead of only the records of interest being deleted, all records are deleted.

        Activity

        Hide
        tfischer Thomas Fox added a comment -

        The join will now be added correctly into the SQL query, but because of TORQUE-9 the delete will use a DELETE FROM... instead of a SELECT FROM ... and joins in deletes will produce errors in most databases.
        So in most (if not all) databases an error will be thrown if the above is attempted. To delete via a join in the future, first the entries should be selected and then deleted manually.

        Show
        tfischer Thomas Fox added a comment - The join will now be added correctly into the SQL query, but because of TORQUE-9 the delete will use a DELETE FROM... instead of a SELECT FROM ... and joins in deletes will produce errors in most databases. So in most (if not all) databases an error will be thrown if the above is attempted. To delete via a join in the future, first the entries should be selected and then deleted manually.
        Hide
        tfischer Thomas Fox added a comment -

        When TORQUE-9 is implemented, delete using joins will not work any more because most databases will not execute DELETE FROM $

        {table}

        with joins.

        Show
        tfischer Thomas Fox added a comment - When TORQUE-9 is implemented, delete using joins will not work any more because most databases will not execute DELETE FROM $ {table} with joins.
        Hide
        jzinn Julian Zinn added a comment -

        See also TORQUE-113.

        Show
        jzinn Julian Zinn added a comment - See also TORQUE-113 .
        Hide
        carlmanaster Carl Manaster added a comment -

        There doesn't appear to be any sql code in play. Instead, all records are being deleted because inside BasePeer.processTables(), whereClause is empty (resulting in a selection of all records). There are two opportunities to put something into whereClause, in the columnMaps loop. Both are passed up because crit.containsKey(key) fails with both "t2.t2_id" and "t2.t1_id". I believe that the only key in crit is "t1.t1_id", which is never examined by this code, because it studies only the columns of the table of interest, which is of course t2.

        Show
        carlmanaster Carl Manaster added a comment - There doesn't appear to be any sql code in play. Instead, all records are being deleted because inside BasePeer.processTables(), whereClause is empty (resulting in a selection of all records). There are two opportunities to put something into whereClause, in the columnMaps loop. Both are passed up because crit.containsKey(key) fails with both "t2.t2_id" and "t2.t1_id". I believe that the only key in crit is "t1.t1_id", which is never examined by this code, because it studies only the columns of the table of interest, which is of course t2.
        Hide
        carlmanaster Carl Manaster added a comment -

        Test case demonstrating the bug.

        Show
        carlmanaster Carl Manaster added a comment - Test case demonstrating the bug.

          People

          • Assignee:
            tfischer Thomas Fox
            Reporter:
            carlmanaster Carl Manaster
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 72h
              72h
              Remaining:
              Remaining Estimate - 72h
              72h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development