/** * Test for PMA_getAllCombinationPartialKeys * * @return void */ public function testPMAGetAllCombinationPartialKeys() { $primaryKey = array('id', 'col1', 'col2'); $result = PMA_getAllCombinationPartialKeys($primaryKey); $this->assertEquals(array('', 'id', 'col1', 'col1,id', 'col2', 'col2,id', 'col2,col1'), $result); }
/** * find all the possible partial dependencies based on data in the table. * * @param string $table current table * @param string $db current database * * @return string HTML containing the list of all the possible partial dependencies */ function PMA_findPartialDependencies($table, $db) { $dependencyList = array(); $GLOBALS['dbi']->selectDb($db, $GLOBALS['userlink']); $columns = (array) $GLOBALS['dbi']->getColumnNames($db, $table, $GLOBALS['userlink']); $columns = (array) Util::backquote($columns); $totalRowsRes = $GLOBALS['dbi']->fetchResult('SELECT COUNT(*) FROM (SELECT * FROM ' . Util::backquote($table) . ' LIMIT 500) as dt;'); $totalRows = $totalRowsRes[0]; $primary = PMA\libraries\Index::getPrimary($table, $db); $primarycols = $primary->getColumns(); $pk = array(); foreach ($primarycols as $col) { $pk[] = Util::backquote($col->getName()); } $partialKeys = PMA_getAllCombinationPartialKeys($pk); $distinctValCount = PMA_findDistinctValuesCount(array_unique(array_merge($columns, $partialKeys)), $table); foreach ($columns as $column) { if (!in_array($column, $pk)) { foreach ($partialKeys as $partialKey) { if ($partialKey && PMA_checkPartialDependency($partialKey, $column, $table, $distinctValCount[$partialKey], $distinctValCount[$column], $totalRows)) { $dependencyList[$partialKey][] = $column; } } } } $html = __('This list is based on a subset of the table\'s data ' . 'and is not necessarily accurate. ') . '<div class="dependencies_box">'; foreach ($dependencyList as $dependon => $colList) { $html .= '<span class="displayblock">' . '<input type="button" class="pickPd" value="' . __('Pick') . '"/>' . '<span class="determinants">' . htmlspecialchars(str_replace('`', '', $dependon)) . '</span> -> ' . '<span class="dependents">' . htmlspecialchars(str_replace('`', '', implode(', ', $colList))) . '</span>' . '</span>'; } if (empty($dependencyList)) { $html .= '<p class="displayblock desc">' . __('No partial dependencies found!') . '</p>'; } $html .= '</div>'; return $html; }