From 782c5b4b3892578b220c26fa805be7c0885b28e3 Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Sun, 27 Aug 2023 21:45:28 +0100 Subject: [PATCH] Fix query to handle null params --- src/Lib/SqliteImageDb.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Lib/SqliteImageDb.php b/src/Lib/SqliteImageDb.php index a79adb6..1e9cdc2 100644 --- a/src/Lib/SqliteImageDb.php +++ b/src/Lib/SqliteImageDb.php @@ -27,7 +27,12 @@ class SqliteImageDb implements ImageDb { } public function findImage(string $path, ResizeParams $params): Image | null { - $stmt = $this->db->prepare('SELECT * FROM images WHERE path = :path AND width = :width AND height = :height AND quality = :quality'); + $query = "SELECT * FROM images WHERE path = :path"; + $query .= $params->width ? " AND width = :width" : " AND width IS NULL"; + $query .= $params->height ? " AND height = :height" : " AND height IS NULL"; + $query .= $params->quality ? " AND quality = :quality" : " AND quality IS NULL"; + + $stmt = $this->db->prepare($query); $stmt->execute([ ':path' => $path, ':width' => $params->width,