mirror of
https://github.com/postgres/postgres.git
synced 2025-08-18 12:22:09 +03:00
Extend EXPLAIN to support output in XML or JSON format.
There are probably still some adjustments to be made in the details of the output, but this gets the basic structure in place. Robert Haas
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.92 2009/06/11 14:49:04 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.93 2009/08/10 05:46:50 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1593,8 +1593,6 @@ map_xml_name_to_sql_identifier(char *name)
|
||||
char *
|
||||
map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
|
||||
{
|
||||
StringInfoData buf;
|
||||
|
||||
if (type_is_array(type))
|
||||
{
|
||||
ArrayType *array;
|
||||
@@ -1605,6 +1603,7 @@ map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
|
||||
int num_elems;
|
||||
Datum *elem_values;
|
||||
bool *elem_nulls;
|
||||
StringInfoData buf;
|
||||
int i;
|
||||
|
||||
array = DatumGetArrayTypeP(value);
|
||||
@@ -1638,8 +1637,7 @@ map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
|
||||
{
|
||||
Oid typeOut;
|
||||
bool isvarlena;
|
||||
char *p,
|
||||
*str;
|
||||
char *str;
|
||||
|
||||
/*
|
||||
* Special XSD formatting for some data types
|
||||
@@ -1788,35 +1786,50 @@ map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings)
|
||||
return str;
|
||||
|
||||
/* otherwise, translate special characters as needed */
|
||||
initStringInfo(&buf);
|
||||
|
||||
for (p = str; *p; p++)
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case '&':
|
||||
appendStringInfoString(&buf, "&");
|
||||
break;
|
||||
case '<':
|
||||
appendStringInfoString(&buf, "<");
|
||||
break;
|
||||
case '>':
|
||||
appendStringInfoString(&buf, ">");
|
||||
break;
|
||||
case '\r':
|
||||
appendStringInfoString(&buf, "
");
|
||||
break;
|
||||
default:
|
||||
appendStringInfoCharMacro(&buf, *p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return buf.data;
|
||||
return escape_xml(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Escape characters in text that have special meanings in XML.
|
||||
*
|
||||
* Returns a palloc'd string.
|
||||
*
|
||||
* NB: this is intentionally not dependent on libxml.
|
||||
*/
|
||||
char *
|
||||
escape_xml(const char *str)
|
||||
{
|
||||
StringInfoData buf;
|
||||
const char *p;
|
||||
|
||||
initStringInfo(&buf);
|
||||
for (p = str; *p; p++)
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case '&':
|
||||
appendStringInfoString(&buf, "&");
|
||||
break;
|
||||
case '<':
|
||||
appendStringInfoString(&buf, "<");
|
||||
break;
|
||||
case '>':
|
||||
appendStringInfoString(&buf, ">");
|
||||
break;
|
||||
case '\r':
|
||||
appendStringInfoString(&buf, "
");
|
||||
break;
|
||||
default:
|
||||
appendStringInfoCharMacro(&buf, *p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buf.data;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
_SPI_strdup(const char *s)
|
||||
{
|
||||
|
Reference in New Issue
Block a user