Changeset: 52d17fea991f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/52d17fea991f Modified Files: clients/mapiclient/dump.c sql/test/testdb-previous-upgrade-hge/Tests/dump.stable.out sql/test/testdb-previous-upgrade/Tests/dump.stable.out sql/test/testdb-upgrade-hge/Tests/dump.stable.out sql/test/testdb-upgrade/Tests/dump.stable.out sql/test/testdb/Tests/dump-nogeom.stable.out sql/test/testdb/Tests/dump.stable.out sql/test/testdb/Tests/load.test Branch: Dec2023 Log Message:
First dump defaults and only then dump add tables. This fixes bug #7453. diffs (truncated from 738 to 300 lines): diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c --- a/clients/mapiclient/dump.c +++ b/clients/mapiclient/dump.c @@ -3154,6 +3154,123 @@ dump_database(Mapi mid, stream *toConsol mapi_close_handle(hdl); hdl = NULL; + /* dump views, functions and triggers */ + if ((hdl = mapi_query(mid, views_functions_triggers)) == NULL || + mapi_error(mid)) + goto bailout; + + while (rc == 0 && + mnstr_errnr(toConsole) == MNSTR_NO__ERROR && + mapi_fetch_row(hdl) != 0) { + char *id = strdup(mapi_fetch_field(hdl, 0)); + char *schema = strdup(mapi_fetch_field(hdl, 1)); + char *name = strdup(mapi_fetch_field(hdl, 2)); + const char *query = mapi_fetch_field(hdl, 3); + const char *remark = mapi_fetch_field(hdl, 4); + + if (mapi_error(mid) || id == NULL || schema == NULL || name == NULL) { + free(id); + free(schema); + free(name); + goto bailout; + } + if (sname != NULL && strcmp(schema, sname) != 0) { + free(id); + free(schema); + free(name); + continue; + } + if (curschema == NULL || strcmp(schema, curschema) != 0) { + if (curschema) + free(curschema); + curschema = strdup(schema); + if (curschema == NULL) { + free(id); + free(schema); + free(name); + goto bailout; + } + mnstr_printf(toConsole, "SET SCHEMA "); + dquoted_print(toConsole, curschema, ";\n"); + } + if (query) { + /* view or trigger */ + mnstr_printf(toConsole, "%s\n", query); + /* only views have comments due to query */ + comment_on(toConsole, "VIEW", schema, name, NULL, remark); + } else { + /* procedure */ + dump_functions(mid, toConsole, 0, schema, name, id); + } + free(id); + free(schema); + free(name); + } + mapi_close_handle(hdl); + hdl = NULL; + + /* dump DEFAULT clauses for tables */ + if (dump_table_defaults(mid, NULL, NULL, toConsole)) + goto bailout2; + + if (!describe) { + if (dump_foreign_keys(mid, NULL, NULL, NULL, toConsole)) + goto bailout2; + + /* dump sequences, part 2 */ + if ((hdl = mapi_query(mid, sequences2)) == NULL || + mapi_error(mid)) + goto bailout; + + while (mapi_fetch_row(hdl) != 0) { + const char *schema = mapi_fetch_field(hdl, 0); /* sch */ + const char *name = mapi_fetch_field(hdl, 1); /* seq */ + const char *restart = mapi_fetch_field(hdl, 3); /* rs */ + const char *minvalue; + const char *maxvalue; + const char *increment = mapi_fetch_field(hdl, 6); /* inc */ + const char *cycle = mapi_fetch_field(hdl, 8); /* cycle */ + + if (mapi_get_field_count(hdl) > 9) { + /* new version (Jan2022) of sys.describe_sequences */ + minvalue = mapi_fetch_field(hdl, 11); /* rmi */ + maxvalue = mapi_fetch_field(hdl, 12); /* rma */ + } else { + /* old version (pre Jan2022) of sys.describe_sequences */ + minvalue = mapi_fetch_field(hdl, 4); /* minvalue */ + maxvalue = mapi_fetch_field(hdl, 5); /* maxvalue */ + if (strcmp(minvalue, "0") == 0) + minvalue = NULL; + if (strcmp(maxvalue, "0") == 0) + maxvalue = NULL; + } + + if (sname != NULL && strcmp(schema, sname) != 0) + continue; + + mnstr_printf(toConsole, + "ALTER SEQUENCE "); + dquoted_print(toConsole, schema, "."); + dquoted_print(toConsole, name, NULL); + mnstr_printf(toConsole, " RESTART WITH %s", restart); + if (strcmp(increment, "1") != 0) + mnstr_printf(toConsole, " INCREMENT BY %s", increment); + if (minvalue) + mnstr_printf(toConsole, " MINVALUE %s", minvalue); + if (maxvalue) + mnstr_printf(toConsole, " MAXVALUE %s", maxvalue); + mnstr_printf(toConsole, " %sCYCLE;\n", strcmp(cycle, "true") == 0 ? "" : "NO "); + if (mnstr_errnr(toConsole) != MNSTR_NO__ERROR) { + mapi_close_handle(hdl); + hdl = NULL; + goto bailout2; + } + } + if (mapi_error(mid)) + goto bailout; + mapi_close_handle(hdl); + } + /* add tables to MERGE tables */ if ((hdl = mapi_query(mid, mergetables)) == NULL || mapi_error(mid)) goto bailout; @@ -3285,123 +3402,6 @@ dump_database(Mapi mid, stream *toConsol mapi_close_handle(hdl); hdl = NULL; - /* dump views, functions and triggers */ - if ((hdl = mapi_query(mid, views_functions_triggers)) == NULL || - mapi_error(mid)) - goto bailout; - - while (rc == 0 && - mnstr_errnr(toConsole) == MNSTR_NO__ERROR && - mapi_fetch_row(hdl) != 0) { - char *id = strdup(mapi_fetch_field(hdl, 0)); - char *schema = strdup(mapi_fetch_field(hdl, 1)); - char *name = strdup(mapi_fetch_field(hdl, 2)); - const char *query = mapi_fetch_field(hdl, 3); - const char *remark = mapi_fetch_field(hdl, 4); - - if (mapi_error(mid) || id == NULL || schema == NULL || name == NULL) { - free(id); - free(schema); - free(name); - goto bailout; - } - if (sname != NULL && strcmp(schema, sname) != 0) { - free(id); - free(schema); - free(name); - continue; - } - if (curschema == NULL || strcmp(schema, curschema) != 0) { - if (curschema) - free(curschema); - curschema = strdup(schema); - if (curschema == NULL) { - free(id); - free(schema); - free(name); - goto bailout; - } - mnstr_printf(toConsole, "SET SCHEMA "); - dquoted_print(toConsole, curschema, ";\n"); - } - if (query) { - /* view or trigger */ - mnstr_printf(toConsole, "%s\n", query); - /* only views have comments due to query */ - comment_on(toConsole, "VIEW", schema, name, NULL, remark); - } else { - /* procedure */ - dump_functions(mid, toConsole, 0, schema, name, id); - } - free(id); - free(schema); - free(name); - } - mapi_close_handle(hdl); - hdl = NULL; - - /* dump DEFAULT clauses for tables */ - if (dump_table_defaults(mid, NULL, NULL, toConsole)) - goto bailout2; - - if (!describe) { - if (dump_foreign_keys(mid, NULL, NULL, NULL, toConsole)) - goto bailout2; - - /* dump sequences, part 2 */ - if ((hdl = mapi_query(mid, sequences2)) == NULL || - mapi_error(mid)) - goto bailout; - - while (mapi_fetch_row(hdl) != 0) { - const char *schema = mapi_fetch_field(hdl, 0); /* sch */ - const char *name = mapi_fetch_field(hdl, 1); /* seq */ - const char *restart = mapi_fetch_field(hdl, 3); /* rs */ - const char *minvalue; - const char *maxvalue; - const char *increment = mapi_fetch_field(hdl, 6); /* inc */ - const char *cycle = mapi_fetch_field(hdl, 8); /* cycle */ - - if (mapi_get_field_count(hdl) > 9) { - /* new version (Jan2022) of sys.describe_sequences */ - minvalue = mapi_fetch_field(hdl, 11); /* rmi */ - maxvalue = mapi_fetch_field(hdl, 12); /* rma */ - } else { - /* old version (pre Jan2022) of sys.describe_sequences */ - minvalue = mapi_fetch_field(hdl, 4); /* minvalue */ - maxvalue = mapi_fetch_field(hdl, 5); /* maxvalue */ - if (strcmp(minvalue, "0") == 0) - minvalue = NULL; - if (strcmp(maxvalue, "0") == 0) - maxvalue = NULL; - } - - if (sname != NULL && strcmp(schema, sname) != 0) - continue; - - mnstr_printf(toConsole, - "ALTER SEQUENCE "); - dquoted_print(toConsole, schema, "."); - dquoted_print(toConsole, name, NULL); - mnstr_printf(toConsole, " RESTART WITH %s", restart); - if (strcmp(increment, "1") != 0) - mnstr_printf(toConsole, " INCREMENT BY %s", increment); - if (minvalue) - mnstr_printf(toConsole, " MINVALUE %s", minvalue); - if (maxvalue) - mnstr_printf(toConsole, " MAXVALUE %s", maxvalue); - mnstr_printf(toConsole, " %sCYCLE;\n", strcmp(cycle, "true") == 0 ? "" : "NO "); - if (mnstr_errnr(toConsole) != MNSTR_NO__ERROR) { - mapi_close_handle(hdl); - hdl = NULL; - goto bailout2; - } - } - if (mapi_error(mid)) - goto bailout; - mapi_close_handle(hdl); - } - if ((hdl = mapi_query(mid, table_grants)) == NULL || mapi_error(mid)) goto bailout; diff --git a/sql/test/testdb-previous-upgrade-hge/Tests/dump.stable.out b/sql/test/testdb-previous-upgrade-hge/Tests/dump.stable.out --- a/sql/test/testdb-previous-upgrade-hge/Tests/dump.stable.out +++ b/sql/test/testdb-previous-upgrade-hge/Tests/dump.stable.out @@ -101349,21 +101349,6 @@ CREATE TABLE "testschema"."geomtest" ( COPY 2 RECORDS INTO "testschema"."geomtest" FROM stdin USING DELIMITERS E'\t',E'\n','"'; POINT (10.5 12.3) LINESTRING (10 10, 20 20, 30 40) LINESTRING (10 10, 20 20, 30 40) POLYGON ((10 10, 10 20, 20 20, 20 15, 10 10)) POLYGON ((10 10, 10 20, 20 20, 20 15, 10 10)) MULTIPOINT ((20 80), (110 160), (20 160)) MULTILINESTRING ((0 0, 0 80, 60 80, 60 0, 0 0)) MULTILINESTRING ((0 0, 0 80, 60 80, 60 0, 0 0)) MULTIPOLYGON (((140 110, 260 110, 170 20, 50 20, 140 110)), ((300 270, 420 270, 340 190, 220 190, 300 270))) MULTIPOLYGON (((140 110, 260 110, 170 20, 50 20, 140 110)), ((300 270, 420 270, 340 190, 220 190, 300 270))) POLYGON ((10 10, 10 20, 20 20, 20 15, 10 10)) GEOMETRYCOLLECTION (POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0)), LINESTRING (10 10, 20 20, 30 40)) BOX (10.000000 10.000000, 20.000000 20.000000) NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL -ALTER TABLE "testschema"."testme" ADD TABLE "testschema"."subtable1" AS PARTITION FROM RANGE MINVALUE TO '11' WITH NULL VALUES; -ALTER TABLE "testschema"."testme" ADD TABLE "testschema"."subtable2" AS PARTITION FROM '11' TO '20'; -ALTER TABLE "testschema"."testme" ADD TABLE "testschema"."subtable3" AS PARTITION FROM '21' TO RANGE MAXVALUE; -ALTER TABLE "testschema"."testme2" ADD TABLE "testschema"."subtable4" AS PARTITION FROM RANGE MINVALUE TO RANGE MAXVALUE; -ALTER TABLE "testschema"."testme2" ADD TABLE "testschema"."subtable5" AS PARTITION FOR NULL VALUES; -ALTER TABLE "testschema"."testme3" ADD TABLE "testschema"."subtable6" AS PARTITION FROM RANGE MINVALUE TO RANGE MAXVALUE WITH NULL VALUES; -ALTER TABLE "testschema"."testvaluespartitions" ADD TABLE "testschema"."sublimits1" AS PARTITION IN ('1', '2', '3'); -ALTER TABLE "testschema"."testvaluespartitions" ADD TABLE "testschema"."sublimits2" AS PARTITION IN ('4', '5', '6') WITH NULL VALUES; -ALTER TABLE "testschema"."testvaluespartitions" ADD TABLE "testschema"."sublimits3" AS PARTITION IN ('7', '8', '9'); -ALTER TABLE "testschema"."mt3" ADD TABLE "testschema"."mt1"; -ALTER TABLE "testschema"."mt3" ADD TABLE "testschema"."t4"; -ALTER TABLE "testschema"."mt2" ADD TABLE "testschema"."t1"; -ALTER TABLE "testschema"."mt2" ADD TABLE "testschema"."t3"; -ALTER TABLE "testschema"."mt1" ADD TABLE "testschema"."t1"; -ALTER TABLE "testschema"."mt1" ADD TABLE "testschema"."t2"; create view keytest3 as select t2.key1, t2.key2, t1.key3 from keytest1 t1, keytest2 t2 where t1.key1 = t2.key1 and t1.key2 = t2.key2 ; COMMENT ON VIEW "testschema"."keytest3" IS 'a view used for testing'; @@ -101445,6 +101430,21 @@ ALTER TABLE "testschema"."keytest2" ADD ALTER TABLE "testschema"."selfref" ADD CONSTRAINT "selfref_parentid_fkey" FOREIGN KEY ("parentid") REFERENCES "testschema"."selfref" ("id"); ALTER SEQUENCE "testschema"."selfref_seq" RESTART WITH 7 NO CYCLE; ALTER SEQUENCE "testschema"."test_seq" RESTART WITH 8 INCREMENT BY 3 MINVALUE 5 MAXVALUE 10 CYCLE; +ALTER TABLE "testschema"."testme" ADD TABLE "testschema"."subtable1" AS PARTITION FROM RANGE MINVALUE TO '11' WITH NULL VALUES; +ALTER TABLE "testschema"."testme" ADD TABLE "testschema"."subtable2" AS PARTITION FROM '11' TO '20'; +ALTER TABLE "testschema"."testme" ADD TABLE "testschema"."subtable3" AS PARTITION FROM '21' TO RANGE MAXVALUE; +ALTER TABLE "testschema"."testme2" ADD TABLE "testschema"."subtable4" AS PARTITION FROM RANGE MINVALUE TO RANGE MAXVALUE; +ALTER TABLE "testschema"."testme2" ADD TABLE "testschema"."subtable5" AS PARTITION FOR NULL VALUES; +ALTER TABLE "testschema"."testme3" ADD TABLE "testschema"."subtable6" AS PARTITION FROM RANGE MINVALUE TO RANGE MAXVALUE WITH NULL VALUES; +ALTER TABLE "testschema"."testvaluespartitions" ADD TABLE "testschema"."sublimits1" AS PARTITION IN ('1', '2', '3'); +ALTER TABLE "testschema"."testvaluespartitions" ADD TABLE "testschema"."sublimits2" AS PARTITION IN ('4', '5', '6') WITH NULL VALUES; +ALTER TABLE "testschema"."testvaluespartitions" ADD TABLE "testschema"."sublimits3" AS PARTITION IN ('7', '8', '9'); +ALTER TABLE "testschema"."mt3" ADD TABLE "testschema"."mt1"; +ALTER TABLE "testschema"."mt3" ADD TABLE "testschema"."t4"; +ALTER TABLE "testschema"."mt2" ADD TABLE "testschema"."t1"; +ALTER TABLE "testschema"."mt2" ADD TABLE "testschema"."t3"; +ALTER TABLE "testschema"."mt1" ADD TABLE "testschema"."t1"; +ALTER TABLE "testschema"."mt1" ADD TABLE "testschema"."t2"; GRANT SELECT("string1") ON "testschema"."smallstring" TO "testuser" WITH GRANT OPTION; GRANT SELECT("string3") ON "testschema"."smallstring" TO "testuser" WITH GRANT OPTION; GRANT EXECUTE ON FUNCTION "testschema"."keyjoin"() TO PUBLIC; diff --git a/sql/test/testdb-previous-upgrade/Tests/dump.stable.out b/sql/test/testdb-previous-upgrade/Tests/dump.stable.out --- a/sql/test/testdb-previous-upgrade/Tests/dump.stable.out _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org