Skip to content

Commit 3562c0c

Browse files
author
Harsh Dubey
committed
Added tests for openxml functions
Signed-off-by: Harsh Dubey <[email protected]>
1 parent 4a4a045 commit 3562c0c

File tree

7 files changed

+260
-2
lines changed

7 files changed

+260
-2
lines changed

test/JDBC/expected/openxml_with_clause-vu-cleanup.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ GO
2121

2222
DROP TABLE regions;
2323
GO
24+
25+
DROP VIEW openxml_column_patterns
26+
GO
27+
28+
DROP VIEW openxml_documents
29+
GO

test/JDBC/expected/openxml_with_clause-vu-prepare.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,27 @@ GO
4545

4646
CREATE TABLE regions (region_id INT, region_name VARCHAR(50));
4747
GO
48+
49+
-- View for col pattern generation and xml doc retrieval
50+
CREATE VIEW openxml_column_patterns AS
51+
SELECT
52+
column_name,
53+
flag,
54+
sys.tsql_openxml_get_colpattern(column_name, flag) AS xpath_pattern
55+
FROM (
56+
VALUES
57+
('id', 0), ('id', 1), ('id', 2), ('id', 3),
58+
('name', 0), ('name', 1), ('name', 2), ('name', 3),
59+
('value', 0), ('value', 1), ('value', 2), ('value', 3)
60+
) AS patterns(column_name, flag);
61+
GO
62+
63+
CREATE VIEW openxml_documents AS
64+
SELECT
65+
document_id,
66+
sys.tsql_openxml_get_xmldoc(document_id) AS xml_document
67+
FROM (
68+
SELECT generate_series(1, 100) AS document_id
69+
) AS doc_ids
70+
WHERE sys.tsql_openxml_get_xmldoc(document_id) IS NOT NULL;
71+
GO

test/JDBC/expected/openxml_with_clause-vu-verify.out

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,3 +1504,146 @@ INV001#!#Standard#!#<NULL>#!#<NULL>#!#<NULL>
15041504
INV002#!#Express#!#<NULL>#!#<NULL>#!#<NULL>
15051505
~~END~~
15061506

1507+
1508+
-- Tests for tsql_openxml_get_colpattern and tsql_openxml_get_xmldoc
1509+
-- Test basic flag patterns
1510+
SELECT sys.tsql_openxml_get_colpattern('name', 0);
1511+
GO
1512+
~~START~~
1513+
nvarchar
1514+
@name
1515+
~~END~~
1516+
1517+
1518+
SELECT sys.tsql_openxml_get_colpattern('name', 1);
1519+
GO
1520+
~~START~~
1521+
nvarchar
1522+
@name
1523+
~~END~~
1524+
1525+
1526+
SELECT sys.tsql_openxml_get_colpattern('name', 2);
1527+
GO
1528+
~~START~~
1529+
nvarchar
1530+
name
1531+
~~END~~
1532+
1533+
1534+
SELECT sys.tsql_openxml_get_colpattern('name', 3);
1535+
GO
1536+
~~START~~
1537+
nvarchar
1538+
name|@name
1539+
~~END~~
1540+
1541+
1542+
-- Test flag normalization (mod 4)
1543+
SELECT sys.tsql_openxml_get_colpattern('id', 4)
1544+
GO
1545+
~~START~~
1546+
nvarchar
1547+
@id
1548+
~~END~~
1549+
1550+
1551+
SELECT sys.tsql_openxml_get_colpattern('id', 5);
1552+
GO
1553+
~~START~~
1554+
nvarchar
1555+
@id
1556+
~~END~~
1557+
1558+
1559+
SELECT sys.tsql_openxml_get_colpattern('id', 6);
1560+
GO
1561+
~~START~~
1562+
nvarchar
1563+
id
1564+
~~END~~
1565+
1566+
1567+
SELECT sys.tsql_openxml_get_colpattern('id', 7);
1568+
GO
1569+
~~START~~
1570+
nvarchar
1571+
id|@id
1572+
~~END~~
1573+
1574+
1575+
-- Test error and null cases
1576+
SELECT sys.tsql_openxml_get_colpattern(NULL, 1);
1577+
GO
1578+
~~START~~
1579+
nvarchar
1580+
<NULL>
1581+
~~END~~
1582+
1583+
1584+
SELECT sys.tsql_openxml_get_colpattern('', 1);
1585+
GO
1586+
~~START~~
1587+
nvarchar
1588+
~~ERROR (Code: 33557097)~~
1589+
1590+
~~ERROR (Message: Column name cannot be empty for OPENXML)~~
1591+
1592+
1593+
SELECT sys.tsql_openxml_get_colpattern('name', -1);
1594+
GO
1595+
~~START~~
1596+
nvarchar
1597+
~~ERROR (Code: 33557097)~~
1598+
1599+
~~ERROR (Message: Invalid flag value -1 for OPENXML)~~
1600+
1601+
1602+
-- Test with valid document handle
1603+
DECLARE @doc_handle INT;
1604+
EXEC sp_xml_preparedocument @doc_handle OUTPUT, '<root><item>test</item></root>';
1605+
SELECT sys.tsql_openxml_get_xmldoc(@doc_handle);
1606+
EXEC sp_xml_removedocument @doc_handle;
1607+
GO
1608+
~~START~~
1609+
xml
1610+
<root><item>test</item></root>
1611+
~~END~~
1612+
1613+
1614+
-- Test with invalid or NULL handle
1615+
SELECT sys.tsql_openxml_get_xmldoc(999);
1616+
GO
1617+
~~START~~
1618+
xml
1619+
~~ERROR (Code: 33557097)~~
1620+
1621+
~~ERROR (Message: Could not find prepared statement with handle 999.)~~
1622+
1623+
SELECT sys.tsql_openxml_get_xmldoc(NULL);
1624+
GO
1625+
~~START~~
1626+
xml
1627+
<NULL>
1628+
~~END~~
1629+
1630+
1631+
-- Tests for views for col pattern and xml doc generation
1632+
SELECT * FROM openxml_column_patterns WHERE flag = 3;
1633+
GO
1634+
~~START~~
1635+
varchar#!#int#!#nvarchar
1636+
id#!#3#!#id|@id
1637+
name#!#3#!#name|@name
1638+
value#!#3#!#value|@value
1639+
~~END~~
1640+
1641+
1642+
SELECT document_id FROM openxml_documents;
1643+
GO
1644+
~~START~~
1645+
int
1646+
~~ERROR (Code: 33557097)~~
1647+
1648+
~~ERROR (Message: Could not find prepared statement with handle 1.)~~
1649+

