Merge #19966 - Fix #19964 - decimal column type detection for import

Pull-request: #19966
Fixes: #19964
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2025-12-14 11:08:39 +01:00
commit 58cee9656f
No known key found for this signature in database
GPG Key ID: 70684F4717D49A31
4 changed files with 51 additions and 28 deletions

View File

@ -587,6 +587,7 @@ class Import
*
* @return array Contains the precision, scale, and full size
* representation of the given decimal cell
* @psalm-return array{int,int,string}
*/
public function getDecimalSize(string $cell): array
{
@ -710,15 +711,19 @@ class Import
* The last cumulative type was DECIMAL
*/
$size = $this->getDecimalSize($cell);
$m = $size[self::M];
$d = $size[self::D];
$oldM = $this->getDecimalPrecision($lastCumulativeSize);
$oldD = $this->getDecimalScale($lastCumulativeSize);
/* New val if M or D is greater than current largest */
if ($size[self::M] > $oldM || $size[self::D] > $oldD) {
/* Take the largest of both types */
return (string) (($size[self::M] > $oldM ? $size[self::M] : $oldM)
. ',' . ($size[self::D] > $oldD ? $size[self::D] : $oldD));
if ($m - $d > $oldM - $oldD || $d > $oldD) {
// Widen type to fit current cell
$newD = $oldD > $d ? $oldD : $d;
$newM = ($oldM - $oldD > $m - $d ? $oldM - $oldD : $m - $d) + $newD;
return $newM . ',' . $newD;
}
return $lastCumulativeSize;

View File

@ -20522,7 +20522,7 @@ parameters:
-
message: "#^Casting to string something that's already string\\.$#"
count: 4
count: 3
path: libraries/classes/Import.php
-
@ -20570,21 +20570,11 @@ parameters:
count: 1
path: libraries/classes/Import.php
-
message: "#^Method PhpMyAdmin\\\\Import\\:\\:detectSize\\(\\) should return int\\|string but returns mixed\\.$#"
count: 3
path: libraries/classes/Import.php
-
message: "#^Method PhpMyAdmin\\\\Import\\:\\:executeQuery\\(\\) has parameter \\$sqlData with no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Import.php
-
message: "#^Method PhpMyAdmin\\\\Import\\:\\:getDecimalSize\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: libraries/classes/Import.php
-
message: "#^Method PhpMyAdmin\\\\Import\\:\\:getLocalFiles\\(\\) has parameter \\$importList with no value type specified in iterable type array\\.$#"
count: 1

View File

@ -7838,14 +7838,11 @@
<code>$sql_query</code>
<code>$table</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="1">
<code>string|int</code>
</MixedInferredReturnType>
<MixedMethodCall occurrences="2">
<code>getExtension</code>
<code>getProperties</code>
</MixedMethodCall>
<MixedOperand occurrences="19">
<MixedOperand occurrences="16">
<code>$complete_query</code>
<code>$display_query</code>
<code>$executed_queries</code>
@ -7855,9 +7852,6 @@
<code>$read_multiply</code>
<code>$size</code>
<code>$size</code>
<code>$size[self::D]</code>
<code>$size[self::D] &gt; $oldD ? $size[self::D] : $oldD</code>
<code>$size[self::M] &gt; $oldM ? $size[self::M] : $oldM</code>
<code>$skip_queries</code>
<code>$sqlData['valid_queries']</code>
<code>$sqlData['valid_queries']</code>
@ -7866,11 +7860,6 @@
<code>$sql_query</code>
<code>$timestamp</code>
</MixedOperand>
<MixedReturnStatement occurrences="3">
<code>$size[self::FULL]</code>
<code>$size[self::FULL]</code>
<code>$size[self::M]</code>
</MixedReturnStatement>
<PossiblyFalseOperand occurrences="3">
<code>$decPos</code>
<code>strpos($lastCumulativeSize, ',')</code>
@ -7890,7 +7879,7 @@
<PossiblyNullArrayAccess occurrences="1">
<code>$additionalSql[$i]</code>
</PossiblyNullArrayAccess>
<RedundantCast occurrences="4">
<RedundantCast occurrences="3">
<code>(string) $cell</code>
<code>(string) $cell</code>
<code>(string) $cell</code>

View File

@ -455,6 +455,45 @@ class ImportTest extends AbstractTestCase
return $data;
}
/**
* Test for detectSize
*
* @param string|int $lastCumulativeSize Last cumulative column size
* @param int|null $lastCumulativeType Last cumulative column type (NONE or VARCHAR or DECIMAL or INT or BIGINT)
* @param int $currentCellType Type of the current cell (NONE or VARCHAR or DECIMAL or INT or BIGINT)
* @param string $cell The current cell
*
* @dataProvider provTestDetectSize
*/
public function testDetectSize(
string $expected,
$lastCumulativeSize,
?int $lastCumulativeType,
int $currentCellType,
string $cell
): void {
$actual = $this->import->detectSize($lastCumulativeSize, $lastCumulativeType, $currentCellType, $cell);
self::assertSame($expected, $actual);
}
/**
* Data provider for testDetectSize
*
* @return array<array{string,string|int,int,int,string}>
*/
public function provTestDetectSize(): array
{
return [
[
'8,3',
'7,2',
Import::DECIMAL,
Import::DECIMAL,
'11.555',
],
];
}
/**
* Test for checkIfRollbackPossible
*/