PostgreSQL: Export DROP SEQUENCE if dropping table

This commit is contained in:
Jakub Vrana 2018-01-22 14:33:21 +01:00
parent eee9a62c8f
commit 993dce398d
5 changed files with 8 additions and 5 deletions

View file

@ -915,9 +915,10 @@ if (!defined("DRIVER")) {
/** Get SQL command to create table
* @param string
* @param bool
* @param string
* @return string
*/
function create_sql($table, $auto_increment) {
function create_sql($table, $auto_increment, $style) {
global $connection;
$return = $connection->result("SHOW CREATE TABLE " . table($table), 1);
if (!$auto_increment) {

View file

@ -617,7 +617,7 @@ AND typelem = 0"
return $return;
}
function create_sql($table, $auto_increment) {
function create_sql($table, $auto_increment, $style) {
global $connection;
$return = '';
$return_parts = array();
@ -647,7 +647,8 @@ AND typelem = 0"
if (preg_match('~nextval\(\'([^\']+)\'\)~', $field['default'], $matches)) {
$sequence_name = $matches[1];
$sq = reset(get_rows("SELECT * FROM $sequence_name"));
$sequences[] = "CREATE SEQUENCE $sequence_name INCREMENT $sq[increment_by] MINVALUE $sq[min_value] MAXVALUE $sq[max_value] START " . ($auto_increment ? $sq['last_value'] : 1) . " CACHE $sq[cache_value];";
$sequences[] = ($style == "DROP+CREATE" ? "DROP SEQUENCE $sequence_name;\n" : "")
. "CREATE SEQUENCE $sequence_name INCREMENT $sq[increment_by] MINVALUE $sq[min_value] MAXVALUE $sq[max_value] START " . ($auto_increment ? $sq['last_value'] : 1) . " CACHE $sq[cache_value];";
}
}

View file

@ -715,7 +715,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
return true;
}
function create_sql($table, $auto_increment) {
function create_sql($table, $auto_increment, $style) {
global $connection;
$return = $connection->result("SELECT sql FROM sqlite_master WHERE type IN ('table', 'view') AND name = " . q($table));
foreach (indexes($table) as $name => $index) {

View file

@ -737,7 +737,7 @@ class Adminer {
}
$create = "CREATE TABLE " . table($table) . " (" . implode(", ", $fields) . ")";
} else {
$create = create_sql($table, $_POST["auto_increment"]);
$create = create_sql($table, $_POST["auto_increment"], $style);
}
set_utf8mb4($create);
if ($style && $create) {

View file

@ -4,6 +4,7 @@ CSP: Allow any styles, images, media and fonts, disallow base-uri
SQLite: Enable foreign key checks
PostgreSQL: Respect NULL default value
PostgreSQL: Do not export triggers if not requested
PostgreSQL: Export DROP SEQUENCE if dropping table
Elasticsearch: Insert, update, delete
Adminer 4.4.0 (released 2018-01-17):