Fix decimal column type detection for import
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
This commit is contained in:
parent
38ef3239cb
commit
a447dc83da
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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] > $oldD ? $size[self::D] : $oldD</code>
|
||||
<code>$size[self::M] > $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>
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user