Ejemplo n.º 1
0
$content->success = true;
$content->env = PostParser::create_attribute($G_APP_ENVIRONMENT);
# What we are doing with the request
$_JPOST->action = isset($_JPOST->action) ? $_JPOST->action : '';
# What to do
switch ($_JPOST->action) {
    # Dropping the table
    case 'drop':
        # Dropping the table
        $query = "\tUPDATE\n\t\t\t\t\t\t" . NQ_TABLE_SETTINGS_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`name`\t\t\t= CONCAT('!trash:',`id`,':',`name`),\n\t\t\t\t\t\t`alias`\t\t\t= CONCAT(NOW(),`alias`),\n\t\t\t\t\t\t`environment`\t= 'trash',\n\t\t\t\t\t\t`modified`\t\t= NOW()\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t\t=" . (int) $G_TABLE_ID . "\n\t\t\t\t\tLIMIT 1";
        mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
        break;
        # Truncating the table (delete and recreate for speed)
    # Truncating the table (delete and recreate for speed)
    case 'truncate':
        $G_TABLE_DETAILS = recreate_table($G_CONTROLLER_DBLINK, $G_TABLE_DETAILS);
        break;
        # Regular request
    # Regular request
    default:
        # Validating our rename
        if (isset($_JPOST->rename) && $_JPOST->rename != '' && $_JPOST->rename != $G_TABLE_DETAILS['name']) {
            # Checking if the table name isn't used
            $query = "\tSELECT\n\t\t\t\t\t\t\t`name`\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t" . NQ_TABLE_SETTINGS_TABLE . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`app_id`\t\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t\t\t\t`name`\t\t\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $_JPOST->rename) . "' AND\n\t\t\t\t\t\t\t`environment`\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $G_TABLE_DETAILS['environment']) . "'\n\t\t\t\t\t\tLIMIT 1";
            $result = mysqli_single_result_query($G_CONTROLLER_DBLINK, $query);
            # If we are renaming with a name already in use
            if (mysqli_num_rows($result) > 0) {
                exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_NEW_TABLENAME);
            }
        }
        # Validating a new alias
Ejemplo n.º 2
0
$TABLE = $_GET["foreign"];
$name = $_GET["name"];
$row = $_POST;
if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) {
    $message = $_POST["drop"] ? lang('Foreign key has been dropped.') : ($name != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.'));
    $location = ME . "table=" . urlencode($TABLE);
    $row["source"] = array_filter($row["source"], 'strlen');
    ksort($row["source"]);
    // enforce input order
    $target = array();
    foreach ($row["source"] as $key => $val) {
        $target[$key] = $row["target"][$key];
    }
    $row["target"] = $target;
    if ($jush == "sqlite") {
        queries_adminer_redirect($location, $message, recreate_table($TABLE, $TABLE, array(), array(), array(" {$name}" => $_POST["drop"] ? "" : " " . format_foreign_key($row))));
    } else {
        $alter = "ALTER TABLE " . table($TABLE);
        $drop = "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name);
        if ($_POST["drop"]) {
            query_adminer_redirect($alter . $drop, $location, $message);
        } else {
            query_adminer_redirect($alter . ($name != "" ? "{$drop}," : "") . "\nADD" . format_foreign_key($row), $location, $message);
            $error = lang('Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.') . "<br>{$error}";
            //! no partitioning
        }
    }
}
page_header(lang('Foreign key'), $error, array("table" => $TABLE), h($TABLE));
if ($_POST) {
    ksort($row["source"]);