Beispiel #1
0
            $upd_query .= ' ON DELETE ' . $on_delete;
        }
        if ($on_update != 'nix') {
            $upd_query .= ' ON UPDATE ' . $on_update;
        }
        PMA_DBI_try_query($upd_query) or PMD_return(0, 'strErrorRelationAdded');
        PMD_return(1, 'strInnoDBRelationAdded');
    }
    //  n o n - I n n o D B
} else {
    if ($GLOBALS['cfgRelation']['relwork'] == false) {
        PMD_return(0, 'strGeneralRelationFeat:strDisabled');
    } else {
        // no need to recheck if the keys are primary or unique at this point,
        // this was checked on the interface part
        $q = 'INSERT INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)' . ' values(' . '\'' . PMA_sqlAddslashes($db) . '\', ' . '\'' . PMA_sqlAddslashes($T2) . '\', ' . '\'' . PMA_sqlAddslashes($F2) . '\', ' . '\'' . PMA_sqlAddslashes($db) . '\', ' . '\'' . PMA_sqlAddslashes($T1) . '\',' . '\'' . PMA_sqlAddslashes($F1) . '\')';
        if (PMA_query_as_cu($q, false, PMA_DBI_QUERY_STORE)) {
            PMD_return(1, 'strInternalRelationAdded');
        } else {
            PMD_return(0, 'strErrorRelationAdded');
        }
    }
}
function PMD_return($b, $ret)
{
    global $db, $T1, $F1, $T2, $F2;
    header("Content-Type: text/xml; charset=utf-8");
    //utf-8 .$_GLOBALS['charset']
    header("Cache-Control: no-cache");
    die('<root act="relation_new" return="' . $ret . '" b="' . $b . '" DB1="' . urlencode($db) . '" T1="' . urlencode($T1) . '" F1="' . urlencode($F1) . '" DB2="' . urlencode($db) . '" T2="' . urlencode($T2) . '" F2="' . urlencode($F2) . '"></root>');
}
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 ($type_T1 == 'INNODB' && $type_T2 == 'INNODB') {
    // InnoDB
    $existrel_innodb = PMA_getForeigners($DB2, $T2, '', 'innodb');
    if (PMA_MYSQL_INT_VERSION >= 40013 && isset($existrel_innodb[$F2]['constraint'])) {
        $upd_query = 'ALTER TABLE ' . PMA_backquote($T2) . ' DROP FOREIGN KEY ' . PMA_backquote($existrel_innodb[$F2]['constraint']);
        $upd_rs = PMA_DBI_query($upd_query);
    }
} else {
    // internal relations
    PMA_query_as_cu('DELETE FROM ' . $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(1, 'strRelationDeleted');
function PMD_return($b, $ret)
{
    global $K;
    header("Content-Type: text/xml; charset=utf-8");
    header("Cache-Control: no-cache");
    die('<root act="relation_upd" return="' . $ret . '" b="' . $b . '" K="' . $K . '"></root>');
}