<a href="tbl_printview.php?<?php echo $url_query; ?> "><?php if ($cfg['PropertiesIconic']) { echo '<img class="icon" src="' . $pmaThemeImage . 'b_print.png" width="16" height="16" alt="' . $strPrintView . '"/>'; } echo $strPrintView; ?> </a> <?php if (!$tbl_is_view && !$db_is_information_schema) { // if internal relations are available, or foreign keys are supported // ($tbl_type comes from libraries/tbl_info.inc.php) if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_type)) { ?> <a href="tbl_relation.php?<?php echo $url_query; ?> "><?php if ($cfg['PropertiesIconic']) { echo '<img class="icon" src="' . $pmaThemeImage . 'b_relations.png" width="16" height="16" alt="' . $strRelationView . '"/>'; } echo $strRelationView; ?> </a> <?php } ?> <a href="sql.php?<?php
<tr id="id_tr_<?php echo $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . '.' . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]); ?> " <?php if ($display_field == $tab_column[$t_n]["COLUMN_NAME"][$j]) { echo ' class="tab_field_3" '; } else { echo ' class="tab_field" '; } ?> onmouseover="old_class = this.className; this.className = 'tab_field_2';" onmouseout="this.className = old_class;" onmousedown="Click_field('<?php echo $GLOBALS['PMD_URL']["TABLE_NAME_SMALL"][$i] . "','" . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]) . "',"; if (!PMA_foreignkey_supported($GLOBALS['PMD']['TABLE_TYPE'][$i])) { echo isset($tables_pk_or_unique_keys[$t_n . "." . $tab_column[$t_n]["COLUMN_NAME"][$j]]) ? 1 : 0; } else { // if foreign keys are supported, it's not necessary that the // index is a primary key echo isset($tables_all_keys[$t_n . "." . $tab_column[$t_n]["COLUMN_NAME"][$j]]) ? 1 : 0; } ?> )"> <td width="10px" colspan="3" id="<?php echo $t_n_url . "." . urlencode($tab_column[$t_n]["COLUMN_NAME"][$j]); ?> "> <div style="white-space:nowrap"> <?php
/** * * * @uses $GLOBALS['PMD'] * @uses count() * @uses in_array() * @return array ??? */ function get_script_tabs() { $script_tabs = '<script type="text/javascript">' . "\n" . '// <![CDATA[' . "\n" . 'var j_tabs = new Array();' . "\n"; for ($i = 0, $cnt = count($GLOBALS['PMD']['TABLE_NAME']); $i < $cnt; $i++) { $script_tabs .= "j_tabs['" . $GLOBALS['PMD_URL']['TABLE_NAME'][$i] . "'] = '" . (PMA_foreignkey_supported($GLOBALS['PMD']['TABLE_TYPE'][$i]) ? '1' : '0') . "';\n"; } $script_tabs .= '// ]]>' . "\n" . '</script>' . "\n"; return $script_tabs; }
echo '>' . htmlspecialchars($value) . '</option>' . "\n"; } // end while // if the link defined in relationtable points to a foreign field // that is not a key in the foreign table, we show the link // (will not be shown with an arrow) if ($foreign_field && !$seen_key) { echo ' ' . '<option value="' . htmlspecialchars($foreign_field) . '"' . ' selected="selected"' . '>' . $foreign_field . '</option>' . "\n"; } ?> </select> </td> <?php } // end if (internal relations) if (PMA_foreignkey_supported($tbl_type)) { echo '<td>'; if (!empty($save_row[$i]['Key'])) { ?> <span class="formelement"> <select name="destination_foreign[<?php echo $myfield_md5; ?> ]"> <?php if (isset($existrel_foreign[$myfield])) { // need to backquote to support a dot character inside // an element $foreign_field = PMA_backquote($existrel_foreign[$myfield]['foreign_db']) . '.' . PMA_backquote($existrel_foreign[$myfield]['foreign_table']) . '.' . PMA_backquote($existrel_foreign[$myfield]['foreign_field']); } else { $foreign_field = FALSE;
/** * process internal and foreign key relations * * @param string $db The database name * @param integer $pageNumber document number/Id * @param array $cfgRelation relation settings * * @return void * @access private */ public function processRelations($db, $pageNumber, $cfgRelation) { /* * A u t o m a t i c l a y o u t * * There are 2 kinds of relations in PMA * 1) Internal Relations 2) Foreign Key Relations */ if (isset($this->autoLayoutInternal) || isset($this->autoLayoutForeign)) { $all_tables = array(); } if (isset($this->autoLayoutForeign)) { /* * get the tables list * who support FOREIGN KEY, it's not * important that we group together InnoDB tables * and PBXT tables, as this logic is just to put * the tables on the layout, not to determine relations */ $tables = PMA_DBI_get_tables_full($db); $foreignkey_tables = array(); foreach ($tables as $table_name => $table_properties) { if (PMA_foreignkey_supported($table_properties['ENGINE'])) { $foreignkey_tables[] = $table_name; } } $all_tables = $foreignkey_tables; /* * could be improved by finding the tables which have the * most references keys and placing them at the beginning * of the array (so that they are all center of schema) */ unset($tables, $foreignkey_tables); } if (isset($this->autoLayoutInternal)) { /* * get the tables list who support Internal Relations; * This type of relations will be created when * you setup the PMA tables correctly */ $master_tables = 'SELECT COUNT(master_table), master_table' . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' WHERE master_db = \'' . PMA_sqlAddSlashes($db) . '\'' . ' GROUP BY master_table' . ' ORDER BY COUNT(master_table) DESC'; $master_tables_rs = PMA_query_as_controluser($master_tables, false, PMA_DBI_QUERY_STORE); if ($master_tables_rs && PMA_DBI_num_rows($master_tables_rs) > 0) { /* first put all the master tables at beginning * of the list, so they are near the center of * the schema */ while (list(, $master_table) = PMA_DBI_fetch_row($master_tables_rs)) { $all_tables[] = $master_table; } /* Now for each master, add its foreigns into an array * of foreign tables, if not already there * (a foreign might be foreign for more than * one table, and might be a master itself) */ $foreign_tables = array(); foreach ($all_tables as $master_table) { $foreigners = PMA_getForeigners($db, $master_table); foreach ($foreigners as $foreigner) { if (!in_array($foreigner['foreign_table'], $foreign_tables)) { $foreign_tables[] = $foreigner['foreign_table']; } } } /* * Now merge the master and foreign arrays/tables */ foreach ($foreign_tables as $foreign_table) { if (!in_array($foreign_table, $all_tables)) { $all_tables[] = $foreign_table; } } } } if (isset($this->autoLayoutInternal) || isset($this->autoLayoutForeign)) { $this->addRelationCoordinates($all_tables, $pageNumber, $db, $cfgRelation); } $this->chosenPage = $pageNumber; }
/** * */ include_once 'pmd_common.php'; require_once './libraries/relation.lib.php'; extract($_POST, EXTR_SKIP); extract($_GET, EXTR_SKIP); $die_save_pos = 0; include_once 'pmd_save_pos.php'; list($DB1, $T1) = explode(".", $T1); list($DB2, $T2) = explode(".", $T2); $tables = PMA_DBI_get_tables_full($db, $T1); $type_T1 = strtoupper($tables[$T1]['ENGINE']); $tables = PMA_DBI_get_tables_full($db, $T2); $type_T2 = strtoupper($tables[$T2]['ENGINE']); if (PMA_foreignkey_supported($type_T1) && PMA_foreignkey_supported($type_T2) && $type_T1 == $type_T2) { // InnoDB $existrel_foreign = PMA_getForeigners($DB2, $T2, '', 'foreign'); if (isset($existrel_foreign[$F2]['constraint'])) { $upd_query = 'ALTER TABLE ' . PMA_backquote($T2) . ' DROP FOREIGN KEY ' . PMA_backquote($existrel_foreign[$F2]['constraint']); $upd_rs = PMA_DBI_query($upd_query); } } else { // internal relations PMA_query_as_cu('DELETE FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . $cfg['Server']['relation'] . ' WHERE ' . 'master_db = \'' . PMA_sqlAddslashes($DB2) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($T2) . '\'' . ' AND master_field = \'' . PMA_sqlAddslashes($F2) . '\'' . ' AND foreign_db = \'' . PMA_sqlAddslashes($DB1) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($T1) . '\'' . ' AND foreign_field = \'' . PMA_sqlAddslashes($F1) . '\'', FALSE, PMA_DBI_QUERY_STORE); } PMD_return_upd(1, 'strRelationDeleted'); function PMD_return_upd($b, $ret) { global $K; header("Content-Type: text/xml; charset=utf-8");
/** * foreign key supported test * @dataProvider foreignkeySupportedDataProvider */ public function testForeignkeySupported($a, $e) { $this->assertEquals($e, PMA_foreignkey_supported($a)); }
$pdf_page_number = PMA_REL_create_page($newpage, $cfgRelation, $db, $query_default_option); // A u t o m a t i c l a y o u t // ================================ if (isset($auto_layout_internal) || isset($auto_layout_foreign)) { $all_tables = array(); } if (isset($auto_layout_foreign)) { // get the tables list $tables = PMA_DBI_get_tables_full($db); // find the ones who support FOREIGN KEY; it's not // important that we group together InnoDB tables // and PBXT tables, as this logic is just to put // the tables on the layout, not to determine relations $foreignkey_tables = array(); foreach ($tables as $table_name => $table_properties) { if (PMA_foreignkey_supported($table_properties['ENGINE'])) { $foreignkey_tables[] = $table_name; } } $all_tables = $foreignkey_tables; // could be improved by finding the tables which have the // most references keys and placing them at the beginning // of the array (so that they are all center of schema) unset($tables, $foreignkey_tables); } // endif auto_layout_foreign if (isset($auto_layout_internal)) { // get the tables that have relations, by descending // number of links $master_tables = 'SELECT COUNT(master_table), master_table' . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . ' WHERE master_db = \'' . $db . '\'' . ' GROUP BY master_table' . ' ORDER BY ' . PMA_backquote('COUNT(master_table)') . ' DESC '; $master_tables_rs = PMA_query_as_controluser($master_tables, FALSE, $query_default_option);
// if the link defined in relationtable points to a foreign field // that is not a key in the foreign table, we show the link // (will not be shown with an arrow) if ($foreign_field && !$seen_key) { echo ' ' .'<option value="' . htmlspecialchars($foreign_field) . '"' .' selected="selected"' .'>' . $foreign_field . '</option>'. "\n"; } ?> </select> </td> <?php } // end if (internal relations) if (PMA_foreignkey_supported($tbl_storage_engine)) { echo '<td>'; if (!empty($save_row[$i]['Key'])) { ?> <span class="formelement"> <select name="destination_foreign[<?php echo $myfield_md5; ?>]" class="referenced_column_dropdown"> <?php if (isset($existrel_foreign[$myfield])) { // need to backquote to support a dot character inside // an element $foreign_field = PMA_backquote($existrel_foreign[$myfield]['foreign_db']) . '.' . PMA_backquote($existrel_foreign[$myfield]['foreign_table']) . '.' . PMA_backquote($existrel_foreign[$myfield]['foreign_field']); } else { $foreign_field = false; }
), PMA_getIcon('b_edit.png', __('Edit view'), true) ); } ?> <a href="tbl_printview.php?<?php echo $url_query; ?>"><?php echo PMA_getIcon('b_print.png', __('Print view'), true); ?></a> <?php if (! $tbl_is_view && ! $db_is_information_schema) { // if internal relations are available, or foreign keys are supported // ($tbl_storage_engine comes from libraries/tbl_info.inc.php) if ($cfgRelation['relwork'] || PMA_foreignkey_supported($tbl_storage_engine)) { ?> <a href="tbl_relation.php?<?php echo $url_query; ?>"><?php echo PMA_getIcon('b_relations.png', __('Relation view'), true); ?></a> <?php } if (!PMA_DRIZZLE) { ?> <a href="sql.php?<?php echo $url_query; ?>&session_max_rows=all&sql_query=<?php echo urlencode('SELECT * FROM ' . PMA_backquote($table) . ' PROCEDURE ANALYSE()'); ?>"><?php echo PMA_getIcon('b_tblanalyse.png', __('Propose table structure'), true); ?></a><?php echo PMA_showMySQLDocu('Extending_MySQL', 'procedure_analyse') . "\n"; }