|
81 | 81 | #include "mb/pg_wchar.h"
|
82 | 82 | #include "miscadmin.h"
|
83 | 83 | #include "nodes/execnodes.h"
|
| 84 | +#include "nodes/miscnodes.h" |
84 | 85 | #include "nodes/nodeFuncs.h"
|
85 | 86 | #include "utils/array.h"
|
86 | 87 | #include "utils/builtins.h"
|
@@ -894,41 +895,18 @@ bool
|
894 | 895 | xml_is_document(xmltype *arg)
|
895 | 896 | {
|
896 | 897 | #ifdef USE_LIBXML
|
897 |
| - bool result; |
898 |
| - volatile xmlDocPtr doc = NULL; |
899 |
| - MemoryContext ccxt = CurrentMemoryContext; |
900 |
| - |
901 |
| - /* We want to catch ereport(INVALID_XML_DOCUMENT) and return false */ |
902 |
| - PG_TRY(); |
903 |
| - { |
904 |
| - doc = xml_parse((text *) arg, XMLOPTION_DOCUMENT, true, |
905 |
| - GetDatabaseEncoding(), NULL); |
906 |
| - result = true; |
907 |
| - } |
908 |
| - PG_CATCH(); |
909 |
| - { |
910 |
| - ErrorData *errdata; |
911 |
| - MemoryContext ecxt; |
912 |
| - |
913 |
| - ecxt = MemoryContextSwitchTo(ccxt); |
914 |
| - errdata = CopyErrorData(); |
915 |
| - if (errdata->sqlerrcode == ERRCODE_INVALID_XML_DOCUMENT) |
916 |
| - { |
917 |
| - FlushErrorState(); |
918 |
| - result = false; |
919 |
| - } |
920 |
| - else |
921 |
| - { |
922 |
| - MemoryContextSwitchTo(ecxt); |
923 |
| - PG_RE_THROW(); |
924 |
| - } |
925 |
| - } |
926 |
| - PG_END_TRY(); |
| 898 | + xmlDocPtr doc; |
| 899 | + ErrorSaveContext escontext = {T_ErrorSaveContext}; |
927 | 900 |
|
| 901 | + /* |
| 902 | + * We'll report "true" if no soft error is reported by xml_parse(). |
| 903 | + */ |
| 904 | + doc = xml_parse((text *) arg, XMLOPTION_DOCUMENT, true, |
| 905 | + GetDatabaseEncoding(), (Node *) &escontext); |
928 | 906 | if (doc)
|
929 | 907 | xmlFreeDoc(doc);
|
930 | 908 |
|
931 |
| - return result; |
| 909 | + return !escontext.error_occurred; |
932 | 910 | #else /* not USE_LIBXML */
|
933 | 911 | NO_XML_SUPPORT();
|
934 | 912 | return false;
|
@@ -4320,26 +4298,18 @@ xpath_exists(PG_FUNCTION_ARGS)
|
4320 | 4298 | static bool
|
4321 | 4299 | wellformed_xml(text *data, XmlOptionType xmloption_arg)
|
4322 | 4300 | {
|
4323 |
| - bool result; |
4324 |
| - volatile xmlDocPtr doc = NULL; |
4325 |
| - |
4326 |
| - /* We want to catch any exceptions and return false */ |
4327 |
| - PG_TRY(); |
4328 |
| - { |
4329 |
| - doc = xml_parse(data, xmloption_arg, true, GetDatabaseEncoding(), NULL); |
4330 |
| - result = true; |
4331 |
| - } |
4332 |
| - PG_CATCH(); |
4333 |
| - { |
4334 |
| - FlushErrorState(); |
4335 |
| - result = false; |
4336 |
| - } |
4337 |
| - PG_END_TRY(); |
| 4301 | + xmlDocPtr doc; |
| 4302 | + ErrorSaveContext escontext = {T_ErrorSaveContext}; |
4338 | 4303 |
|
| 4304 | + /* |
| 4305 | + * We'll report "true" if no soft error is reported by xml_parse(). |
| 4306 | + */ |
| 4307 | + doc = xml_parse(data, xmloption_arg, true, |
| 4308 | + GetDatabaseEncoding(), (Node *) &escontext); |
4339 | 4309 | if (doc)
|
4340 | 4310 | xmlFreeDoc(doc);
|
4341 | 4311 |
|
4342 |
| - return result; |
| 4312 | + return !escontext.error_occurred; |
4343 | 4313 | }
|
4344 | 4314 | #endif
|
4345 | 4315 |
|
|
0 commit comments