Fix query to handle null params

This commit is contained in:
Lewis Dale 2023-08-27 21:45:28 +01:00
parent 3949e611ea
commit 782c5b4b38

View File

@ -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,