From 41dfbfb7f88de5239a761fbe9191a637e13071b7 Mon Sep 17 00:00:00 2001 From: vasavi suthapalli Date: Tue, 4 Jul 2023 10:25:43 +0000 Subject: [PATCH 1/3] sqlcmd hangs for select query with XML colums Previously the sqlcmd hangs for select query which has XML columns. This commit fixes by sending NbcRowToken when nullMapSize is equal to simpleRowSize. And for older clients of TDS 7.2 where NbcRowToken doesn't exist should send 0xffffffffffffffff specially for XML. Task: BABEL-4196 Signed-off-by: vasavi suthapalli --- contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c index 2e63fd539b..db238153bd 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c @@ -2667,7 +2667,7 @@ TdsPrintTup(TupleTableSlot *slot, DestReceiver *self) } } - if (nullMapSize < simpleRowSize) + if (nullMapSize <= simpleRowSize) { rowToken = TDS_TOKEN_NBCROW; } @@ -2750,7 +2750,6 @@ TdsPrintTup(TupleTableSlot *slot, DestReceiver *self) break; case TDS_TYPE_CHAR: case TDS_TYPE_NCHAR: - case TDS_TYPE_XML: case TDS_TYPE_BINARY: /* @@ -2759,6 +2758,14 @@ TdsPrintTup(TupleTableSlot *slot, DestReceiver *self) */ TdsPutInt16LE(0xffff); break; + case TDS_TYPE_XML: + + /* + * In case of TDS version lower than or equal to 7.3A, + * we need to send 0xffffffffffffffff (PLP_NULL) + */ + TdsPutUInt64LE(0xffffffffffffffff); + break; case TDS_TYPE_SQLVARIANT: /* From b7a42b6a2433b4e8474fc5e7c4c18df233b07805 Mon Sep 17 00:00:00 2001 From: vasavi suthapalli Date: Wed, 5 Jul 2023 09:28:37 +0000 Subject: [PATCH 2/3] Modified the simpleRowSize for type_xml and add tests for it --- .../babelfishpg_tds/src/backend/tds/tdsresponse.c | 9 ++++++++- test/JDBC/expected/TestXML.out | 12 ++++++++++++ test/JDBC/input/datatypes/TestXML.txt | 7 ++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c index db238153bd..d5ea9eebbc 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c @@ -2637,7 +2637,6 @@ TdsPrintTup(TupleTableSlot *slot, DestReceiver *self) break; case TDS_TYPE_CHAR: case TDS_TYPE_NCHAR: - case TDS_TYPE_XML: case TDS_TYPE_BINARY: /* @@ -2646,6 +2645,14 @@ TdsPrintTup(TupleTableSlot *slot, DestReceiver *self) */ simpleRowSize += 2; break; + case TDS_TYPE_XML: + /* + * To send NULL,we have to + * indicate it using 0xffffffffffffffff + * (PLP_NULL) + */ + simpleRowSize += 8; + break; case TDS_TYPE_SQLVARIANT: /* diff --git a/test/JDBC/expected/TestXML.out b/test/JDBC/expected/TestXML.out index dc7168f245..14ce736b2b 100644 --- a/test/JDBC/expected/TestXML.out +++ b/test/JDBC/expected/TestXML.out @@ -27,3 +27,15 @@ xml ~~END~~ DROP TABLE XML_dt; + +CREATE TABLE [dbo].[notification_definition]([id] [bigint] NOT NULL,[name_tx] [nvarchar](200) NOT NULL,[description_tx] [nvarchar](max) NULL,[schedule_xml] [xml] NULL,[default_sender_tx] [nvarchar](200) NULL,[lock_id] [tinyint] NOT NULL,[settings_xml] [xml] NULL,[agency_id] [bigint] NULL) +INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES (13, N'INTRA_MSG', N'Intra-System Message', NULL, N'donotreply_OPMQA@ospreycompliancesuite.com', 63,N'NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11', 1) +~~ROW COUNT: 1~~ + +SELECT ID,NAME_TX,LOCK_ID,DESCRIPTION_TX,N'' as emptystring, SCHEDULE_XML,DEFAULT_SENDER_TX,SETTINGS_XML,AGENCY_ID FROM NOTIFICATION_DEFINITION +~~START~~ +bigint#!#nvarchar#!#tinyint#!#nvarchar#!#nvarchar#!#xml#!#nvarchar#!#xml#!#bigint +13#!#INTRA_MSG#!#63#!#Intra-System Message#!##!##!#donotreply_OPMQA@ospreycompliancesuite.com#!#NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11#!#1 +~~END~~ + +DROP TABLE [dbo].[notification_definition]; diff --git a/test/JDBC/input/datatypes/TestXML.txt b/test/JDBC/input/datatypes/TestXML.txt index 11b9ac8e13..bcc44aa28b 100644 --- a/test/JDBC/input/datatypes/TestXML.txt +++ b/test/JDBC/input/datatypes/TestXML.txt @@ -8,4 +8,9 @@ INSERT INTO XML_dt values(NULL) #INSERT INTO XML_dt values('') INSERT INTO XML_dt values(Contact Name 2YYY-YYY-YYYY) SELECT * FROM XML_dt; -DROP TABLE XML_dt; \ No newline at end of file +DROP TABLE XML_dt; + +CREATE TABLE [dbo].[notification_definition]([id] [bigint] NOT NULL,[name_tx] [nvarchar](200) NOT NULL,[description_tx] [nvarchar](max) NULL,[schedule_xml] [xml] NULL,[default_sender_tx] [nvarchar](200) NULL,[lock_id] [tinyint] NOT NULL,[settings_xml] [xml] NULL,[agency_id] [bigint] NULL) +INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES (13, N'INTRA_MSG', N'Intra-System Message', NULL, N'donotreply_OPMQA@ospreycompliancesuite.com', 63,N'NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11', 1) +SELECT ID,NAME_TX,LOCK_ID,DESCRIPTION_TX,N'' as emptystring, SCHEDULE_XML,DEFAULT_SENDER_TX,SETTINGS_XML,AGENCY_ID FROM NOTIFICATION_DEFINITION +DROP TABLE [dbo].[notification_definition]; From c87fcce8617fd871fc07bd72a17b5dc8b47aeea6 Mon Sep 17 00:00:00 2001 From: vasavi suthapalli Date: Mon, 10 Jul 2023 06:29:04 +0000 Subject: [PATCH 3/3] Added test to insert NULL through prep-exec --- test/JDBC/expected/TestXML.out | 13 +++++++++++++ test/JDBC/input/datatypes/TestXML.txt | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/test/JDBC/expected/TestXML.out b/test/JDBC/expected/TestXML.out index 14ce736b2b..1c68f4a9b0 100644 --- a/test/JDBC/expected/TestXML.out +++ b/test/JDBC/expected/TestXML.out @@ -39,3 +39,16 @@ bigint#!#nvarchar#!#tinyint#!#nvarchar#!#nvarchar#!#xml#!#nvarchar#!#xml#!#bigin ~~END~~ DROP TABLE [dbo].[notification_definition]; + +CREATE TABLE [dbo].[notification_definition]([id] [bigint] NOT NULL,[name_tx] [nvarchar](200) NOT NULL,[description_tx] [nvarchar](max) NULL,[schedule_xml] [xml] NULL,[default_sender_tx] [nvarchar](200) NULL,[lock_id] [tinyint] NOT NULL,[settings_xml] [xml] NULL,[agency_id] [bigint] NULL) +prepst#!# INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES(?, ?, ?, ?, ?, ?, ?, ?) #!#bigint|-|a|-|13#!#nvarchar|-|b|-|INTRA_MSG#!#nvarchar|-|c|-|Intra-System Message#!#XML|-|d|-|NULL#!#nvarchar|-|e|-|donotreply_OPMQA#!#tinyint|-|f|-|63#!#XML|-|g|-|NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11#!#bigint|-|h|-|1 +~~ROW COUNT: 1~~ + +#INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES (13, N'INTRA_MSG', N'Intra-System Message', NULL, N'donotreply_OPMQA@ospreycompliancesuite.com', 63,N'NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11', 1) +SELECT ID,NAME_TX,LOCK_ID,DESCRIPTION_TX,N'' as emptystring, SCHEDULE_XML,DEFAULT_SENDER_TX,SETTINGS_XML,AGENCY_ID FROM NOTIFICATION_DEFINITION +~~START~~ +bigint#!#nvarchar#!#tinyint#!#nvarchar#!#nvarchar#!#xml#!#nvarchar#!#xml#!#bigint +13#!#INTRA_MSG#!#63#!#Intra-System Message#!##!#NULL#!#donotreply_OPMQA#!#NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11#!#1 +~~END~~ + +DROP TABLE [dbo].[notification_definition]; diff --git a/test/JDBC/input/datatypes/TestXML.txt b/test/JDBC/input/datatypes/TestXML.txt index bcc44aa28b..89898fee9a 100644 --- a/test/JDBC/input/datatypes/TestXML.txt +++ b/test/JDBC/input/datatypes/TestXML.txt @@ -14,3 +14,9 @@ CREATE TABLE [dbo].[notification_definition]([id] [bigint] NOT NULL,[name_tx] [n INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES (13, N'INTRA_MSG', N'Intra-System Message', NULL, N'donotreply_OPMQA@ospreycompliancesuite.com', 63,N'NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11', 1) SELECT ID,NAME_TX,LOCK_ID,DESCRIPTION_TX,N'' as emptystring, SCHEDULE_XML,DEFAULT_SENDER_TX,SETTINGS_XML,AGENCY_ID FROM NOTIFICATION_DEFINITION DROP TABLE [dbo].[notification_definition]; + +CREATE TABLE [dbo].[notification_definition]([id] [bigint] NOT NULL,[name_tx] [nvarchar](200) NOT NULL,[description_tx] [nvarchar](max) NULL,[schedule_xml] [xml] NULL,[default_sender_tx] [nvarchar](200) NULL,[lock_id] [tinyint] NOT NULL,[settings_xml] [xml] NULL,[agency_id] [bigint] NULL) +prepst#!# INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES(@a, @b, @c, @d, @e, @f, @g, @h) #!#bigint|-|a|-|13#!#nvarchar|-|b|-|INTRA_MSG#!#nvarchar|-|c|-|Intra-System Message#!#XML|-|d|-|NULL#!#nvarchar|-|e|-|donotreply_OPMQA#!#tinyint|-|f|-|63#!#XML|-|g|-|NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11#!#bigint|-|h|-|1 +#INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES (13, N'INTRA_MSG', N'Intra-System Message', NULL, N'donotreply_OPMQA@ospreycompliancesuite.com', 63,N'NTF_SUB_INTRA_MSGNTF_MSG_INTRA_MSGPolicyDocumentTemplateVars11', 1) +SELECT ID,NAME_TX,LOCK_ID,DESCRIPTION_TX,N'' as emptystring, SCHEDULE_XML,DEFAULT_SENDER_TX,SETTINGS_XML,AGENCY_ID FROM NOTIFICATION_DEFINITION +DROP TABLE [dbo].[notification_definition];