支持XML类型

This commit is contained in:
liuheng
2023-02-16 16:49:01 +08:00
parent 3f2da96ef6
commit b40c3ffd7f
6 changed files with 77 additions and 13 deletions

View File

@ -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()

22
configure vendored
View File

@ -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; }

View File

@ -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

View File

@ -11,6 +11,18 @@ LINE 1: INSERT INTO xmltest VALUES (3, '<wrong');
DETAIL: line 1: Couldn't find end of Start Tag wrong line 1
<wrong
^
CONTEXT: referenced column: data
CREATE TABLE emp (
name varchar(20),
age int,
salary int
);
INSERT INTO emp VALUES ('bill', 20, 1000);
INSERT INTO emp VALUES ('cim', 30, 400);
INSERT INTO emp VALUES ('jeff', 23, 600);
INSERT INTO emp VALUES ('linda', 19, 100);
INSERT INTO emp VALUES ('sam', 30, 2000);
INSERT INTO emp VALUES ('sharon', 25, 1000);
SELECT * FROM xmltest ORDER BY 1;
id | data
----+--------------------
@ -32,8 +44,10 @@ SELECT xmlcomment('-test');
SELECT xmlcomment('test-');
ERROR: invalid XML comment
CONTEXT: referenced column: xmlcomment
SELECT xmlcomment('--test');
ERROR: invalid XML comment
CONTEXT: referenced column: xmlcomment
SELECT xmlcomment('te st');
xmlcomment
--------------
@ -58,6 +72,7 @@ SELECT xmlconcat(1, 2);
ERROR: argument of XMLCONCAT must be type xml, not type integer
LINE 1: SELECT xmlconcat(1, 2);
^
CONTEXT: referenced column: xmlconcat
SELECT xmlconcat('bad', '<syntax');
ERROR: invalid XML content
LINE 1: SELECT xmlconcat('bad', '<syntax');
@ -65,6 +80,7 @@ LINE 1: SELECT xmlconcat('bad', '<syntax');
DETAIL: line 1: Couldn't find end of Start Tag syntax line 1
<syntax
^
CONTEXT: referenced column: xmlconcat
SELECT xmlconcat('<foo/>', NULL, '<?xml version="1.1" standalone="no"?><bar/>');
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 'b<a/>r' as funnier));
xmlelement
------------------------------------------------------------
@ -214,6 +233,7 @@ DETAIL: line 1: xmlParseEntityRef: no name
line 1: chunk is not well balanced
<invalidentity>&</invalidentity>
^
CONTEXT: referenced column: xmlparse
SELECT xmlparse(content '<undefinedentity>&idontexist;</undefinedentity>');
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
<undefinedentity>&idontexist;</undefinedentity>
^
CONTEXT: referenced column: xmlparse
SELECT xmlparse(content '<invalidns xmlns=''&lt;''/>');
xmlparse
---------------------------
@ -245,6 +266,7 @@ line 1: Opening and ending tag mismatch: twoerrors line 1 and unbalanced
line 1: chunk is not well balanced
<twoerrors>&idontexist;</unbalanced>
^
CONTEXT: referenced column: xmlparse
SELECT xmlparse(content '<nosuchprefix:tag/>');
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 '<abc>x</abc>');
xmlparse
--------------
@ -270,6 +293,7 @@ DETAIL: line 1: xmlParseEntityRef: no name
line 1: Opening and ending tag mismatch: invalidentity line 1 and abc
<invalidentity>&</abc>
^
CONTEXT: referenced column: xmlparse
SELECT xmlparse(document '<undefinedentity>&idontexist;</abc>');
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
<undefinedentity>&idontexist;</abc>
^
CONTEXT: referenced column: xmlparse
SELECT xmlparse(document '<invalidns xmlns=''&lt;''/>');
xmlparse
---------------------------
@ -298,6 +323,7 @@ DETAIL: line 1: Entity 'idontexist' not defined
line 1: Opening and ending tag mismatch: twoerrors line 1 and unbalanced
<twoerrors>&idontexist;</unbalanced>
^
CONTEXT: referenced column: xmlparse
SELECT xmlparse(document '<nosuchprefix:tag/>');
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 '<foo>bar</foo>' IS DOCUMENT;
?column?
----------
@ -569,8 +599,11 @@ SELECT xpath(NULL, NULL) IS NULL FROM xmltest;
(2 rows)
SELECT xpath('', '<!-- error -->');
ERROR: empty XPath expression
CONTEXT: SQL function "xpath" statement 1
xpath
-------
(1 row)
SELECT xpath('//text()', '<local:data xmlns:local="http://127.0.0.1"><local:piece id="1">number one</local:piece><local:piece id="2" /></local:data>');
xpath
----------------
@ -883,14 +916,18 @@ ERROR: could not parse XML document
DETAIL: line 1: Namespace prefix nosuchprefix on tag is not defined
<nosuchprefix:tag/>
^
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('/*', '<relativens xmlns=''relative''/>');
WARNING: line 1: xmlns: URI relative is not absolute
<relativens xmlns='relative'/>
^
CONTEXT: SQL function "xpath" statement 1
CONTEXT: referenced column: xpath
SQL function "xpath" statement 1
referenced column: xpath
xpath
--------------------------------------
{"<relativens xmlns=\"relative\"/>"}
@ -916,3 +953,5 @@ SELECT XMLPARSE(DOCUMENT '<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"><chapter>&nbsp;</chapter>
(1 row)
DROP VIEW xmlview4;
DROP TABLE emp;

View File

@ -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

View File

@ -7,6 +7,19 @@ INSERT INTO xmltest VALUES (1, '<value>one</value>');
INSERT INTO xmltest VALUES (2, '<value>two</value>');
INSERT INTO xmltest VALUES (3, '<wrong');
CREATE TABLE emp (
name varchar(20),
age int,
salary int
);
INSERT INTO emp VALUES ('bill', 20, 1000);
INSERT INTO emp VALUES ('cim', 30, 400);
INSERT INTO emp VALUES ('jeff', 23, 600);
INSERT INTO emp VALUES ('linda', 19, 100);
INSERT INTO emp VALUES ('sam', 30, 2000);
INSERT INTO emp VALUES ('sharon', 25, 1000);
SELECT * FROM xmltest ORDER BY 1;
@ -265,3 +278,5 @@ SELECT XMLPARSE(DOCUMENT '<!DOCTYPE foo [<!ENTITY c SYSTEM "/etc/passwd">]><foo>
SELECT XMLPARSE(DOCUMENT '<!DOCTYPE foo [<!ENTITY c SYSTEM "/etc/no.such.file">]><foo>&c;</foo>');
-- This might or might not load the requested DTD, but it mustn't throw error.
SELECT XMLPARSE(DOCUMENT '<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"><chapter>&nbsp;</chapter>');
DROP VIEW xmlview4;
DROP TABLE emp;