s = nodeToStringWithLocations(obj); if (pretty)
f = pretty_format_node_dump(s); else
f = format_node_dump(s);
pfree(s);
ereport(lev,
(errmsg_internal("%s:", title),
errdetail_internal("%s", f)));
pfree(f);
}
/* *FormatanodeToStringoutputfordisplayonaterminal. * *Theresultisapalloc'dstring. * *Thisversionjusttriestobreakatwhitespace.
*/
char *
format_node_dump(const char *dump)
{ #define LINELEN 78
char line[LINELEN + 1];
StringInfoData str; int i; int j; int k;
initStringInfo(&str);
i = 0; for (;;)
{ for (j = 0; j < LINELEN && dump[i] != '\0'; i++, j++)
line[j] = dump[i]; if (dump[i] == '\0')
break; if (dump[i] == ' ')
{ /* ok to break at adjacent space */
i++;
} else
{ for (k = j - 1; k > 0; k--) if (line[k] == ' ')
break; if (k > 0)
{ /* back up; will reprint all after space */
i -= (j - k - 1);
j = k;
}
}
line[j] = '\0';
appendStringInfo(&str, "%s\n", line);
} if (j > 0)
{
line[j] = '\0';
appendStringInfo(&str, "%s\n", line);
} return str.data; #undef LINELEN
}
/* *FormatanodeToStringoutputfordisplayonaterminal. * *Theresultisapalloc'dstring. * *Thisversiontriestoindentintelligently.
*/
char *
pretty_format_node_dump(const char *dump)
{ #define INDENTSTOP 3 #define MAXINDENT 60 #define LINELEN 78
char line[LINELEN + 1];
StringInfoData str; int indentLev; int indentDist; int i; int j;
initStringInfo(&str);
indentLev = 0; /* logical indent level */
indentDist = 0; /* physical indent distance */
i = 0; for (;;)
{ for (j = 0; j < indentDist; j++)
line[j] = ' '; for (; j < LINELEN && dump[i] != '\0'; i++, j++)
{
line[j] = dump[i]; switch (line[j])
{
case '}': if (j != indentDist)
{ /* print data before the } */
line[j] = '\0';
appendStringInfo(&str, "%s\n", line);
} /* print the } at indentDist */
line[indentDist] = '}';
line[indentDist + 1] = '\0';
appendStringInfo(&str, "%s\n", line); /* outdent */ if (indentLev > 0)
{
indentLev--;
indentDist = Min(indentLev * INDENTSTOP, MAXINDENT);
}
j = indentDist - 1; /* j will equal indentDist on next loop iteration */ /* suppress whitespace just after } */ while (dump[i + 1] == ' ')
i++;
break;
case ')': /* force line break after ), unless another ) follows */ if (dump[i + 1] != ')')
{
line[j + 1] = '\0';
appendStringInfo(&str, "%s\n", line);
j = indentDist - 1; while (dump[i + 1] == ' ')
i++;
}
break;
case '{': /* force line break before { */ if (j != indentDist)
{
line[j] = '\0';
appendStringInfo(&str, "%s\n", line);
} /* indent */
indentLev++;
indentDist = Min(indentLev * INDENTSTOP, MAXINDENT); for (j = 0; j < indentDist; j++)
line[j] = ' ';
line[j] = dump[i];
break;
case ':': /* force line break before : */ if (j != indentDist)
{
line[j] = '\0';
appendStringInfo(&str, "%s\n", line);
}
j = indentDist;
line[j] = dump[i];
break;
}
}
line[j] = '\0'; if (dump[i] == '\0')
break;
appendStringInfo(&str, "%s\n", line);
} if (j > 0)
appendStringInfo(&str, "%s\n", line); return str.data; #undef INDENTSTOP #undef MAXINDENT #undef LINELEN
}
/* *print_rt *printcontentsofrangetable
*/ void
print_rt(const List *rtable)
{
const ListCell *l; int i = 1;
switch (rte->rtekind)
{
case RTE_RELATION:
printf("%d\t%s\t%u\t%c",
i, rte->eref->aliasname, rte->relid, rte->relkind);
break;
case RTE_SUBQUERY:
printf("%d\t%s\t[subquery]",
i, rte->eref->aliasname);
break;
case RTE_JOIN:
printf("%d\t%s\t[join]",
i, rte->eref->aliasname);
break;
case RTE_FUNCTION:
printf("%d\t%s\t[rangefunction]",
i, rte->eref->aliasname);
break;
case RTE_TABLEFUNC:
printf("%d\t%s\t[table function]",
i, rte->eref->aliasname);
break;
case RTE_VALUES:
printf("%d\t%s\t[values list]",
i, rte->eref->aliasname);
break;
case RTE_CTE:
printf("%d\t%s\t[cte]",
i, rte->eref->aliasname);
break;
case RTE_NAMEDTUPLESTORE:
printf("%d\t%s\t[tuplestore]",
i, rte->eref->aliasname);
break;
case RTE_RESULT:
printf("%d\t%s\t[result]",
i, rte->eref->aliasname);
break;
case RTE_GROUP:
printf("%d\t%s\t[group]",
i, rte->eref->aliasname);
break;
default:
printf("%d\t%s\t[unknown rtekind]",
i, rte->eref->aliasname);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.