Merge pull request #17673 from kamil-tekiela/unique

Allow empty values to be inserted into columns
This commit is contained in:
Maurício Meneghini Fauth 2022-08-12 20:36:44 -03:00 committed by GitHub
commit 1ec5502ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 123 additions and 4 deletions

View File

@ -1674,9 +1674,8 @@ class InsertEdit
} elseif (
! (empty($multiEditFuncs[$key])
&& isset($multiEditColumnsPrev[$key])
&& (($currentValue === "'" . $this->dbi->escapeString($multiEditColumnsPrev[$key]) . "'")
|| ($currentValue === '0x' . $multiEditColumnsPrev[$key])))
&& $currentValue
&& $currentValue === $multiEditColumnsPrev[$key])
&& $currentValueAsAnArray !== ''
) {
// avoid setting a field to NULL when it's already NULL
// (field had the null checkbox before the update

View File

@ -1448,7 +1448,7 @@ class Sql
}
}
$hasUnique = $table && $this->resultSetContainsUniqueKey($db, $table, $fieldsMeta);
$hasUnique = $table !== null && $this->resultSetContainsUniqueKey($db, $table, $fieldsMeta);
$editable = ($hasUnique
|| $GLOBALS['cfg']['RowActionLinksWithoutUnique']

View File

@ -2023,6 +2023,126 @@ class InsertEditTest extends AbstractTestCase
],
$result
);
// Test to see if a zero-string is not ignored
$result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit(
$multi_edit_columns_name,
[],
'0',
[],
[],
false,
[],
[],
"'0'",
[],
'0',
[]
);
$this->assertEquals(
[
["`fld` = '0'"],
[],
],
$result
);
// Can only happen when table contains blob field that was left unchanged during edit
$result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit(
$multi_edit_columns_name,
[],
'',
[],
[],
false,
[],
[],
'',
[],
'0',
[]
);
$this->assertEquals(
[
[],
[],
],
$result
);
// Test to see if a field will be set to null when it wasn't null previously
$result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit(
$multi_edit_columns_name,
['on'],
'',
[],
[],
false,
[],
[],
'NULL',
[],
'0',
[]
);
$this->assertEquals(
[
['`fld` = NULL'],
[],
],
$result
);
// Test to see if a field will be ignored if it was null previously
$result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit(
$multi_edit_columns_name,
['on'],
'',
[],
[],
false,
[],
[],
'NULL',
[],
'0',
['on']
);
$this->assertEquals(
[
[],
[],
],
$result
);
// Test to see if a field will be ignored if it the value is unchanged
$result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit(
$multi_edit_columns_name,
[],
"a'b",
["a'b"],
[],
false,
[],
[],
"'a\'b'",
[],
'0',
[]
);
$this->assertEquals(
[
[],
[],
],
$result
);
}
/**