📄 relation.lib.php
字号:
$i = 0; while ($relrow = PMA_DBI_fetch_assoc($relations)) { $field = $relrow['master_field']; $foreign[$field]['foreign_db'] = $relrow['foreign_db']; $foreign[$field]['foreign_table'] = $relrow['foreign_table']; $foreign[$field]['foreign_field'] = $relrow['foreign_field']; $i++; } // end while PMA_DBI_free_result($relations); unset($relations); } if (($source == 'both' || $source == 'innodb') && isset($table) && strlen($table)) { $show_create_table_query = 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table); $show_create_table_res = PMA_DBI_query($show_create_table_query); list(, $show_create_table) = PMA_DBI_fetch_row($show_create_table_res); PMA_DBI_free_result($show_create_table_res); unset($show_create_table_res, $show_create_table_query); $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); foreach ($analyzed_sql[0]['foreign_keys'] AS $one_key) { // the analyzer may return more than one column name in the // index list or the ref_index_list foreach ($one_key['index_list'] AS $i => $field) { // If a foreign key is defined in the 'internal' source (pmadb) // and in 'innodb', we won't get it twice if $source='both' // because we use $field as key // The parser looks for a CONSTRAINT clause just before // the FOREIGN KEY clause. It finds it (as output from // SHOW CREATE TABLE) in MySQL 4.0.13, but not in older // versions like 3.23.58. // In those cases, the FOREIGN KEY parsing will put numbers // like -1, 0, 1... instead of the constraint number. if (isset($one_key['constraint'])) { $foreign[$field]['constraint'] = $one_key['constraint']; } if (isset($one_key['ref_db_name'])) { $foreign[$field]['foreign_db'] = $one_key['ref_db_name']; } else { $foreign[$field]['foreign_db'] = $db; } $foreign[$field]['foreign_table'] = $one_key['ref_table_name']; $foreign[$field]['foreign_field'] = $one_key['ref_index_list'][$i]; if (isset($one_key['on_delete'])) { $foreign[$field]['on_delete'] = $one_key['on_delete']; } if (isset($one_key['on_update'])) { $foreign[$field]['on_update'] = $one_key['on_update']; } } } } /** * Emulating relations for some information_schema tables */ if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema' && ($source == 'internal' || $source == 'both')) { require_once './libraries/information_schema_relations.lib.php'; if (!isset($foreign)) { $foreign = array(); } if (isset($GLOBALS['information_schema_relations'][$table])) { foreach ($GLOBALS['information_schema_relations'][$table] as $field => $relations) { if ((! isset($column) || ! strlen($column) || $column == $field) && (! isset($foreign[$field]) || ! strlen($foreign[$field]))) { $foreign[$field] = $relations; } } } } if (!empty($foreign) && is_array($foreign)) { return $foreign; } else { return false; }} // end of the 'PMA_getForeigners()' function/** * Gets the display field of a table * * @param string the name of the db to check for * @param string the name of the table to check for * * @return string field name * * @global array the list of relations settings * * @access public * * @author Mike Beck <mikebeck@users.sourceforge.net> */function PMA_getDisplayField($db, $table) { global $cfgRelation; /** * Try to fetch the display field from DB. */ if (trim(@$cfgRelation['table_info']) != '') { $disp_query = ' SELECT display_field FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['table_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; $disp_res = PMA_query_as_cu($disp_query); $row = ($disp_res ? PMA_DBI_fetch_assoc($disp_res) : ''); PMA_DBI_free_result($disp_res); if (isset($row['display_field'])) { return $row['display_field']; } } /** * Emulating the display field for some information_schema tables. */ if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') { switch ($table) { case 'CHARACTER_SETS': return 'DESCRIPTION'; case 'TABLES': return 'TABLE_COMMENT'; } } /** * No Luck... */ return false;} // end of the 'PMA_getDisplayField()' function/** * Gets the comments for all rows of a table * * @param string the name of the db to check for * @param string the name of the table to check for * * @return array [field_name] = comment * * @global array the list of relations settings * * @access public * * @authors Mike Beck <mikebeck@users.sourceforge.net> * and lem9 */function PMA_getComments($db, $table = '') { global $cfgRelation; if ($table != '') { // MySQL 4.1.x native column comments if (PMA_MYSQL_INT_VERSION >= 40100) { $fields = PMA_DBI_get_fields($db, $table); if ($fields) { foreach ($fields as $key=>$field) { $tmp_col = $field['Field']; if (!empty($field['Comment'])) { $native_comment[$tmp_col] = $field['Comment']; } } if (isset($native_comment)) { $comment = $native_comment; } } } // pmadb internal column comments // (this function can be called even if $cfgRelation['commwork'] is // false, to get native column comments, so recheck here) if ($cfgRelation['commwork']) { $com_qry = ' SELECT column_name, comment FROM ' . PMA_backquote($cfgRelation['db']) . '.' .PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\' AND table_name = \'' . PMA_sqlAddslashes($table) . '\''; $com_rs = PMA_query_as_cu($com_qry, true, PMA_DBI_QUERY_STORE); } } else { // pmadb internal db comments $com_qry = ' SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\' AND table_name = \'\' AND column_name = \'(db_comment)\''; $com_rs = PMA_query_as_cu($com_qry, true, PMA_DBI_QUERY_STORE); } if (isset($com_rs) && PMA_DBI_num_rows($com_rs) > 0) { $i = 0; while ($row = PMA_DBI_fetch_assoc($com_rs)) { $i++; $col = ($table != '' ? $row['column_name'] : $i); if (strlen($row['comment']) > 0) { $comment[$col] = $row['comment']; // if this version supports native comments and this function // was called with a table parameter if (PMA_MYSQL_INT_VERSION >= 40100 && isset($table) && strlen($table)) { // if native comment found, use it instead of pmadb if (!empty($native_comment[$col])) { $comment[$col] = $native_comment[$col]; } else { // no native comment, so migrate pmadb-style to native PMA_setComment($db, $table, $col, $comment[$col], '', 'native'); // and erase the pmadb-style comment PMA_setComment($db, $table, $col, '', '', 'pmadb'); } } } } // end while PMA_DBI_free_result($com_rs); unset($com_rs); } if (isset($comment) && is_array($comment)) { return $comment; } else { return false; } } // end of the 'PMA_getComments()' function/** * Adds/removes slashes if required * * @param string the string to slash * * @return string the slashed string * * @access public */function PMA_handleSlashes($val) { return PMA_sqlAddslashes($val);} // end of the "PMA_handleSlashes()" function/** * Set a single comment to a certain value. * * @param string the name of the db * @param string the name of the table (may be empty in case of a db comment) * @param string the name of the column * @param string the value of the column * @param string (optional) if a column is renamed, this is the name of the former key which will get deleted * @param string whether we set pmadb comments, native comments or both * * @return boolean true, if comment-query was made. * * @global array the list of relations settings * * @access public */function PMA_setComment($db, $table, $col, $comment, $removekey = '', $mode='auto') { global $cfgRelation; if ($mode=='auto') { if (PMA_MYSQL_INT_VERSION >= 40100) { $mode='native'; } else { $mode='pmadb'; } } // native mode is only for column comments so we need a table name if ($mode == 'native' && isset($table) && strlen($table)) { $query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHANGE ' . PMA_Table::generateAlter($col, $col, '', '', '', '', false, '', false, '', $comment, '', ''); PMA_DBI_try_query($query, null, PMA_DBI_QUERY_STORE); return true; } // $mode == 'pmadb' section: $cols = array( 'db_name' => 'db_name ', 'table_name' => 'table_name ', 'column_name' => 'column_name' ); if ($removekey != '' AND $removekey != $col) { $remove_query = ' DELETE FROM ' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . ' WHERE ' . $cols['db_name'] . ' = \'' . PMA_sqlAddslashes($db) . '\' AND ' . $cols['table_name'] . ' = \'' . PMA_sqlAddslashes($table) . '\' AND ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($removekey) . '\''; PMA_query_as_cu($remove_query); unset($remove_query);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -