Skip to content

Commit be86458

Browse files
adamzielclaude
andcommitted
Use strtr with named placeholders for the zero-date CASE expression
Replace sprintf with strtr so each substituted value appears once in the argument list and the template reads like annotated SQL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 025b03d commit be86458

1 file changed

Lines changed: 18 additions & 26 deletions

File tree

wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5696,34 +5696,26 @@ private function cast_value_for_saving(
56965696
* - Enabled without strict mode: zero-part dates produce a warning and are stored as '0000-00-00'.
56975697
* - Enabled with strict mode: zero-part dates produce an error.
56985698
*/
5699-
$reject_zero_date = (
5700-
$this->is_sql_mode_active( 'NO_ZERO_DATE' ) && $is_strict_mode
5701-
) ? 1 : 0;
5702-
$reject_zero_in_date = $this->is_sql_mode_active( 'NO_ZERO_IN_DATE' ) ? 1 : 0;
5703-
$zero_date_value = 'date' === $mysql_data_type
5704-
? "'0000-00-00'"
5705-
: "'0000-00-00 00:00:00'";
5706-
5707-
return sprintf(
5699+
return strtr(
57085700
"CASE
5709-
WHEN %s IS NULL THEN NULL
5710-
WHEN %s IN ('0000-00-00', '0000-00-00 00:00:00') AND NOT %d THEN %s
5711-
WHEN SUBSTR(%s, 1, 4) != '0000' AND (SUBSTR(%s, 6, 2) = '00' OR SUBSTR(%s, 9, 2) = '00') AND NOT %d THEN %s
5712-
WHEN %s > '0' THEN %s
5713-
ELSE %s
5701+
WHEN {value} IS NULL THEN NULL
5702+
WHEN {value} IN ('0000-00-00', '0000-00-00 00:00:00') AND NOT {reject_zero_date} THEN {zero_date_value}
5703+
WHEN SUBSTR({value}, 1, 4) != '0000' AND (SUBSTR({value}, 6, 2) = '00' OR SUBSTR({value}, 9, 2) = '00') AND NOT {reject_zero_in_date} THEN {value}
5704+
WHEN {value} > '0' THEN {function_call}
5705+
ELSE {fallback}
57145706
END",
5715-
$translated_value,
5716-
$translated_value,
5717-
$reject_zero_date,
5718-
$zero_date_value,
5719-
$translated_value,
5720-
$translated_value,
5721-
$translated_value,
5722-
$reject_zero_in_date,
5723-
$translated_value,
5724-
$function_call,
5725-
$function_call,
5726-
$fallback
5707+
array(
5708+
'{value}' => $translated_value,
5709+
'{reject_zero_date}' => (
5710+
$this->is_sql_mode_active( 'NO_ZERO_DATE' ) && $is_strict_mode
5711+
) ? 1 : 0,
5712+
'{zero_date_value}' => 'date' === $mysql_data_type
5713+
? "'0000-00-00'"
5714+
: "'0000-00-00 00:00:00'",
5715+
'{reject_zero_in_date}' => $this->is_sql_mode_active( 'NO_ZERO_IN_DATE' ) ? 1 : 0,
5716+
'{function_call}' => $function_call,
5717+
'{fallback}' => $fallback,
5718+
)
57275719
);
57285720
default:
57295721
/*

0 commit comments

Comments
 (0)