Skip to content

SQL Error with Filter "Only These Albums" + Child Albums. #16

@ajquick

Description

@ajquick

Trying to select specific albums with the tag "Only These Albums" + Child Albums results in this SQL error:

Warning: [mysql error 1064] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT DISTINCT(id)
FROM piwigo_categories
WHERE uppercats REGEXP '(^|,)4...' at line 16

This is the code being executed:

SELECT i.id
  FROM piwigo_images AS i
  WHERE
    i.id NOT IN (
      SELECT image_id
        FROM piwigo_image_category
        WHERE category_id NOT IN(
SELECT DISTINCT(id)
  FROM piwigo_categories
  WHERE uppercats REGEXP '(^|,)41(,|$)')
      )
    and i.id IN (
      SELECT image_id
        FROM piwigo_image_category
        WHERE category_id = 
SELECT DISTINCT(id)
  FROM piwigo_categories
  WHERE uppercats REGEXP '(^|,)41(,|$)'
      )
  GROUP BY i.id
  ORDER BY date_available DESC, file ASC, id ASC

Which should probably be:

SELECT i.id
  FROM piwigo_images AS i
  WHERE
    i.id NOT IN (
      SELECT image_id
        FROM piwigo_image_category
        WHERE category_id NOT IN(
SELECT DISTINCT(id)
  FROM piwigo_categories
  WHERE uppercats REGEXP '(^|,)41(,|$)')
      )
    and i.id IN (
      SELECT image_id
        FROM piwigo_image_category
        WHERE category_id IN ( 
SELECT DISTINCT(id)
  FROM piwigo_categories
  WHERE uppercats REGEXP '(^|,)41(,|$)'
      )
)
  GROUP BY i.id
  ORDER BY date_available DESC, file ASC, id ASC

This change is going from an equal operator to an IN list with parentheses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions