Skip to content

Commit

Permalink
sqlcmd hangs for select query with null XML values (#1591) (#1719)
Browse files Browse the repository at this point in the history
sqlcmd hangs for select query with null XML values (#1591)

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 NULL values.

Task: BABEL-4196
Signed-off-by: vasavi suthapalli <[email protected]>
  • Loading branch information
1 parent bb8dbbb commit bebb106
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/template/version-branch-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
engine_branch: BABEL_2_4_STABLE__PG_14_7
extension_branch: BABEL_2_4_STABLE
'14.8':
engine_branch: BABEL_2_X_DEV__PG_14_X
extension_branch: BABEL_2_X_DEV
engine_branch: BABEL_2_5_STABLE__PG_14_8
extension_branch: BABEL_2_5_STABLE
'15.2':
engine_branch: BABEL_3_1_STABLE__PG_15_2
extension_branch: BABEL_3_1_STABLE
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/singledb-version-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
env:
OLD_INSTALL_DIR: psql_source
NEW_INSTALL_DIR: psql_target
ENGINE_BRANCH_FROM: BABEL_2_X_DEV__PG_14_X
EXTENSION_BRANCH_FROM: BABEL_2_X_DEV
ENGINE_BRANCH_FROM: BABEL_2_5_STABLE__PG_14_8
EXTENSION_BRANCH_FROM: BABEL_2_5_STABLE

runs-on: ubuntu-20.04
steps:
Expand Down
20 changes: 17 additions & 3 deletions contrib/babelfishpg_tds/src/backend/tds/tdsresponse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:

/*
Expand All @@ -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:

/*
Expand All @@ -2667,7 +2674,7 @@ TdsPrintTup(TupleTableSlot *slot, DestReceiver *self)
}
}

if (nullMapSize < simpleRowSize)
if (nullMapSize <= simpleRowSize)
{
rowToken = TDS_TOKEN_NBCROW;
}
Expand Down Expand Up @@ -2750,7 +2757,6 @@ TdsPrintTup(TupleTableSlot *slot, DestReceiver *self)
break;
case TDS_TYPE_CHAR:
case TDS_TYPE_NCHAR:
case TDS_TYPE_XML:
case TDS_TYPE_BINARY:

/*
Expand All @@ -2759,6 +2765,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:

/*
Expand Down
25 changes: 25 additions & 0 deletions test/JDBC/expected/TestXML.out
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,28 @@ 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'[email protected]', 63,N'<Settings><SubjectTemplateTypeCd>NTF_SUB_INTRA_MSG</SubjectTemplateTypeCd><MessageTemplateTypeCd>NTF_MSG_INTRA_MSG<MessageTemplateTypeCd><VariableRefDomainName>PolicyDocumentTemplateVars<VariableRefDomainName><ProcessDefinitionId>11</ProcessDefinitionId></Settings>', 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#!##!#<NULL>#!#[email protected]#!#<Settings><SubjectTemplateTypeCd>NTF_SUB_INTRA_MSG</SubjectTemplateTypeCd><MessageTemplateTypeCd>NTF_MSG_INTRA_MSG<MessageTemplateTypeCd><VariableRefDomainName>PolicyDocumentTemplateVars<VariableRefDomainName><ProcessDefinitionId>11</ProcessDefinitionId></Settings>#!#1
~~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|-|<Settings><SubjectTemplateTypeCd>NTF_SUB_INTRA_MSG</SubjectTemplateTypeCd><MessageTemplateTypeCd>NTF_MSG_INTRA_MSG</MessageTemplateTypeCd><VariableRefDomainName>PolicyDocumentTemplateVars</VariableRefDomainName><ProcessDefinitionId>11</ProcessDefinitionId></Settings>#!#bigint|-|h|-|1
~~ROW COUNT: 1~~

#INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES (13, N'INTRA_MSG', N'Intra-System Message', NULL, N'[email protected]', 63,N'<Settings><SubjectTemplateTypeCd>NTF_SUB_INTRA_MSG</SubjectTemplateTypeCd><MessageTemplateTypeCd>NTF_MSG_INTRA_MSG<MessageTemplateTypeCd><VariableRefDomainName>PolicyDocumentTemplateVars<VariableRefDomainName><ProcessDefinitionId>11</ProcessDefinitionId></Settings>', 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#!#<Settings><SubjectTemplateTypeCd>NTF_SUB_INTRA_MSG</SubjectTemplateTypeCd><MessageTemplateTypeCd>NTF_MSG_INTRA_MSG</MessageTemplateTypeCd><VariableRefDomainName>PolicyDocumentTemplateVars</VariableRefDomainName><ProcessDefinitionId>11</ProcessDefinitionId></Settings>#!#1
~~END~~

DROP TABLE [dbo].[notification_definition];
13 changes: 12 additions & 1 deletion test/JDBC/input/datatypes/TestXML.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@ INSERT INTO XML_dt values(NULL)
#INSERT INTO XML_dt values('')
INSERT INTO XML_dt values(<contact><name>Contact Name 2</name><phone>YYY-YYY-YYYY</phone>)
SELECT * FROM XML_dt;
DROP TABLE XML_dt;
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'[email protected]', 63,N'<Settings><SubjectTemplateTypeCd>NTF_SUB_INTRA_MSG</SubjectTemplateTypeCd><MessageTemplateTypeCd>NTF_MSG_INTRA_MSG<MessageTemplateTypeCd><VariableRefDomainName>PolicyDocumentTemplateVars<VariableRefDomainName><ProcessDefinitionId>11</ProcessDefinitionId></Settings>', 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|-|<Settings><SubjectTemplateTypeCd>NTF_SUB_INTRA_MSG</SubjectTemplateTypeCd><MessageTemplateTypeCd>NTF_MSG_INTRA_MSG</MessageTemplateTypeCd><VariableRefDomainName>PolicyDocumentTemplateVars</VariableRefDomainName><ProcessDefinitionId>11</ProcessDefinitionId></Settings>#!#bigint|-|h|-|1
#INSERT [dbo].[NOTIFICATION_DEFINITION] VALUES (13, N'INTRA_MSG', N'Intra-System Message', NULL, N'[email protected]', 63,N'<Settings><SubjectTemplateTypeCd>NTF_SUB_INTRA_MSG</SubjectTemplateTypeCd><MessageTemplateTypeCd>NTF_MSG_INTRA_MSG<MessageTemplateTypeCd><VariableRefDomainName>PolicyDocumentTemplateVars<VariableRefDomainName><ProcessDefinitionId>11</ProcessDefinitionId></Settings>', 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];

0 comments on commit bebb106

Please sign in to comment.