Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] sp_xml_preparedocument #3460

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions contrib/babelfishpg_tsql/sql/sys_procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,38 @@ GRANT EXECUTE on PROCEDURE sys.sp_enum_oledb_providers() TO PUBLIC;
CREATE OR REPLACE PROCEDURE sys.sp_reset_connection()
AS 'babelfishpg_tsql', 'sp_reset_connection_internal' LANGUAGE C;
GRANT EXECUTE ON PROCEDURE sys.sp_reset_connection() TO PUBLIC;

CREATE OR REPLACE PROCEDURE sys.sp_xml_preparedocument(
INOUT hdoc INTEGER,
IN xmltext VARCHAR(8000) DEFAULT NULL,
IN xpath_namespaces VARCHAR(8000) DEFAULT NULL
)
AS $$
DECLARE
xml_data XML;
ns_data XML;
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS SessionXMLDocuments (
Handle INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
Xml_content XML,
NamespaceDefinitions XML
) ON COMMIT PRESERVE ROWS;

IF xmltext IS NULL OR length(xmltext)=0 OR xml_is_well_formed_document(xmltext) THEN
xml_data := xmltext::XML;
ELSE
RAISE EXCEPTION 'The XML input is not well-formed.';
END IF;

IF xpath_namespaces IS NULL OR length(xmltext)=0 OR xml_is_well_formed_document(xpath_namespaces) THEN
ns_data := xpath_namespaces::XML;
ELSE
RAISE EXCEPTION 'The XPath namespace declarations are not well-formed.';
END IF;

INSERT INTO SessionXMLDocuments (Xml_content, NamespaceDefinitions)
VALUES (xml_data, ns_data)
RETURNING Handle INTO hdoc;
END;
$$
LANGUAGE plpgsql;
Loading