Skip to content

Commit

Permalink
fix crash in fn_listextendedproperty (#3238) (#3275)
Browse files Browse the repository at this point in the history
Properly handle nullable column when fetching tuple from sys.babelfish_extended_properties catalog.

Task : BABEL-5087

Signed-off-by: Tanzeel Khan <[email protected]>
  • Loading branch information
tanscorpio7 authored Dec 18, 2024
1 parent cf2e36c commit d08cf7c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion contrib/babelfishpg_tsql/src/extendedproperty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,10 @@ get_extended_property_from_tuple(Relation relation, HeapTuple tuple,
values[2] = datumCopy(datum, false, -1);
datum = heap_getattr(tuple, Anum_bbf_extended_properties_value,
RelationGetDescr(relation), &isnull);
values[3] = datumCopy(datum, false, -1);
if (!isnull)
values[3] = datumCopy(datum, false, -1);
else
nulls[3] = true;

return true;
}
20 changes: 20 additions & 0 deletions test/JDBC/expected/BABEL-EXTENDEDPROPERTY-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ TYPE#!#babel_extended_property_v3_type#!#type property1#!#type property1 before
~~END~~


-- BABEL-5087
EXEC sp_addextendedproperty
@name = N'MS_Description',
@level0type = N'SCHEMA',
@level0name = N'babel_extended_property_v3_schema',
@level1type = N'table',
@level1name = N'babel_extended_property_v3_table';
GO

SELECT * FROM fn_listextendedproperty(NULL, 'SCHEMA', N'babel_extended_property_v3_schema', 'TABLE', N'babel_extended_property_v3_table', NULL, NULL);
GO
~~START~~
varchar#!#varchar#!#varchar#!#sql_variant
TABLE#!#babel_extended_property_v3_table#!#MS_Description#!#<NULL>
TABLE#!#babel_extended_property_v3_table#!#table property1#!#table property1 value
TABLE#!#babel_extended_property_v3_table#!#table property2#!#table property2 value
~~END~~


-- list all extended properties
SELECT class, class_desc, IIF(major_id > 0, 1, 0) AS major_id, minor_id, name, value FROM sys.extended_properties ORDER BY class, class_desc, name, value;
GO
Expand All @@ -81,6 +100,7 @@ tinyint#!#nvarchar#!#int#!#int#!#varchar#!#sql_variant
1#!#OBJECT_OR_COLUMN#!#1#!#1#!#column property1#!#column property1 value
1#!#OBJECT_OR_COLUMN#!#1#!#1#!#COLUMN PROPERTY2 "{\)#!#COLUMN PROPERTY2 VALUE "{\)
1#!#OBJECT_OR_COLUMN#!#1#!#0#!#function property1#!#function property1 value
1#!#OBJECT_OR_COLUMN#!#1#!#0#!#MS_Description#!#<NULL>
1#!#OBJECT_OR_COLUMN#!#1#!#0#!#procedure property1#!#procedure property1 value
1#!#OBJECT_OR_COLUMN#!#1#!#0#!#sequence property1#!#sequence property1 value
1#!#OBJECT_OR_COLUMN#!#1#!#0#!#table property1#!#table property1 value
Expand Down
12 changes: 12 additions & 0 deletions test/JDBC/input/BABEL-EXTENDEDPROPERTY-vu-verify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ GO
SELECT * FROM fn_listextendedproperty(NULL, 'schema', 'babel_extended_property_v3_schema', 'type', NULL, NULL, NULL) ORDER BY objtype, objname, name, value;
GO

-- BABEL-5087
EXEC sp_addextendedproperty
@name = N'MS_Description',
@level0type = N'SCHEMA',
@level0name = N'babel_extended_property_v3_schema',
@level1type = N'table',
@level1name = N'babel_extended_property_v3_table';
GO

SELECT * FROM fn_listextendedproperty(NULL, 'SCHEMA', N'babel_extended_property_v3_schema', 'TABLE', N'babel_extended_property_v3_table', NULL, NULL);
GO

-- list all extended properties
SELECT class, class_desc, IIF(major_id > 0, 1, 0) AS major_id, minor_id, name, value FROM sys.extended_properties ORDER BY class, class_desc, name, value;
GO

0 comments on commit d08cf7c

Please sign in to comment.