From 3e3803ee20dc3dfc3d21e5cafa7a76159c8d4aba Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 1 Mar 2021 11:14:32 +0100 Subject: [PATCH] Bug 27821: Make sanitize_zero_date support datetime and timestamp Signed-off-by: Jonathan Druart --- installer/data/mysql/updatedatabase.pl | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 0cad111f93..1c5c24a653 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -23670,11 +23670,23 @@ sub CheckVersion { sub sanitize_zero_date { my ( $table_name, $column_name ) = @_; - $dbh->do(qq| - UPDATE $table_name - SET $column_name = NULL - WHERE CAST($column_name AS CHAR(10)) = '0000-00-00'; - |); + + my (undef, $datatype) = $dbh->selectrow_array(qq| + SHOW COLUMNS FROM $table_name WHERE Field = ?|, undef, $column_name); + + if ( $datatype eq 'date' ) { + $dbh->do(qq| + UPDATE $table_name + SET $column_name = NULL + WHERE CAST($column_name AS CHAR(10)) = '0000-00-00'; + |); + } else { + $dbh->do(qq| + UPDATE $table_name + SET $column_name = NULL + WHERE CAST($column_name AS CHAR(19)) = '0000-00-00 00:00:00'; + |); + } } exit; -- 2.39.5