From 36fe47f8b9b23444229e7be7d0314cc0cee7a8aa Mon Sep 17 00:00:00 2001 From: Saksham Gupta Date: Thu, 27 May 2021 19:42:27 +0530 Subject: [PATCH] Fixes #16892: current_timestamp() stringified on INSERT for date field Signed-off-by: Saksham Gupta Add tests and fix condition Signed-off-by: Saksham Gupta Fix lint Signed-off-by: Saksham Gupta --- libraries/classes/InsertEdit.php | 7 ++++--- test/classes/InsertEditTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 161e41a051..d241723c7d 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1725,9 +1725,10 @@ class InsertEdit $html_output .= ''; } - if (substr($column['pma_type'], 0, 8) === 'datetime') { + if (substr($column['pma_type'], 0, 4) === 'date') { + $type = substr($column['pma_type'], 0, 8) === 'datetime' ? 'datetime' : 'date'; $html_output .= ''; + . $column_name_appendix . '" value="' . $type . '">'; } if ($column['True_Type'] === 'bit') { $html_output .= 'dbi->escapeString($current_value) . "'"; - } elseif (! ($type === 'datetime' || $type === 'timestamp') + } elseif (! ($type === 'datetime' || $type === 'timestamp' || $type === 'date') || ($current_value !== 'CURRENT_TIMESTAMP' && $current_value !== 'current_timestamp()') ) { diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 193b8d89f9..0c977f8f01 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -2182,6 +2182,35 @@ class InsertEditTest extends AbstractTestCase '', $result ); + + // case 4: (else -> date) + $column['pma_type'] = 'date'; + $result = $this->callFunction( + $this->insertEdit, + InsertEdit::class, + 'getValueColumnForOtherDatatypes', + [ + $column, + 'defchar', + 'a', + 'b', + 'c', + 22, + '<', + 12, + 1, + '/', + '<', + "foo\nbar", + $extracted_columnspec, + false, + ] + ); + + $this->assertStringContainsString( + '', + $result + ); } /**