Skip to content

Commit d6a6f8c

Browse files
committed
Fix contrib/xml2 so regression test still works when it's built without libxslt.
This involves modifying the module to have a stable ABI, that is, the xslt_process() function still exists even without libxslt. It throws a runtime error if called, but doesn't prevent executing the CREATE FUNCTION call. This is a good thing anyway to simplify cross-version upgrades.
1 parent 8373490 commit d6a6f8c

File tree

4 files changed

+135
-13
lines changed

4 files changed

+135
-13
lines changed

contrib/xml2/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# $PostgreSQL: pgsql/contrib/xml2/Makefile,v 1.13 2010/02/28 21:31:57 tgl Exp $
1+
# $PostgreSQL: pgsql/contrib/xml2/Makefile,v 1.14 2010/03/01 18:07:59 tgl Exp $
22

33
MODULE_big = pgxml
44

5-
OBJS = $(if $(filter -lxslt, $(LIBS)), xpath.o xslt_proc.o, xpath.o)
5+
OBJS = xpath.o xslt_proc.o
66

77
SHLIB_LINK += $(filter -lxslt, $(LIBS)) $(filter -lxml2, $(LIBS))
88

contrib/xml2/expected/xml2_1.out

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
--
2+
-- first, define the functions. Turn off echoing so that expected file
3+
-- does not depend on contents of pgxml.sql.
4+
--
5+
SET client_min_messages = warning;
6+
\set ECHO none
7+
RESET client_min_messages;
8+
select query_to_xml('select 1 as x',true,false,'');
9+
query_to_xml
10+
---------------------------------------------------------------
11+
<table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
12+
+
13+
<row> +
14+
<x>1</x> +
15+
</row> +
16+
+
17+
</table> +
18+
19+
(1 row)
20+
21+
select xslt_process( query_to_xml('select x from generate_series(1,5) as
22+
x',true,false,'')::text,
23+
$$<xsl:stylesheet version="1.0"
24+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
25+
<xsl:output method="xml" indent="yes" />
26+
<xsl:template match="*">
27+
<xsl:copy>
28+
<xsl:copy-of select="@*" />
29+
<xsl:apply-templates />
30+
</xsl:copy>
31+
</xsl:template>
32+
<xsl:template match="comment()|processing-instruction()">
33+
<xsl:copy />
34+
</xsl:template>
35+
</xsl:stylesheet>
36+
$$::text);
37+
ERROR: xslt_process() is not available without libxslt
38+
CREATE TABLE xpath_test (id integer NOT NULL, t xml);
39+
INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
40+
SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
41+
as t(id int4);
42+
id
43+
----
44+
(0 rows)
45+
46+
SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
47+
as t(id int4, doc int4);
48+
id | doc
49+
----+-----
50+
1 | 1
51+
(1 row)
52+
53+
DROP TABLE xpath_test;
54+
CREATE TABLE xpath_test (id integer NOT NULL, t text);
55+
INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
56+
SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
57+
as t(id int4);
58+
id
59+
----
60+
(0 rows)
61+
62+
SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
63+
as t(id int4, doc int4);
64+
id | doc
65+
----+-----
66+
1 | 1
67+
(1 row)
68+
69+
create table articles (article_id integer, article_xml xml, date_entered date);
70+
insert into articles (article_id, article_xml, date_entered)
71+
values (2, '<article><author>test</author><pages>37</pages></article>', now());
72+
SELECT * FROM
73+
xpath_table('article_id',
74+
'article_xml',
75+
'articles',
76+
'/article/author|/article/pages|/article/title',
77+
'date_entered > ''2003-01-01'' ')
78+
AS t(article_id integer, author text, page_count integer, title text);
79+
article_id | author | page_count | title
80+
------------+--------+------------+-------
81+
2 | test | 37 |
82+
(1 row)
83+
84+
-- this used to fail when invoked a second time
85+
select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
86+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
87+
<xsl:template match="@*|node()">
88+
<xsl:copy>
89+
<xsl:apply-templates select="@*|node()"/>
90+
</xsl:copy>
91+
</xsl:template>
92+
</xsl:stylesheet>$$)::xml;
93+
ERROR: xslt_process() is not available without libxslt
94+
select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
95+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
96+
<xsl:template match="@*|node()">
97+
<xsl:copy>
98+
<xsl:apply-templates select="@*|node()"/>
99+
</xsl:copy>
100+
</xsl:template>
101+
</xsl:stylesheet>$$)::xml;
102+
ERROR: xslt_process() is not available without libxslt
103+
create table t1 (id integer, xml_data xml);
104+
insert into t1 (id, xml_data)
105+
values
106+
(1, '<attributes><attribute name="attr_1">Some
107+
Value</attribute></attributes>');
108+
create index idx_xpath on t1 ( xpath_string
109+
('/attributes/attribute[@name="attr_1"]/text()', xml_data::text));

contrib/xml2/pgxml.sql.in

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/contrib/xml2/pgxml.sql.in,v 1.11 2007/11/13 04:24:29 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/xml2/pgxml.sql.in,v 1.12 2010/03/01 18:07:59 tgl Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
@@ -40,22 +40,17 @@ CREATE OR REPLACE FUNCTION xpath_list(text,text,text) RETURNS text
4040
AS 'MODULE_PATHNAME'
4141
LANGUAGE C STRICT IMMUTABLE;
4242

43-
4443
CREATE OR REPLACE FUNCTION xpath_list(text,text) RETURNS text
4544
AS 'SELECT xpath_list($1,$2,'','')'
4645
LANGUAGE SQL STRICT IMMUTABLE;
4746

48-
49-
5047
-- Wrapper functions for nodeset where no tags needed
5148

52-
5349
CREATE OR REPLACE FUNCTION xpath_nodeset(text,text)
5450
RETURNS text
5551
AS 'SELECT xpath_nodeset($1,$2,'''','''')'
5652
LANGUAGE SQL STRICT IMMUTABLE;
5753

58-
5954
CREATE OR REPLACE FUNCTION xpath_nodeset(text,text,text)
6055
RETURNS text
6156
AS 'SELECT xpath_nodeset($1,$2,'''',$3)'
@@ -69,17 +64,13 @@ AS 'MODULE_PATHNAME'
6964
LANGUAGE C STRICT STABLE;
7065

7166
-- XSLT functions
72-
-- Delete from here to the end of the file if you are not compiling with
73-
-- XSLT support.
74-
7567

7668
CREATE OR REPLACE FUNCTION xslt_process(text,text,text)
7769
RETURNS text
7870
AS 'MODULE_PATHNAME'
7971
LANGUAGE C STRICT VOLATILE;
8072

8173
-- the function checks for the correct argument count
82-
8374
CREATE OR REPLACE FUNCTION xslt_process(text,text)
8475
RETURNS text
8576
AS 'MODULE_PATHNAME'

contrib/xml2/xslt_proc.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/xml2/xslt_proc.c,v 1.18 2010/03/01 05:16:35 tgl Exp $
2+
* $PostgreSQL: pgsql/contrib/xml2/xslt_proc.c,v 1.19 2010/03/01 18:07:59 tgl Exp $
33
*
44
* XSLT processing functions (requiring libxslt)
55
*
@@ -13,6 +13,8 @@
1313
#include "miscadmin.h"
1414
#include "utils/builtins.h"
1515

16+
#ifdef USE_LIBXSLT
17+
1618
/* libxml includes */
1719

1820
#include <libxml/xpath.h>
@@ -26,11 +28,15 @@
2628
#include <libxslt/transform.h>
2729
#include <libxslt/xsltutils.h>
2830

31+
#endif /* USE_LIBXSLT */
32+
2933

3034
/* externally accessible functions */
3135

3236
Datum xslt_process(PG_FUNCTION_ARGS);
3337

38+
#ifdef USE_LIBXSLT
39+
3440
/* declarations to come from xpath.c */
3541
extern void elog_error(const char *explain, bool force);
3642
extern void pgxml_parser_init(void);
@@ -40,12 +46,16 @@ static void parse_params(const char **params, text *paramstr);
4046

4147
#define MAXPARAMS 20 /* must be even, see parse_params() */
4248

49+
#endif /* USE_LIBXSLT */
50+
4351

4452
PG_FUNCTION_INFO_V1(xslt_process);
4553

4654
Datum
4755
xslt_process(PG_FUNCTION_ARGS)
4856
{
57+
#ifdef USE_LIBXSLT
58+
4959
text *doct = PG_GETARG_TEXT_P(0);
5060
text *ssheet = PG_GETARG_TEXT_P(1);
5161
text *paramstr;
@@ -123,8 +133,18 @@ xslt_process(PG_FUNCTION_ARGS)
123133
PG_RETURN_NULL();
124134

125135
PG_RETURN_TEXT_P(cstring_to_text_with_len((char *) resstr, reslen));
136+
137+
#else /* !USE_LIBXSLT */
138+
139+
ereport(ERROR,
140+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
141+
errmsg("xslt_process() is not available without libxslt")));
142+
PG_RETURN_NULL();
143+
144+
#endif /* USE_LIBXSLT */
126145
}
127146

147+
#ifdef USE_LIBXSLT
128148

129149
static void
130150
parse_params(const char **params, text *paramstr)
@@ -173,3 +193,5 @@ parse_params(const char **params, text *paramstr)
173193

174194
params[i] = NULL;
175195
}
196+
197+
#endif /* USE_LIBXSLT */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy