diff options
author | Mo Sureerat <sureemo@gmail.com> | 2022-11-02 21:05:11 +0300 |
---|---|---|
committer | Mo Sureerat <sureemo@gmail.com> | 2022-11-02 23:01:38 +0300 |
commit | 7615c7e780bb49030d235a54de6383ced178b935 (patch) | |
tree | a497dbb2c8f5ec609e607a378fffec38e2b97d2d | |
parent | bff74dc588895c58a409af222e9d8911f4620fd7 (diff) |
[ISSUE-17793] Insert record - fix null not selected if nullable UUID + insert error
Signed-off-by: Mo Sureerat <sureemo@gmail.com>
-rw-r--r-- | libraries/classes/InsertEdit.php | 9 | ||||
-rw-r--r-- | test/classes/InsertEditTest.php | 190 |
2 files changed, 164 insertions, 35 deletions
diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 3e6ab3e411..cea65e632c 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1106,7 +1106,14 @@ class InsertEdit private function getSpecialCharsAndBackupFieldForInsertingMode( array $column ) { - if (! isset($column['Default'])) { + $isNullableUUID = ! empty($column['True_Type']) + && ! empty($column['Default']) + && ! empty($column['Null']) + && $column['True_Type'] === 'uuid' + && $column['Default'] === 'uuid()' + && $column['Null'] === 'YES'; + + if ($isNullableUUID || (! isset($column['Default']))) { $column['Default'] = ''; $realNullValue = true; $data = ''; diff --git a/test/classes/InsertEditTest.php b/test/classes/InsertEditTest.php index 36186fd19e..06bf72becf 100644 --- a/test/classes/InsertEditTest.php +++ b/test/classes/InsertEditTest.php @@ -1590,17 +1590,22 @@ class InsertEditTest extends AbstractTestCase /** * Test for getSpecialCharsAndBackupFieldForInsertingMode + * + * @param array $column Column parameters + * @param array $expected Expected result + * @psalm-param array<string, string|bool|null> $column + * @psalm-param array<bool|string> $expected + * + * @dataProvider providerForTestGetSpecialCharsAndBackupFieldForInsertingMode */ - public function testGetSpecialCharsAndBackupFieldForInsertingMode(): void - { - $column = []; - $column['True_Type'] = 'bit'; - $column['Default'] = 'b\'101\''; - $column['is_binary'] = true; + public function testGetSpecialCharsAndBackupFieldForInsertingMode( + array $column, + array $expected + ): void { $GLOBALS['cfg']['ProtectBinary'] = false; $GLOBALS['cfg']['ShowFunctionFields'] = true; - $result = $this->callFunction( + $result = (array) $this->callFunction( $this->insertEdit, InsertEdit::class, 'getSpecialCharsAndBackupFieldForInsertingMode', @@ -1608,37 +1613,154 @@ class InsertEditTest extends AbstractTestCase ); $this->assertEquals( - [ - false, - 'b\'101\'', - '101', - '', - '101', - ], + $expected, $result ); + } - // case 2 - unset($column['Default']); - $column['True_Type'] = 'char'; - - $result = (array) $this->callFunction( - $this->insertEdit, - InsertEdit::class, - 'getSpecialCharsAndBackupFieldForInsertingMode', - [$column] - ); - - $this->assertEquals( - [ - true, - '', - '', - '', - '', + /** + * Data provider for test getSpecialCharsAndBackupFieldForInsertingMode() + * + * @return array + * @psalm-return array<string, array{array<string, string|bool|null>, array<bool|string>}> + */ + public function providerForTestGetSpecialCharsAndBackupFieldForInsertingMode(): array + { + return [ + 'bit' => [ + [ + 'True_Type' => 'bit', + 'Default' => 'b\'101\'', + 'is_binary' => true, + ], + [ + false, + 'b\'101\'', + '101', + '', + '101', + ], ], - $result - ); + 'char' => [ + [ + 'True_Type' => 'char', + 'is_binary' => true, + ], + [ + true, + '', + '', + '', + '', + ], + ], + 'time with CURRENT_TIMESTAMP value' => [ + [ + 'True_Type' => 'time', + 'Default' => 'CURRENT_TIMESTAMP', + ], + [ + false, + 'CURRENT_TIMESTAMP', + 'CURRENT_TIMESTAMP', + '', + 'CURRENT_TIMESTAMP', + ], + ], + 'time with current_timestamp() value' => [ + [ + 'True_Type' => 'time', + 'Default' => 'current_timestamp()', + ], + [ + false, + 'current_timestamp()', + 'current_timestamp()', + '', + 'current_timestamp()', + ], + ], + 'time with no dot value' => [ + [ + 'True_Type' => 'time', + 'Default' => '10', + ], + [ + false, + '10', + '10.000000', + '', + '10.000000', + ], + ], + 'time with dot value' => [ + [ + 'True_Type' => 'time', + 'Default' => '10.08', + ], + [ + false, + '10.08', + '10.080000', + '', + '10.080000', + ], + ], + 'any text with escape text default' => [ + [ + 'True_Type' => 'text', + 'Default' => '"lorem\"ipsem"', + ], + [ + false, + '"lorem\"ipsem"', + 'lorem"ipsem', + '', + 'lorem"ipsem', + ], + ], + 'varchar with html special chars' => [ + [ + 'True_Type' => 'varchar', + 'Default' => 'hello world<br><b>lorem</b> ipsem', + ], + [ + false, + 'hello world<br><b>lorem</b> ipsem', + 'hello world<br><b>lorem</b> ipsem', + '', + 'hello world<br><b>lorem</b> ipsem', + ], + ], + 'uuid with nullable' => [ + [ + 'True_Type' => 'uuid', + 'Default' => 'uuid()', + 'Null' => 'YES', + ], + [ + true, + '', + '', + '', + '', + ], + ], + 'uuid with not nullable' => [ + [ + 'True_Type' => 'uuid', + 'Default' => 'uuid()', + 'Null' => 'NO', + ], + [ + false, + 'uuid()', + 'uuid()', + '', + 'uuid()', + ], + ], + ]; } /** |