innodb and PMA_getForeigners
This commit is contained in:
@@ -8,6 +8,9 @@ $Source$
|
|||||||
2003-06-19 Marc Delisle <lem9@users.sourceforge.net>
|
2003-06-19 Marc Delisle <lem9@users.sourceforge.net>
|
||||||
* libraries/sqlparser.lib.php3: analyzer for FOREIGN KEYS
|
* libraries/sqlparser.lib.php3: analyzer for FOREIGN KEYS
|
||||||
* libraries/sqlparser.lib.php3: bug 756861, DEFAULT 0 becomes DEFAULT0
|
* libraries/sqlparser.lib.php3: bug 756861, DEFAULT 0 becomes DEFAULT0
|
||||||
|
* libraries/display_tbl.lib.php3: use PMA_getForeigners()
|
||||||
|
* libraries/relation.lib.php3: now PMA_getForeigners() gets also
|
||||||
|
foreign keys defined in innnodb
|
||||||
|
|
||||||
2003-06-17 Michal Cihar <nijel@users.sourceforge.net>
|
2003-06-17 Michal Cihar <nijel@users.sourceforge.net>
|
||||||
* config.inc.php3: Fixed typo (s/'PMA_pdf_page'/'PMA_pdf_pages'/).
|
* config.inc.php3: Fixed typo (s/'PMA_pdf_page'/'PMA_pdf_pages'/).
|
||||||
|
@@ -1615,34 +1615,28 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
|
|||||||
// init map
|
// init map
|
||||||
$map = array();
|
$map = array();
|
||||||
|
|
||||||
if ($cfgRelation['relwork']) {
|
// find tables
|
||||||
// find tables
|
|
||||||
//$pattern = '`?[[:space:]]+(((ON|on)[[:space:]]+[^,]+)?,|((NATURAL|natural)[[:space:]]+)?(INNER|inner|LEFT|left|RIGHT|right)([[:space:]]+(OUTER|outer))?[[:space:]]+(JOIN|join))[[:space:]]*`?';
|
|
||||||
//$target = eregi_replace('^.*[[:space:]]+FROM[[:space:]]+`?|`?[[:space:]]*(ON[[:space:]]+[^,]+)?(WHERE[[:space:]]+.*)?$', '', $sql_query);
|
|
||||||
//$target = eregi_replace('`?[[:space:]]ORDER BY[[:space:]](.*)','',$target);
|
|
||||||
//$tabs = '(\'' . join('\',\'', split($pattern, $target)) . '\')';
|
|
||||||
$target=array();
|
|
||||||
reset($analyzed_sql[0]['table_ref']);
|
|
||||||
while (list ($table_ref_position, $table_ref) = each ($analyzed_sql[0]['table_ref'])) {
|
|
||||||
$target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
|
|
||||||
}
|
|
||||||
$tabs = '(\'' . join('\',\'', $target) . '\')';
|
|
||||||
|
|
||||||
$local_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
|
$target=array();
|
||||||
. ' FROM ' . PMA_backquote($cfgRelation['relation'])
|
reset($analyzed_sql[0]['table_ref']);
|
||||||
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\''
|
while (list ($table_ref_position, $table_ref) = each ($analyzed_sql[0]['table_ref'])) {
|
||||||
. ' AND master_table IN ' . $tabs;
|
$target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
|
||||||
$result = @PMA_query_as_cu($local_query, FALSE);
|
}
|
||||||
if ($result) {
|
$tabs = '(\'' . join('\',\'', $target) . '\')';
|
||||||
while ($rel = PMA_mysql_fetch_row($result)) {
|
|
||||||
// check for display field?
|
if ($cfgRelation['displaywork']) {
|
||||||
if ($cfgRelation['displaywork']) {
|
$exist_rel = PMA_getForeigners($db, $table, '', 'both');
|
||||||
$display_field = PMA_getDisplayField($rel[1], $rel[2]);
|
if ($exist_rel) {
|
||||||
$map[$rel[0]] = array($rel[2], $rel[3], $display_field, $rel[1]);
|
while (list($master_field,$rel) = each($exist_rel)) {
|
||||||
} // end if
|
$display_field = PMA_getDisplayField($rel['foreign_db'],$rel['foreign_table']);
|
||||||
|
$map[$master_field] = array($rel['foreign_table'],
|
||||||
|
$rel['foreign_field'],
|
||||||
|
$display_field,
|
||||||
|
$rel['foreign_db']);
|
||||||
} // end while
|
} // end while
|
||||||
} // end if
|
} // end if
|
||||||
} // end 2b
|
} // end if
|
||||||
|
// end 2b
|
||||||
|
|
||||||
// 3. ----- Displays the results table -----
|
// 3. ----- Displays the results table -----
|
||||||
echo '<!-- Results table -->' . "\n"
|
echo '<!-- Results table -->' . "\n"
|
||||||
|
@@ -272,6 +272,7 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){
|
|||||||
* @param string the name of the db to check for
|
* @param string the name of the db to check for
|
||||||
* @param string the name of the table to check for
|
* @param string the name of the table to check for
|
||||||
* @param string the name of the column to check for
|
* @param string the name of the column to check for
|
||||||
|
* @param string the source for foreign key information
|
||||||
*
|
*
|
||||||
* @return array db,table,column
|
* @return array db,table,column
|
||||||
*
|
*
|
||||||
@@ -280,33 +281,61 @@ if (!defined('PMA_RELATION_LIB_INCLUDED')){
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*
|
*
|
||||||
* @author Mike Beck <mikebeck@users.sourceforge.net>
|
* @author Mike Beck <mikebeck@users.sourceforge.net> and Marc Delisle
|
||||||
*/
|
*/
|
||||||
function PMA_getForeigners($db, $table, $column = '') {
|
function PMA_getForeigners($db, $table, $column = '', $source = 'both') {
|
||||||
global $cfgRelation, $err_url_0;
|
global $cfgRelation, $err_url_0;
|
||||||
|
|
||||||
$rel_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
|
if ($source == 'both' || $source == 'internal') {
|
||||||
. ' FROM ' . PMA_backquote($cfgRelation['relation'])
|
$rel_query = 'SELECT master_field, foreign_db, foreign_table, foreign_field'
|
||||||
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
|
. ' FROM ' . PMA_backquote($cfgRelation['relation'])
|
||||||
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\' ';
|
. ' WHERE master_db = \'' . PMA_sqlAddslashes($db) . '\' '
|
||||||
if (!empty($column)) {
|
. ' AND master_table = \'' . PMA_sqlAddslashes($table) . '\' ';
|
||||||
$rel_query .= ' AND master_field = \'' . PMA_sqlAddslashes($column) . '\'';
|
if (!empty($column)) {
|
||||||
|
$rel_query .= ' AND master_field = \'' . PMA_sqlAddslashes($column) . '\'';
|
||||||
|
}
|
||||||
|
$relations = PMA_query_as_cu($rel_query);
|
||||||
|
$i = 0;
|
||||||
|
while ($relrow = @PMA_mysql_fetch_array($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
|
||||||
}
|
}
|
||||||
$relations = PMA_query_as_cu($rel_query);
|
|
||||||
$i = 0;
|
|
||||||
while ($relrow = @PMA_mysql_fetch_array($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
|
|
||||||
|
|
||||||
if (isset($foreign) && is_array($foreign)) {
|
if ($source == 'both' || $source == 'innodb') {
|
||||||
return $foreign;
|
$show_create_table_query = 'SHOW CREATE TABLE '
|
||||||
} else {
|
. PMA_backquote($db) . '.' . PMA_backquote($table);
|
||||||
return FALSE;
|
$show_create_table_res = PMA_mysql_query($show_create_table_query);
|
||||||
}
|
list(,$show_create_table) = PMA_mysql_fetch_row($show_create_table_res);
|
||||||
|
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
|
||||||
|
|
||||||
|
while (list(,$one_key) = each ($analyzed_sql[0]['foreign_keys'])) {
|
||||||
|
|
||||||
|
// TODO: the analyzer may return more than one column name in the
|
||||||
|
// index list or the ref_index_list but for now we take the first
|
||||||
|
$field = $one_key['index_list'][0];
|
||||||
|
|
||||||
|
// TODO: SHOW CREATE TABLE does not return the db name in
|
||||||
|
// the REFERENCES, so we assume the same db as master
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
$foreign[$field]['foreign_db'] = $db;
|
||||||
|
$foreign[$field]['foreign_table'] = $one_key['ref_table_name'];
|
||||||
|
$foreign[$field]['foreign_field'] = $one_key['ref_index_list'][0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($foreign) && is_array($foreign)) {
|
||||||
|
return $foreign;
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
} // end of the 'PMA_getForeigners()' function
|
} // end of the 'PMA_getForeigners()' function
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user