Skip to content

Commit 64cc464

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 e4e1bbd commit 64cc464

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
@@ -5689,34 +5689,26 @@ private function cast_value_for_saving(
56895689
* - Enabled without strict mode: zero-part dates produce a warning and are stored as '0000-00-00'.
56905690
* - Enabled with strict mode: zero-part dates produce an error.
56915691
*/
5692-
$reject_zero_date = (
5693-
$this->is_sql_mode_active( 'NO_ZERO_DATE' ) && $is_strict_mode
5694-
) ? 1 : 0;
5695-
$reject_zero_in_date = $this->is_sql_mode_active( 'NO_ZERO_IN_DATE' ) ? 1 : 0;
5696-
$zero_date_value = 'date' === $mysql_data_type
5697-
? "'0000-00-00'"
5698-
: "'0000-00-00 00:00:00'";
5699-
5700-
return sprintf(
5692+
return strtr(
57015693
"CASE
5702-
WHEN %s IS NULL THEN NULL
5703-
WHEN %s IN ('0000-00-00', '0000-00-00 00:00:00') AND NOT %d THEN %s
5704-
WHEN SUBSTR(%s, 1, 4) != '0000' AND (SUBSTR(%s, 6, 2) = '00' OR SUBSTR(%s, 9, 2) = '00') AND NOT %d THEN %s
5705-
WHEN %s > '0' THEN %s
5706-
ELSE %s
5694+
WHEN {value} IS NULL THEN NULL
5695+
WHEN {value} IN ('0000-00-00', '0000-00-00 00:00:00') AND NOT {reject_zero_date} THEN {zero_date_value}
5696+
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}
5697+
WHEN {value} > '0' THEN {function_call}
5698+
ELSE {fallback}
57075699
END",
5708-
$translated_value,
5709-
$translated_value,
5710-
$reject_zero_date,
5711-
$zero_date_value,
5712-
$translated_value,
5713-
$translated_value,
5714-
$translated_value,
5715-
$reject_zero_in_date,
5716-
$translated_value,
5717-
$function_call,
5718-
$function_call,
5719-
$fallback
5700+
array(
5701+
'{value}' => $translated_value,
5702+
'{reject_zero_date}' => (
5703+
$this->is_sql_mode_active( 'NO_ZERO_DATE' ) && $is_strict_mode
5704+
) ? 1 : 0,
5705+
'{zero_date_value}' => 'date' === $mysql_data_type
5706+
? "'0000-00-00'"
5707+
: "'0000-00-00 00:00:00'",
5708+
'{reject_zero_in_date}' => $this->is_sql_mode_active( 'NO_ZERO_IN_DATE' ) ? 1 : 0,
5709+
'{function_call}' => $function_call,
5710+
'{fallback}' => $fallback,
5711+
)
57205712
);
57215713
default:
57225714
/*

0 commit comments

Comments
 (0)