test/JDBC/input/xml/openxml_with_clause-vu-cleanup.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ DROP TABLE person_table;
2020
GO
2121

2222
DROP TABLE regions;
23+
GO
24+
25+
DROP VIEW openxml_column_patterns
26+
GO
27+
28+
DROP VIEW openxml_documents
2329
GO

test/JDBC/input/xml/openxml_with_clause-vu-prepare.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,27 @@ GO
4545

4646
CREATE TABLE regions (region_id INT, region_name VARCHAR(50));
4747
GO
48+
49+
-- View for col pattern generation and xml doc retrieval
50+
CREATE VIEW openxml_column_patterns AS
51+
SELECT
52+
column_name,
53+
flag,
54+
sys.tsql_openxml_get_colpattern(column_name, flag) AS xpath_pattern
55+
FROM (
56+
VALUES
57+
('id', 0), ('id', 1), ('id', 2), ('id', 3),
58+
('name', 0), ('name', 1), ('name', 2), ('name', 3),
59+
('value', 0), ('value', 1), ('value', 2), ('value', 3)
60+
) AS patterns(column_name, flag);
61+
GO
62+
63+
CREATE VIEW openxml_documents AS
64+
SELECT
65+
document_id,
66+
sys.tsql_openxml_get_xmldoc(document_id) AS xml_document
67+
FROM (
68+
SELECT generate_series(1, 100) AS document_id
69+
) AS doc_ids
70+
WHERE sys.tsql_openxml_get_xmldoc(document_id) IS NOT NULL;
71+
GO

test/JDBC/input/xml/openxml_with_clause-vu-verify.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,4 +1220,61 @@ WITH (
12201220
);
12211221

12221222
EXEC sp_xml_removedocument @handle;
1223+
GO
1224+
1225+
-- Tests for tsql_openxml_get_colpattern and tsql_openxml_get_xmldoc
1226+
-- Test basic flag patterns
1227+
SELECT sys.tsql_openxml_get_colpattern('name', 0);
1228+
GO
1229+
1230+
SELECT sys.tsql_openxml_get_colpattern('name', 1);
1231+
GO
1232+
1233+
SELECT sys.tsql_openxml_get_colpattern('name', 2);
1234+
GO
1235+
1236+
SELECT sys.tsql_openxml_get_colpattern('name', 3);
1237+
GO
1238+
1239+
-- Test flag normalization (mod 4)
1240+
SELECT sys.tsql_openxml_get_colpattern('id', 4)
1241+
GO
1242+
1243+
SELECT sys.tsql_openxml_get_colpattern('id', 5);
1244+
GO
1245+
1246+
SELECT sys.tsql_openxml_get_colpattern('id', 6);
1247+
GO
1248+
1249+
SELECT sys.tsql_openxml_get_colpattern('id', 7);
1250+
GO
1251+
1252+
-- Test error and null cases
1253+
SELECT sys.tsql_openxml_get_colpattern(NULL, 1);
1254+
GO
1255+
1256+
SELECT sys.tsql_openxml_get_colpattern('', 1);
1257+
GO
1258+
1259+
SELECT sys.tsql_openxml_get_colpattern('name', -1);
1260+
GO
1261+
1262+
-- Test with valid document handle
1263+
DECLARE @doc_handle INT;
1264+
EXEC sp_xml_preparedocument @doc_handle OUTPUT, '<root><item>test</item></root>';
1265+
SELECT sys.tsql_openxml_get_xmldoc(@doc_handle);
1266+
EXEC sp_xml_removedocument @doc_handle;
1267+
GO
1268+
1269+
-- Test with invalid or NULL handle
1270+
SELECT sys.tsql_openxml_get_xmldoc(999);
1271+
GO
1272+
SELECT sys.tsql_openxml_get_xmldoc(NULL);
1273+
GO
1274+
1275+
-- Tests for views for col pattern and xml doc generation
1276+
SELECT * FROM openxml_column_patterns WHERE flag = 3;
1277+
GO
1278+
1279+
SELECT document_id FROM openxml_documents;
12231280
GO

test/python/expected/upgrade_validation/expected_dependency.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,6 @@ Function sys.tsql_get_constraintdef(oid)
714714
Function sys.tsql_get_expr(text,oid)
715715
Function sys.tsql_get_functiondef(oid)
716716
Function sys.tsql_get_returntypmodvalue(oid)
717-
Function sys.tsql_openxml_get_colpattern(text,integer)
718-
Function sys.tsql_openxml_get_xmldoc(integer)
719717
Function sys.tsql_query_to_json_ffunc(internal)
720718
Function sys.tsql_query_to_json_sfunc(internal,anyelement,integer,boolean,boolean,text)
721719
Function sys.tsql_query_to_xml_ffunc(internal)

0 commit comments

Comments
 (0)