From 27b538c9557b52bc10c400f448cd8a4f55b60f71 Mon Sep 17 00:00:00 2001 From: yuchao Date: Fri, 31 Mar 2023 16:11:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMySQL=E9=A3=8E=E6=A0=BC?= =?UTF-8?q?=E7=9A=84=E5=AD=98=E5=82=A8=E8=BF=87=E7=A8=8B=E4=BD=BF=E7=94=A8?= =?UTF-8?q?gs=5Frestore=E5=AF=BC=E5=85=A5=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_dump/pg_dump.cpp | 39 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.cpp b/src/bin/pg_dump/pg_dump.cpp index f54edae9a..15d27f184 100644 --- a/src/bin/pg_dump/pg_dump.cpp +++ b/src/bin/pg_dump/pg_dump.cpp @@ -502,6 +502,7 @@ static void dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo); static void dumpUniquePrimaryDef(PQExpBuffer buf, ConstraintInfo* coninfo, IndxInfo* indxinfo, bool isBcompatibility); static bool findDBCompatibility(Archive* fout, const char* databasename); static void dumpTableAutoIncrement(Archive* fout, PQExpBuffer sqlbuf, TableInfo* tbinfo); +static bool IsPlainFormat(); static bool needIgnoreSequence(TableInfo* tbinfo); inline bool isDB4AIschema(const NamespaceInfo *nspinfo); #ifdef DUMPSYSLOG @@ -1707,7 +1708,9 @@ void validatedumpoptions() */ void validatedumpformats() { - if (*format == 'c' || *format == 'd' || *format == 't') { + if ((pg_strcasecmp(format, "custom") == 0 || pg_strcasecmp(format, "c") == 0) || + (pg_strcasecmp(format, "directory") == 0 || pg_strcasecmp(format, "d") == 0) || + (pg_strcasecmp(format, "tar") == 0 || pg_strcasecmp(format, "t") == 0)) { if (check_filepath == false) { write_stderr(_("options -F/--format argument '%c' must be used with -f/--file together\n"), *format); write_stderr(_("Try \"%s --help\" for more information.\n"), progname); @@ -13314,7 +13317,7 @@ static void dumpFunc(Archive* fout, FuncInfo* finfo) appendPQExpBuffer(delqry, "DROP %s IF EXISTS %s.%s%s;\n", funcKind, fmtId(finfo->dobj.nmspace->dobj.name), funcsig, if_cascade); - if (addDelimiter) { + if (addDelimiter && IsPlainFormat()) { appendPQExpBuffer(q, "delimiter //\n"); } @@ -13357,7 +13360,7 @@ static void dumpFunc(Archive* fout, FuncInfo* finfo) exit_horribly(NULL, "unrecognized provolatile value for function \"%s\"\n", finfo->dobj.name); } - if (isHasProshippable) { + if (isHasProshippable && (isProcedure || !addDelimiter)) { if (proshippable[0] == 't') { appendPQExpBuffer(q, " SHIPPABLE"); } else { @@ -13431,13 +13434,13 @@ static void dumpFunc(Archive* fout, FuncInfo* finfo) if (!fout->encryptfile && (pg_strcasecmp(format, "plain") == 0 || pg_strcasecmp(format, "p") == 0 || pg_strcasecmp(format, "a") == 0 || pg_strcasecmp(format, "append") == 0)) { - if (addDelimiter) { + if (addDelimiter && IsPlainFormat()) { appendPQExpBuffer(q, "\n %s;\n%s", asPart->data, "//\n"); } else { appendPQExpBuffer(q, "\n %s;\n%s", asPart->data, (isProcedure || (!isNullProargsrc)) ? "/\n" : ""); } } else { - if (addDelimiter) { + if (addDelimiter && IsPlainFormat()) { appendPQExpBuffer(q, "\n %s;\n%s", asPart->data, "//\n"); } else { appendPQExpBuffer(q, "\n %s;\n%s", asPart->data, (isProcedure || (!isNullProargsrc)) ? "\n" : ""); @@ -13449,7 +13452,7 @@ static void dumpFunc(Archive* fout, FuncInfo* finfo) if (binary_upgrade) binary_upgrade_extension_member(q, &finfo->dobj, labelq->data); - if (addDelimiter) { + if (addDelimiter && IsPlainFormat()) { appendPQExpBuffer(q, "delimiter ;\n"); } @@ -18538,7 +18541,7 @@ static void dumpViewSchema( * The DROP statement is automatically backed up when the backup format is -c/-t/-d. * So when use include_depend_objs and -p, we should also add the function. */ - if (include_depend_objs && !outputClean && (*format == 'p')) { + if (include_depend_objs && !outputClean && IsPlainFormat()) { appendPQExpBuffer(q, "DROP VIEW IF EXISTS %s.", fmtId(tbinfo->dobj.nmspace->dobj.name)); appendPQExpBuffer(q, "%s CASCADE;\n", fmtId(tbinfo->dobj.name)); } @@ -19088,7 +19091,7 @@ static void DumpMatviewSchema( * The DROP statement is automatically backed up when the backup format is -c/-t/-d. * So when use include_depend_objs and -p, we should also add the function. */ - if (include_depend_objs && !outputClean && (*format == 'p')) { + if (include_depend_objs && !outputClean && IsPlainFormat()) { appendPQExpBuffer(q, "DROP MATERIALIZED VIEW IF EXISTS %s.", fmtId(tbinfo->dobj.nmspace->dobj.name)); appendPQExpBuffer(q, "%s CASCADE;\n", fmtId(tbinfo->dobj.name)); } @@ -19276,7 +19279,7 @@ static void dumpTableSchema(Archive* fout, TableInfo* tbinfo) * The DROP statement is automatically backed up when the backup format is -c/-t/-d. * So when use include_depend_objs and -p, we should also add the function. */ - if (include_depend_objs && !outputClean && (*format == 'p')) { + if (include_depend_objs && !outputClean && IsPlainFormat()) { appendPQExpBuffer(q, "DROP %s IF EXISTS %s.", reltypename, fmtId(tbinfo->dobj.nmspace->dobj.name)); appendPQExpBuffer(q, "%s CASCADE;\n", fmtId(tbinfo->dobj.name)); } @@ -21320,7 +21323,7 @@ static void dumpSequence(Archive* fout, TableInfo* tbinfo, bool large) * The DROP statement is automatically backed up when the backup format is -c/-t/-d. * So when use include_depend_objs and -p, we should also add the function. */ - if (include_depend_objs && !outputClean && (*format == 'p')) { + if (include_depend_objs && !outputClean && IsPlainFormat()) { appendPQExpBuffer(query, "DROP %s SEQUENCE IF EXISTS %s.", optLarge, fmtId(tbinfo->dobj.nmspace->dobj.name)); appendPQExpBuffer(query, "%s CASCADE;\n", fmtId(tbinfo->dobj.name)); } @@ -21614,24 +21617,21 @@ static void dumpTrigger(Archive* fout, TriggerInfo* tginfo) if (NULL != tginfo->tgdef) { if (tginfo->tgdb) { appendPQExpBuffer(query, "DROP FUNCTION %s ;\n", tginfo->tgfname); - if (tginfo->tgbodybstyle) + if (tginfo->tgbodybstyle && IsPlainFormat()) appendPQExpBuffer(query, "delimiter //\n"); appendPQExpBuffer(query, "%s", tginfo->tgdef); - if (*format == 'p') { + if (IsPlainFormat()) { if (tginfo->tgbodybstyle) appendPQExpBuffer(query, "\n//\n"); else appendPQExpBuffer(query, "\n/\n"); } else { - if (tginfo->tgbodybstyle) - appendPQExpBuffer(query, "\n//\n"); - else - appendPQExpBuffer(query, ";\n"); + appendPQExpBuffer(query, ";\n"); } } else { appendPQExpBuffer(query, "%s;\n", tginfo->tgdef); } - if (tginfo->tgbodybstyle) + if (tginfo->tgbodybstyle && IsPlainFormat()) appendPQExpBuffer(query, "delimiter ;\n"); } else { if (tginfo->tgisconstraint) { @@ -23462,6 +23462,11 @@ static void dumpTableAutoIncrement(Archive* fout, PQExpBuffer sqlbuf, TableInfo* destroyPQExpBuffer(query); } +static bool IsPlainFormat() +{ + return pg_strcasecmp(format, "plain") == 0 || pg_strcasecmp(format, "p") == 0; +} + static bool needIgnoreSequence(TableInfo* tbinfo) { if (OidIsValid(tbinfo->owning_tab)) {