From b40c3ffd7f9006bbe58c648d986f22cdf67d43de Mon Sep 17 00:00:00 2001 From: liuheng Date: Thu, 16 Feb 2023 16:49:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81XML=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/src/build_options.cmake | 3 +- configure | 22 +++++++++----- src/common/CMakeLists.txt | 2 ++ src/test/regress/expected/xml.out | 47 ++++++++++++++++++++++++++--- src/test/regress/parallel_schedule0 | 1 + src/test/regress/sql/xml.sql | 15 +++++++++ 6 files changed, 77 insertions(+), 13 deletions(-) diff --git a/cmake/src/build_options.cmake b/cmake/src/build_options.cmake index 5f2865a6f..4560cc765 100755 --- a/cmake/src/build_options.cmake +++ b/cmake/src/build_options.cmake @@ -74,7 +74,7 @@ option(USE_BONJOUR "enable bonjour, the old is --with-bonjour" OFF) option(USE_LDAP "build with ldap, the old is --with-ldap" OFF)#ON option(USE_ETCD "build with etcd libs, new option for old mppdb, after 8.1 close it" OFF) option(USE_PROTOBUF "build with with protobuf's libs, we must need it" ON) -option(USE_LIBXML "build with libxml, the old is --with-libxml" OFF) +option(USE_LIBXML "build with libxml, the old is --with-libxml" ON) option(HAVE_LIBXML2 "build with libxml2, the old is --with-libxml2" OFF) option(USE_LIBXSLT "build with libxslt, the old is --with-libxslt" OFF) option(USE_PAM "build with pam, the old is --with-pam" OFF) @@ -230,6 +230,7 @@ if(${USE_LIBXML}) else() set(LIBS "${LIBS} -lxml") set(GAUSSDB_CONFIGURE "${GAUSSDB_CONFIGURE} -DUSE_LIBXML") + set(CMAKE_CXX_FLAGS -l:liblzma.so.5) endif() endif() diff --git a/configure b/configure index 711590adb..b1d953c91 100755 --- a/configure +++ b/configure @@ -6482,7 +6482,11 @@ fi # XML # - +if [[ "$enable_lite_mode" != yes ]]; then + with_libxml=yes +else + with_libxml=no +fi # Check whether --with-libxml was given. if test "${with_libxml+set}" = set; then @@ -6510,10 +6514,11 @@ else fi - - +xml2_cflag=${with_3rdpartydir}/kernel/dependency/libxml2/comm/include/libxml2 +xml2_lib=${with_3rdpartydir}/kernel/dependency/libxml2/comm/lib +xml2_config=${with_3rdpartydir}/kernel/dependency/libxml2/comm/bin/xml2-config if test "$with_libxml" = yes ; then - for ac_prog in xml2-config + for ac_prog in ${xml2_config} do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 @@ -6542,7 +6547,7 @@ IFS=$as_save_IFS fi fi -XML2_CONFIG=$ac_cv_prog_XML2_CONFIG +XML2_CONFIG=$xml2_config if test -n "$XML2_CONFIG"; then { $as_echo "$as_me:$LINENO: result: $XML2_CONFIG" >&5 $as_echo "$XML2_CONFIG" >&6; } @@ -6558,12 +6563,12 @@ done if test -n "$XML2_CONFIG"; then for pgac_option in `$XML2_CONFIG --cflags`; do case $pgac_option in - -I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option";; + -I*|-D*) CPPFLAGS="$CPPFLAGS $pgac_option -I${xml2_cflag}";; esac done for pgac_option in `$XML2_CONFIG --libs`; do case $pgac_option in - -L*) LDFLAGS="$LDFLAGS $pgac_option";; + -L*) LDFLAGS="$LDFLAGS $pgac_option -L${xml2_lib}";; esac done fi @@ -9847,7 +9852,7 @@ if test "${ac_cv_lib_xml2_xmlSaveToBuffer+set}" = set; then $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS -LIBS="-lxml2 $LIBS" +LIBS="-L${xml2_lib} -lxml2 -lm -ldl $LIBS" cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF @@ -13439,6 +13444,7 @@ done fi if test "$with_libxml" = yes ; then + CPPFLAGS="-I${xml2_cflag} $CPPFLAGS" if test "${ac_cv_header_libxml_parser_h+set}" = set; then { $as_echo "$as_me:$LINENO: checking for libxml/parser.h" >&5 $as_echo_n "checking for libxml/parser.h... " >&6; } diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 0ff7b4e29..08e20cc6a 100755 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -5,6 +5,8 @@ set(CMAKE_RULE_MESSAGES OFF) set(CMAKE_SKIP_RPATH TRUE) INCLUDE_DIRECTORIES(${CJSON_INCLUDE_PATH} ${BOOST_INCLUDE_PATH}) +INCLUDE_DIRECTORIES(${LIBXML_INCLUDE_PATH}/libxml2) +INCLUDE_DIRECTORIES(${LIBXML_LIB_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/timezone diff --git a/src/test/regress/expected/xml.out b/src/test/regress/expected/xml.out index 19f3d09a6..72cba2472 100644 --- a/src/test/regress/expected/xml.out +++ b/src/test/regress/expected/xml.out @@ -11,6 +11,18 @@ LINE 1: INSERT INTO xmltest VALUES (3, '', NULL, ''); xmlconcat -------------- @@ -102,6 +118,7 @@ SELECT xmlelement(name element, ERROR: unnamed XML attribute value must be a column reference LINE 2: xmlattributes ('unnamed and wrong')); ^ +CONTEXT: referenced column: xmlelement SELECT xmlelement(name element, xmlelement(name nested, 'stuff')); xmlelement ------------------------------------------- @@ -123,6 +140,7 @@ SELECT xmlelement(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a)); ERROR: XML attribute name "a" appears more than once LINE 1: ...ment(name duplicate, xmlattributes(1 as a, 2 as b, 3 as a)); ^ +CONTEXT: referenced column: xmlelement SELECT xmlelement(name num, 37); xmlelement --------------- @@ -188,6 +206,7 @@ SELECT xmlelement(name foo, xmlattributes('2009-04-09 00:24:37'::timestamp as ba SELECT xmlelement(name foo, xmlattributes('infinity'::timestamp as bar)); ERROR: timestamp out of range DETAIL: XML does not support infinite timestamp values. +CONTEXT: referenced column: xmlelement SELECT xmlelement(name foo, xmlattributes('<>&"''' as funny, xml 'br' as funnier)); xmlelement ------------------------------------------------------------ @@ -214,6 +233,7 @@ DETAIL: line 1: xmlParseEntityRef: no name line 1: chunk is not well balanced & ^ +CONTEXT: referenced column: xmlparse SELECT xmlparse(content '&idontexist;'); ERROR: invalid XML content DETAIL: line 1: Entity 'idontexist' not defined @@ -222,6 +242,7 @@ DETAIL: line 1: Entity 'idontexist' not defined line 1: chunk is not well balanced &idontexist; ^ +CONTEXT: referenced column: xmlparse SELECT xmlparse(content ''); xmlparse --------------------------- @@ -245,6 +266,7 @@ line 1: Opening and ending tag mismatch: twoerrors line 1 and unbalanced line 1: chunk is not well balanced &idontexist; ^ +CONTEXT: referenced column: xmlparse SELECT xmlparse(content ''); xmlparse --------------------- @@ -256,6 +278,7 @@ ERROR: invalid XML document DETAIL: line 1: Start tag expected, '<' not found abc ^ +CONTEXT: referenced column: xmlparse SELECT xmlparse(document 'x'); xmlparse -------------- @@ -270,6 +293,7 @@ DETAIL: line 1: xmlParseEntityRef: no name line 1: Opening and ending tag mismatch: invalidentity line 1 and abc & ^ +CONTEXT: referenced column: xmlparse SELECT xmlparse(document '&idontexist;'); ERROR: invalid XML document DETAIL: line 1: Entity 'idontexist' not defined @@ -278,6 +302,7 @@ DETAIL: line 1: Entity 'idontexist' not defined line 1: Opening and ending tag mismatch: undefinedentity line 1 and abc &idontexist; ^ +CONTEXT: referenced column: xmlparse SELECT xmlparse(document ''); xmlparse --------------------------- @@ -298,6 +323,7 @@ DETAIL: line 1: Entity 'idontexist' not defined line 1: Opening and ending tag mismatch: twoerrors line 1 and unbalanced &idontexist; ^ +CONTEXT: referenced column: xmlparse SELECT xmlparse(document ''); xmlparse --------------------- @@ -313,6 +339,7 @@ SELECT xmlpi(name foo); SELECT xmlpi(name xml); ERROR: invalid XML processing instruction DETAIL: XML processing instruction target name cannot be "xml". +CONTEXT: referenced column: xmlpi SELECT xmlpi(name xmlstuff); xmlpi -------------- @@ -328,6 +355,7 @@ SELECT xmlpi(name foo, 'bar'); SELECT xmlpi(name foo, 'in?>valid'); ERROR: invalid XML processing instruction DETAIL: XML processing instruction cannot contain "?>". +CONTEXT: referenced column: xmlpi SELECT xmlpi(name foo, null); xmlpi ------- @@ -337,6 +365,7 @@ SELECT xmlpi(name foo, null); SELECT xmlpi(name xml, null); ERROR: invalid XML processing instruction DETAIL: XML processing instruction target name cannot be "xml". +CONTEXT: referenced column: xmlpi SELECT xmlpi(name xmlstuff, null); xmlpi ------- @@ -438,6 +467,7 @@ SELECT xmlserialize(content 'good' as char(10)); SELECT xmlserialize(document 'bad' as text); ERROR: not an XML document +CONTEXT: referenced column: xmlserialize SELECT xml 'bar' IS DOCUMENT; ?column? ---------- @@ -569,8 +599,11 @@ SELECT xpath(NULL, NULL) IS NULL FROM xmltest; (2 rows) SELECT xpath('', ''); -ERROR: empty XPath expression -CONTEXT: SQL function "xpath" statement 1 + xpath +------- + +(1 row) + SELECT xpath('//text()', 'number one'); xpath ---------------- @@ -883,14 +916,18 @@ ERROR: could not parse XML document DETAIL: line 1: Namespace prefix nosuchprefix on tag is not defined ^ -CONTEXT: SQL function "xpath" statement 1 +CONTEXT: referenced column: xpath +SQL function "xpath" statement 1 +referenced column: xpath -- XPath deprecates relative namespaces, but they're not supposed to -- throw an error, only a warning. SELECT xpath('/*', ''); WARNING: line 1: xmlns: URI relative is not absolute ^ -CONTEXT: SQL function "xpath" statement 1 +CONTEXT: referenced column: xpath +SQL function "xpath" statement 1 +referenced column: xpath xpath -------------------------------------- {""} @@ -916,3 +953,5 @@ SELECT XMLPARSE(DOCUMENT '  (1 row) +DROP VIEW xmlview4; +DROP TABLE emp; diff --git a/src/test/regress/parallel_schedule0 b/src/test/regress/parallel_schedule0 index 0773705c6..4f103ed6b 100644 --- a/src/test/regress/parallel_schedule0 +++ b/src/test/regress/parallel_schedule0 @@ -236,6 +236,7 @@ test: single_node_bitmapops single_node_combocid #single_node_window #test: single_node_xmlmap #test: single_node_functional_deps single_node_advisory_lock single_node_json single_node_equivclass +test: xml # ---------- # Another group of parallel tests diff --git a/src/test/regress/sql/xml.sql b/src/test/regress/sql/xml.sql index 2ce691cac..986c588ea 100644 --- a/src/test/regress/sql/xml.sql +++ b/src/test/regress/sql/xml.sql @@ -7,6 +7,19 @@ INSERT INTO xmltest VALUES (1, 'one'); INSERT INTO xmltest VALUES (2, 'two'); INSERT INTO xmltest VALUES (3, ']> SELECT XMLPARSE(DOCUMENT ']>&c;'); -- This might or might not load the requested DTD, but it mustn't throw error. SELECT XMLPARSE(DOCUMENT ' '); +DROP VIEW xmlview4; +DROP TABLE emp; \ No newline at end of file