/** * Creates and returns SQL command for dropping the sequence. * * @return string */ public static function get_drop_sql($node_schema, $node_sequences) { $table_name = mysql5::get_quoted_table_name(self::TABLE_NAME); $seq_col = mysql5::get_quoted_column_name(self::SEQ_COL); $sequences = dbx::to_array($node_sequences); if (count($sequences) === 0) { return ''; } $sequence_names = "('" . implode("', '", array_map(function ($n) { if ($n instanceof SimpleXMLElement) { return $n['name']; } return $n; }, $sequences)) . "')"; return "DELETE FROM {$table_name} WHERE {$seq_col} IN {$sequence_names};"; }
private static function diff_single($ofs, $old_seq, $new_seq) { $sql = array(); if (!dbsteward::$ignore_oldnames && !empty($new_seq['oldSequenceName'])) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::SEQ_COL) . " = '{$new_seq['name']}'"; } if ($new_seq['inc'] == null && $old_seq['inc'] != null) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::INC_COL) . ' = DEFAULT'; } if ($new_seq['inc'] != null && strcasecmp($new_seq['inc'], $old_seq['inc']) != 0) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::INC_COL) . ' = ' . $new_seq['inc']; } if ($new_seq['min'] == null && $old_seq['min'] != null) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::MIN_COL) . ' = DEFAULT'; } elseif ($new_seq['min'] != null && strcasecmp($new_seq['min'], $old_seq['min']) != 0) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::MIN_COL) . ' = ' . $new_seq['min']; } if ($new_seq['max'] == null && $old_seq['max'] != null) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::MAX_COL) . ' = DEFAULT'; } elseif ($new_seq['max'] != null && strcasecmp($new_seq['max'], $old_seq['max']) != 0) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::MAX_COL) . ' = ' . $new_seq['max']; } if ($new_seq['start'] != null && strcasecmp($new_seq['start'], $old_seq['start']) != 0) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::CUR_COL) . ' = ' . $new_seq['start']; } if ($new_seq['cycle'] == null && $old_seq['cycle'] != null) { $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::CYC_COL) . ' = DEFAULT'; } elseif ($new_seq['cycle'] != null && strcasecmp($new_seq['cycle'], $old_seq['cycle']) != 0) { $value = strcasecmp($new_seq['cycle'], 'false') == 0 ? 'FALSE' : 'TRUE'; $sql[] = mysql5::get_quoted_column_name(mysql5_sequence::CYC_COL) . ' = ' . $value; } if (!empty($sql)) { $out = "UPDATE " . mysql5::get_quoted_table_name(mysql5_sequence::TABLE_NAME); $out .= "\nSET " . implode(",\n ", $sql); $out .= "\nWHERE " . mysql5::get_quoted_column_name(mysql5_sequence::SEQ_COL) . " = "; $out .= "'" . $old_seq['name'] . "'"; $ofs->write("{$out};\n"); } }