Comment to 'Messenger error'
Comment to Messenger error
  • another example, uninstalling the notification mode gives me another error:

    SET @sName = 'bx_notifications';
    
    
    
    DROP TABLE IF EXISTS `bx_notifications_events`, `bx_notifications_events2users`, `bx_notifications_read`;
    DROP TABLE IF EXISTS `bx_notifications_handlers`, `bx_notifications_settings`, `bx_notifications_settings2users`;
    DROP TABLE IF EXISTS `bx_notifications_queue`;
    
    
    
    -- STUDIO PAGE & WIDGET
    DELETE FROM `tp`, `tw`, `twb`, `tpw` 
    USING `sys_std_pages` AS `tp` LEFT JOIN `sys_std_widgets` AS `tw` ON `tp`.`id` = `tw`.`page_id` LEFT JOIN `sys_std_widgets_bookmarks` AS `twb` ON `tw`.`id` = `twb`.`widget_id` LEFT JOIN `sys_std_pages_widgets` AS `tpw` ON `tw`.`id` = `tpw`.`widget_id`
    WHERE  `tp`.`name` = @sName;
    
    
    

    Only after modifying the uninstall.sql file did I manage to uninstall the module.

    In your SQL script, the issue arises with the `DELETE` command used to remove records from the `sys_std_pages`, `sys_std_widgets`, `sys_std_widgets_bookmarks`, and `sys_std_pages_widgets` tables. In MySQL, the `DELETE ... USING` syntax is not supported as it is in other SQL databases. Instead, MySQL requires a different approach to delete records that are related through JOINs.

    Here's how you can correct the SQL command:

    Correcting the `DELETE` Command

    1. Delete Data from Dependent Tables:

      - First, delete records from the dependent tables (i.e., tables that have `FOREIGN KEY` references to the primary tables).

    2. Delete Data from Primary Tables:

      - After deleting data from the dependent tables, you can then delete data from the primary tables.

    Here’s how you can rephrase the SQL command to delete data from the respective tables:

    SET @sName = 'bx_notifications';
    -- Delete data from dependent tables
    DELETE `tpw` FROM `sys_std_pages_widgets` AS `tpw`
    JOIN `sys_std_widgets` AS `tw` ON `tpw`.`widget_id` = `tw`.`id`
    JOIN `sys_std_widgets_bookmarks` AS `twb` ON `tw`.`id` = `twb`.`widget_id`
    JOIN `sys_std_pages` AS `tp` ON `tp`.`id` = `tw`.`page_id`
    WHERE `tp`.`name` = @sName;
    DELETE `twb` FROM `sys_std_widgets_bookmarks` AS `twb`
    JOIN `sys_std_widgets` AS `tw` ON `twb`.`widget_id` = `tw`.`id`
    JOIN `sys_std_pages` AS `tp` ON `tp`.`id` = `tw`.`page_id`
    WHERE `tp`.`name` = @sName;
    DELETE `tw` FROM `sys_std_widgets` AS `tw`
    JOIN `sys_std_pages` AS `tp` ON `tp`.`id` = `tw`.`page_id`
    WHERE `tp`.`name` = @sName;
    DELETE `tp` FROM `sys_std_pages` AS `tp`
    WHERE `tp`.`name` = @sName;
    

    Explanation

    - First `DELETE`: Removes records from `sys_std_pages_widgets` (tpw) that are associated with widgets and pages where `name` equals `@sName`.

    - Second `DELETE`: Removes records from `sys_std_widgets_bookmarks` (twb) that are associated with widgets with `page_id` in the specified page.

    - Third `DELETE`: Removes records from `sys_std_widgets` (tw) that have `page_id` in the specified page.

    - Fourth `DELETE`**: Removes records from `sys_std_pages` (tp) where `name` equals `@sName`.

    This approach ensures that all records are deleted according to the relationships between the tables and prevents issues with references.

    Make sure to take a complete backup of the database before running these commands, as data deletion is irreversible.