Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 39f06dc

Browse files
committed
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.
1 parent a702159 commit 39f06dc

File tree

1 file changed

+21
-30
lines changed
  • src/backend/utils/adt

1 file changed

+21
-30
lines changed

src/backend/utils/adt/xml.c

+21-30
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.45 2007/07/12 21:04:45 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.46 2007/07/13 03:43:23 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -2673,50 +2673,41 @@ map_sql_typecoll_to_xmlschema_types(List *tupdesc_list)
26732673
List *uniquetypes = NIL;
26742674
int i;
26752675
StringInfoData result;
2676-
ListCell *cell0, *cell1, *cell2;
2676+
ListCell *cell0;
26772677

2678-
foreach (cell0, tupdesc_list)
2678+
/* extract all column types used in the set of TupleDescs */
2679+
foreach(cell0, tupdesc_list)
26792680
{
2680-
TupleDesc tupdesc = lfirst(cell0);
2681+
TupleDesc tupdesc = (TupleDesc) lfirst(cell0);
26812682

2682-
for (i = 1; i <= tupdesc->natts; i++)
2683+
for (i = 0; i < tupdesc->natts; i++)
26832684
{
2684-
bool already_done = false;
2685-
Oid type = SPI_gettypeid(tupdesc, i);
2686-
foreach (cell1, uniquetypes)
2687-
if (type == lfirst_oid(cell1))
2688-
{
2689-
already_done = true;
2690-
break;
2691-
}
2692-
if (already_done)
2685+
if (tupdesc->attrs[i]->attisdropped)
26932686
continue;
2694-
2695-
uniquetypes = lappend_oid(uniquetypes, type);
2687+
uniquetypes = list_append_unique_oid(uniquetypes,
2688+
tupdesc->attrs[i]->atttypid);
26962689
}
26972690
}
26982691

26992692
/* add base types of domains */
2700-
foreach (cell1, uniquetypes)
2693+
foreach(cell0, uniquetypes)
27012694
{
2702-
bool already_done = false;
2703-
Oid type = getBaseType(lfirst_oid(cell1));
2704-
foreach (cell2, uniquetypes)
2705-
if (type == lfirst_oid(cell2))
2706-
{
2707-
already_done = true;
2708-
break;
2709-
}
2710-
if (already_done)
2711-
continue;
2695+
Oid typid = lfirst_oid(cell0);
2696+
Oid basetypid = getBaseType(typid);
27122697

2713-
uniquetypes = lappend_oid(uniquetypes, type);
2698+
if (basetypid != typid)
2699+
uniquetypes = list_append_unique_oid(uniquetypes, basetypid);
27142700
}
27152701

2702+
/* Convert to textual form */
27162703
initStringInfo(&result);
27172704

2718-
foreach (cell1, uniquetypes)
2719-
appendStringInfo(&result, "%s\n", map_sql_type_to_xmlschema_type(lfirst_oid(cell1), -1));
2705+
foreach(cell0, uniquetypes)
2706+
{
2707+
appendStringInfo(&result, "%s\n",
2708+
map_sql_type_to_xmlschema_type(lfirst_oid(cell0),
2709+
-1));
2710+
}
27202711

27212712
return result.data;
27222713
}

0 commit comments

Comments
 (0)