From f0a1f6aea2c5dfdb6a653d0a276a2e0b1c057ed4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 13 Jul 2007 03:43:23 +0000 Subject: [PATCH] Fix map_sql_typecoll_to_xmlschema_types() to not fail on dropped columns, per my gripe earlier today. Make it look a bit less like someone's first effort at backend coding. --- src/backend/utils/adt/xml.c | 49 +++++++++++++++---------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 50ba10f6f9..f2b672b9b0 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -2673,50 +2673,41 @@ map_sql_typecoll_to_xmlschema_types(List *tupdesc_list) List *uniquetypes = NIL; int i; StringInfoData result; - ListCell *cell0, *cell1, *cell2; + ListCell *cell0; - foreach (cell0, tupdesc_list) + /* extract all column types used in the set of TupleDescs */ + foreach(cell0, tupdesc_list) { - TupleDesc tupdesc = lfirst(cell0); + TupleDesc tupdesc = (TupleDesc) lfirst(cell0); - for (i = 1; i <= tupdesc->natts; i++) + for (i = 0; i < tupdesc->natts; i++) { - bool already_done = false; - Oid type = SPI_gettypeid(tupdesc, i); - foreach (cell1, uniquetypes) - if (type == lfirst_oid(cell1)) - { - already_done = true; - break; - } - if (already_done) + if (tupdesc->attrs[i]->attisdropped) continue; - - uniquetypes = lappend_oid(uniquetypes, type); + uniquetypes = list_append_unique_oid(uniquetypes, + tupdesc->attrs[i]->atttypid); } } /* add base types of domains */ - foreach (cell1, uniquetypes) + foreach(cell0, uniquetypes) { - bool already_done = false; - Oid type = getBaseType(lfirst_oid(cell1)); - foreach (cell2, uniquetypes) - if (type == lfirst_oid(cell2)) - { - already_done = true; - break; - } - if (already_done) - continue; + Oid typid = lfirst_oid(cell0); + Oid basetypid = getBaseType(typid); - uniquetypes = lappend_oid(uniquetypes, type); + if (basetypid != typid) + uniquetypes = list_append_unique_oid(uniquetypes, basetypid); } + /* Convert to textual form */ initStringInfo(&result); - foreach (cell1, uniquetypes) - appendStringInfo(&result, "%s\n", map_sql_type_to_xmlschema_type(lfirst_oid(cell1), -1)); + foreach(cell0, uniquetypes) + { + appendStringInfo(&result, "%s\n", + map_sql_type_to_xmlschema_type(lfirst_oid(cell0), + -1)); + } return result.data; } -- 2.39.5