Skip to content

Commit

Permalink
FIX #32376: lettering: fix ifsql() called with invalid $check parameter
Browse files Browse the repository at this point in the history
The $check is supposed to be a check retuning a boolean. By being an
`if (value)` check instead of being an `if (value IS NOT NULL)` check,
postgresql complains the types are not correct:

        Error ERROR: 42804: argument of CASE/WHEN must be type boolean,
        not type integer LINE 1: ...k, tl2.fk_doc FROM ( SELECT DISTINCT
        (CASE WHEN tll.fk_fac... ^ LOCATION: coerce_to_boolean,
        parse_coerce.c:1176

Regression from commit cfc162a.
  • Loading branch information
alexandre-janniaux committed Dec 15, 2024
1 parent 65f9e7f commit 45f6905
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions htdocs/accountancy/class/lettering.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,14 +864,14 @@ public function getLinkedDocumentByGroup($document_ids, $doc_type)
$sql = "SELECT DISTINCT tl2.fk_link, tl2.fk_doc";
$sql .= " FROM (";
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
$sql .= " SELECT DISTINCT " . $this->db->ifsql("tll.".$this->db->sanitize($linked_info['fk_table_link_line_parent']), "tll.".$this->db->sanitize($linked_info['fk_table_link_line_parent']), "tl.".$this->db->sanitize($linked_info['fk_link']))." AS fk_link, tl.".$this->db->sanitize($linked_info['fk_doc'])." AS fk_doc";
$sql .= " SELECT DISTINCT " . $this->db->ifsql("tll.".$this->db->sanitize($linked_info['fk_table_link_line_parent'])." IS NOT NULL", "tll.".$this->db->sanitize($linked_info['fk_table_link_line_parent']), "tl.".$this->db->sanitize($linked_info['fk_link']))." AS fk_link, tl.".$this->db->sanitize($linked_info['fk_doc'])." AS fk_doc";
$sql .= " FROM " . MAIN_DB_PREFIX .$this->db->sanitize($linked_info['table'])." AS tl";
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $this->db->sanitize($linked_info['table_link_line']) . " AS tll ON tll.".$this->db->sanitize($linked_info['fk_table_link_line']) . " = tl.".$this->db->sanitize($linked_info['fk_line_link']);
$sql .= ") AS tl";
$sql .= " LEFT JOIN (";
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
$sql .= " SELECT DISTINCT " . $this->db->ifsql("tll.".$this->db->sanitize($linked_info['fk_table_link_line_parent']), "tll.".$this->db->sanitize($linked_info['fk_table_link_line_parent']), "tl.".$this->db->sanitize($linked_info['fk_link']))." AS fk_link, tl.".$this->db->sanitize($linked_info['fk_doc'])." AS fk_doc";
$sql .= " SELECT DISTINCT " . $this->db->ifsql("tll.".$this->db->sanitize($linked_info['fk_table_link_line_parent'])." IS NOT NULL", "tll.".$this->db->sanitize($linked_info['fk_table_link_line_parent']), "tl.".$this->db->sanitize($linked_info['fk_link']))." AS fk_link, tl.".$this->db->sanitize($linked_info['fk_doc'])." AS fk_doc";
$sql .= " FROM " . MAIN_DB_PREFIX .$this->db->sanitize($linked_info['table'])." AS tl";
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $this->db->sanitize($linked_info['table_link_line']) . " AS tll ON tll.".$this->db->sanitize($linked_info['fk_table_link_line']) . " = tl.".$this->db->sanitize($linked_info['fk_line_link']);
Expand Down

0 comments on commit 45f6905

Please sign in to comment.