Skip to content

Commit

Permalink
Implement getValuesForCsvTable
Browse files Browse the repository at this point in the history
Signed-off-by: Liviu-Mihail Concioiu <[email protected]>
  • Loading branch information
liviuconcioiu committed Jan 18, 2025
1 parent 38bbaff commit 500d4db
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/Controllers/Database/StructureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,13 @@ private function getStuffForEngineTypeTable(
$sumSize,
);
break;
case 'CSV':
[$currentTable, $formattedSize, $unit, $sumSize] = $this->getValuesForCsvTable(
$currentTable,
$sumSize,
);
break;

// Mysql 5.0.x (and lower) uses MRG_MyISAM
// and MySQL 5.1.x (and higher) uses MRG_MYISAM
// Both are aliases for MERGE
Expand Down Expand Up @@ -835,6 +842,74 @@ private function getValuesForInnodbTable(
return [$currentTable, $formattedSize, $unit, $sumSize];
}

/**
* Get values for CSV table
*
* https://bugs.mysql.com/bug.php?id=53929
*
* @param mixed[] $currentTable current table
* @param int $sumSize sum size
*
* @return mixed[]
*/
private function getValuesForCsvTable(
array $currentTable,
int $sumSize,
): array {
$formattedSize = $unit = '';

if (
(in_array($currentTable['ENGINE'], ['CSV'], true)
&& $currentTable['TABLE_ROWS'] < Config::getInstance()->settings['MaxExactCount'])

Check failure on line 863 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

DeprecatedMethod

src/Controllers/Database/StructureController.php:863:46: DeprecatedMethod: The method PhpMyAdmin\Config::getInstance has been marked as deprecated (see https://psalm.dev/001)

Check failure on line 863 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

Call to deprecated method getInstance() of class PhpMyAdmin\Config: Use dependency injection instead.
|| ! isset($currentTable['TABLE_ROWS'])
) {
$currentTable['COUNTED'] = true;
$currentTable['TABLE_ROWS'] = $this->dbi
->getTable(Current::$database, $currentTable['TABLE_NAME'])

Check failure on line 868 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

MixedArgument

src/Controllers/Database/StructureController.php:868:48: MixedArgument: Argument 2 of PhpMyAdmin\Dbal\DatabaseInterface::getTable cannot be mixed, expecting string (see https://psalm.dev/030)

Check failure on line 868 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

Parameter #2 $tableName of method PhpMyAdmin\Dbal\DatabaseInterface::getTable() expects string, mixed given.
->countRecords(true);
} else {
$currentTable['COUNTED'] = false;
}

if ($this->isShowStats) {
// Only count columns that have double quotes
$columnCount = (int) $this->dbi->fetchValue(
'SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '
. $this->dbi->quoteString(Current::$database) . ' AND TABLE_NAME = '
. $this->dbi->quoteString($currentTable['TABLE_NAME']) . ' AND NUMERIC_SCALE IS NULL;'

Check failure on line 879 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

MixedArgument

src/Controllers/Database/StructureController.php:879:43: MixedArgument: Argument 1 of PhpMyAdmin\Dbal\DatabaseInterface::quoteString cannot be mixed, expecting string (see https://psalm.dev/030)

Check failure on line 879 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

Parameter #1 $str of method PhpMyAdmin\Dbal\DatabaseInterface::quoteString() expects string, mixed given.
);

// Get column names
$columnNames = $this->dbi->fetchValue(
'SELECT GROUP_CONCAT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '
. $this->dbi->quoteString(Current::$database) . ' AND TABLE_NAME = '
. $this->dbi->quoteString($currentTable['TABLE_NAME']) . ';'

Check failure on line 886 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

MixedArgument

src/Controllers/Database/StructureController.php:886:43: MixedArgument: Argument 1 of PhpMyAdmin\Dbal\DatabaseInterface::quoteString cannot be mixed, expecting string (see https://psalm.dev/030)

Check failure on line 886 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

Parameter #1 $str of method PhpMyAdmin\Dbal\DatabaseInterface::quoteString() expects string, mixed given.
);

// 10Mb buffer for CONCAT_WS
// not sure if is needed
$this->dbi->query('SET SESSION group_concat_max_len = 10 * 1024 * 1024');

// Calculate data length
$dataLength = (int) $this->dbi->fetchValue('
SELECT SUM(CHAR_LENGTH(REPLACE(REPLACE(REPLACE(
CONCAT_WS(\',\', ' . $columnNames . '),

Check failure on line 896 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

PossiblyNullOperand

src/Controllers/Database/StructureController.php:896:42: PossiblyNullOperand: Cannot concatenate with a possibly null false|null|string (see https://psalm.dev/080)

Check failure on line 896 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

PossiblyFalseOperand

src/Controllers/Database/StructureController.php:896:42: PossiblyFalseOperand: Cannot concatenate with a possibly false false|null|string (see https://psalm.dev/162)
UNHEX(\'0A\'), \'nn\'), UNHEX(\'22\'), \'nn\'), UNHEX(\'5C\'), \'nn\'
))) FROM ' . Util::backquote(Current::$database) . '.' . Util::backquote($currentTable['TABLE_NAME']));

Check failure on line 898 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

MixedArgument

src/Controllers/Database/StructureController.php:898:90: MixedArgument: Argument 1 of PhpMyAdmin\Util::backquote cannot be mixed, expecting Stringable|null|string (see https://psalm.dev/030)

Check failure on line 898 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

Parameter #1 $identifier of static method PhpMyAdmin\Util::backquote() expects string|Stringable|null, mixed given.

// Calculate quotes length
$quotesLength = $currentTable['TABLE_ROWS'] * $columnCount * 2;

Check failure on line 901 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

MixedAssignment

src/Controllers/Database/StructureController.php:901:13: MixedAssignment: Unable to determine the type that $quotesLength is being assigned to (see https://psalm.dev/032)

Check failure on line 901 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

MixedOperand

src/Controllers/Database/StructureController.php:901:29: MixedOperand: Left operand cannot be mixed (see https://psalm.dev/059)

Check failure on line 901 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

Binary operation "*" between mixed and int results in an error.

/** @var int $tblsize */
$tblsize = $dataLength + $quotesLength + $currentTable['TABLE_ROWS'];

Check failure on line 904 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

MixedOperand

src/Controllers/Database/StructureController.php:904:24: MixedOperand: Left operand cannot be mixed (see https://psalm.dev/059)

Check failure on line 904 in src/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

Binary operation "+" between (float|int) and mixed results in an error.

$sumSize += $tblsize;
[$formattedSize, $unit] = Util::formatByteDown($tblsize, 3, $tblsize > 0 ? 1 : 0);
}

return [$currentTable, $formattedSize, $unit, $sumSize];
}

/**
* Get values for Mroonga table
*
Expand Down

0 comments on commit 500d4db

Please sign in to comment.