Skip to content

Commit d599661

Browse files
committed
2134: Fixed sql error in relations modified listener
1 parent 2ab99ff commit d599661

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
## [2.0.7] - 2024-08-20
8+
9+
- [#211](https://github.com/os2display/display-api-service/pull/211)
10+
- Fixed sql error in relations modified listener
11+
712
## [2.0.6] - 2024-06-28
813

914
- [#208](https://github.com/os2display/display-api-service/pull/208)

src/EventListener/RelationsChecksumListener.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private static function getToOneQuery(string $jsonKey, string $parentTable, stri
378378
* INNER JOIN (
379379
* SELECT
380380
* c.playlist_id,
381-
* CAST(GROUP_CONCAT(c.changed SEPARATOR "") > 0 AS UNSIGNED) changed,
381+
* CAST(GROUP_CONCAT(DISTINCT c.changed SEPARATOR "") > 0 AS UNSIGNED) changed,
382382
* SHA1(GROUP_CONCAT(c.id, c.version, c.relations_checksum)) checksum
383383
* FROM
384384
* playlist_slide c
@@ -392,10 +392,11 @@ private static function getToOneQuery(string $jsonKey, string $parentTable, stri
392392
* Explanation:
393393
* Because this is a "to many" relation we need to GROUP_CONCAT values from the child relations. This is done in a temporary table
394394
* with GROUP BY parent id in the child table. This gives us just one child row for each parent row with a checksum from the relevant
395-
* fields across all child rows.
395+
* fields across all child rows. We use a DISTINCT clause in GROUP_CONCAT to limit the length of the resulting value and avoid
396+
* illegal integer values.
396397
*
397398
* This temp table is then joined to the parent table to allow us to SET the p.changed and p.relations_checksum values on the parent.
398-
* - Because GROUP_CONCAT will give us all child rows "changed" as one, e.g. "00010001" we need "> 0" to ecaluate to true/false
399+
* - Because GROUP_CONCAT will give us all child rows "changed" as one, e.g. "00010001" we need "> 0" to evaluate to true/false
399400
* and then CAST that to "unsigned" to get a TINYINT (bool)
400401
* WHERE either p.changed or c.changed is true
401402
* - Because we can't easily get a list of ID's of affected rows as we work up the tree we use the bool "changed" as clause in
@@ -413,7 +414,7 @@ private static function getOneToManyQuery(string $jsonKey, string $parentTable,
413414
INNER JOIN (
414415
SELECT
415416
c.%s,
416-
CAST(GROUP_CONCAT(c.changed SEPARATOR "") > 0 AS UNSIGNED) changed,
417+
CAST(GROUP_CONCAT(DISTINCT c.changed SEPARATOR "") > 0 AS UNSIGNED) changed,
417418
SHA1(GROUP_CONCAT(c.id, c.version, c.relations_checksum)) checksum
418419
FROM
419420
%s c
@@ -448,7 +449,7 @@ private static function getOneToManyQuery(string $jsonKey, string $parentTable,
448449
* INNER JOIN (
449450
* SELECT
450451
* pivot.slide_id,
451-
* CAST(GROUP_CONCAT(c.changed SEPARATOR "") > 0 AS UNSIGNED) changed,
452+
* CAST(GROUP_CONCAT(DISTINCT c.changed SEPARATOR "") > 0 AS UNSIGNED) changed,
452453
* SHA1(GROUP_CONCAT(c.id, c.version, c.relations_checksum)) checksum
453454
* FROM
454455
* slide_media pivot
@@ -463,10 +464,11 @@ private static function getOneToManyQuery(string $jsonKey, string $parentTable,
463464
* Explanation:
464465
* Because this is a "to many" relation we need to GROUP_CONCAT values from the child relations. This is done in a temporary table
465466
* with GROUP BY parent id in the child table. This gives us just one child row for each parent row with a checksum from the relevant
466-
* fields across all child rows.
467+
* fields across all child rows. We use a DISTINCT clause in GROUP_CONCAT to limit the length of the resulting value and avoid
468+
* illegal integer values.
467469
*
468470
* This temp table is then joined to the parent table to allow us to SET the p.changed and p.relations_checksum values on the parent.
469-
* - Because GROUP_CONCAT will give us all child rows "changed" as one, e.g. "00010001" we need "> 0" to ecaluate to true/false
471+
* - Because GROUP_CONCAT will give us all child rows "changed" as one, e.g. "00010001" we need "> 0" to evaluate to true/false
470472
* and then CAST that to "unsigned" to get a TINYINT (bool)
471473
* WHERE either p.changed or c.changed is true
472474
* - Because we can't easily get a list of ID's of affected rows as we work up the tree we use the bool "changed" as clause in
@@ -485,7 +487,7 @@ private static function getManyToManyQuery(string $jsonKey, string $parentTable,
485487
INNER JOIN (
486488
SELECT
487489
pivot.%s,
488-
CAST(GROUP_CONCAT(c.changed SEPARATOR "") > 0 AS UNSIGNED) changed,
490+
CAST(GROUP_CONCAT(DISTINCT c.changed SEPARATOR "") > 0 AS UNSIGNED) changed,
489491
SHA1(GROUP_CONCAT(c.id, c.version, c.relations_checksum)) checksum
490492
FROM
491493
%s pivot

0 commit comments

Comments
 (0)