From c30b24d09f4096e612965af658540595262f6848 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 30 Dec 2022 19:51:34 +0300 Subject: deal with type errors in batch feed editor properly, un-deprecate PDO wrapper functions and document them for posterity --- include/functions.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/functions.php b/include/functions.php index 403c96b85..0d7f8c756 100644 --- a/include/functions.php +++ b/include/functions.php @@ -357,9 +357,11 @@ return $s && ($s !== "f" && $s !== "false"); //no-op for PDO, backwards compat for legacy layer } - /** @deprecated misleading name, seems to be pointless wrapper */ + /** workaround for PDO casting all query parameters to string unless type is specified explicitly, + * which breaks booleans having false value because they become empty string literals ("") causing + * DB type mismatches and breaking SQL queries */ function bool_to_sql_bool(bool $s): int { - return $s ? 1 : 0; + return (int)$s; } function file_is_locked(string $filename): bool { @@ -411,12 +413,13 @@ } } - /** + /** checkbox-specific workaround for PDO casting all query parameters to string unless type is + * specified explicitly, which breaks booleans having false value because they become empty + * string literals ("") causing DB type mismatches and breaking SQL queries * @param mixed $val - * @deprecated misleading name, seems to be a pointless wrapper */ function checkbox_to_sql_bool($val): int { - return ($val == "on") ? 1 : 0; + return ($val === "on") ? 1 : 0; } function uniqid_short(): string { -- cgit v1.2.3