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 9fa7c7c commit ce04461
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions libraries/classes/Controllers/Database/StructureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ protected 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 @@ -883,6 +889,75 @@ protected function getValuesForInnodbTable(
];
}

/**
* Get values for CSV table
*
* https://bugs.mysql.com/bug.php?id=53929
*
* @param array $currentTable current table
* @param int $sumSize sum size
*
* @return array
*/
protected function getValuesForCsvTable(

Check failure on line 902 in libraries/classes/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (7.2)

Method PhpMyAdmin\Controllers\Database\StructureController::getValuesForCsvTable() has parameter $currentTable with no value type specified in iterable type array.

Check failure on line 902 in libraries/classes/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (7.2)

Method PhpMyAdmin\Controllers\Database\StructureController::getValuesForCsvTable() return type has no value type specified in iterable type array.
array $currentTable,
$sumSize
) {
$formattedSize = $unit = '';

if (
(in_array($currentTable['ENGINE'], ['CSV'], true)
&& $currentTable['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount'])

Check failure on line 910 in libraries/classes/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (7.2)

Cannot access offset 'MaxExactCount' on mixed.
|| ! isset($currentTable['TABLE_ROWS'])
) {
$currentTable['COUNTED'] = true;
$currentTable['TABLE_ROWS'] = $this->dbi
->getTable($this->db, $currentTable['TABLE_NAME'])

Check failure on line 915 in libraries/classes/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (7.2)

Parameter #2 $table_name of method PhpMyAdmin\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->escapeString($this->db) . '\' AND TABLE_NAME = \''
. $this->dbi->escapeString($currentTable['TABLE_NAME']) . '\' AND NUMERIC_SCALE IS NULL;'

Check failure on line 926 in libraries/classes/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (7.2)

Parameter #1 $str of method PhpMyAdmin\DatabaseInterface::escapeString() 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->escapeString($this->db) . '\' AND TABLE_NAME = \''
. $this->dbi->escapeString($currentTable['TABLE_NAME']) . '\';'

Check failure on line 933 in libraries/classes/Controllers/Database/StructureController.php

View workflow job for this annotation

GitHub Actions / analyse-php (7.2)

Parameter #1 $str of method PhpMyAdmin\DatabaseInterface::escapeString() 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 . '),
UNHEX(\'0A\'), \'nn\'), UNHEX(\'22\'), \'nn\'), UNHEX(\'5C\'), \'nn\'
))) FROM ' . Util::backquote($this->db) . '.' . Util::backquote($currentTable['TABLE_NAME'])
);

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

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

$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 ce04461

Please sign in to comment.