Skip to content

Commit 67d1001

Browse files
committed
Transactions are broken when trying to delete only the IsTempObject=1 objects. The build is terribly broken.
1 parent 0c68953 commit 67d1001

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

Source/tSQLt.UndoTestDoubles.ssp.sql

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,28 @@ BEGIN
3737
LL.SchemaName,
3838
LL.CurrentName,
3939
LL.OriginalName,
40-
FakeO.type ObjectType
40+
FakeO.type ObjectType,
41+
CASE WHEN EP.value IS NOT NULL THEN 1 ELSE 0 END IsTempObject
4142
FROM LL
4243
LEFT JOIN sys.objects FakeO
4344
ON FakeO.object_id = OBJECT_ID(QUOTENAME(LL.SchemaName)+'.'+QUOTENAME(LL.OriginalName))
45+
LEFT JOIN sys.extended_properties AS EP
46+
ON EP.class_desc = 'TABLE'
47+
AND EP.major_id = FakeO.object_id
48+
AND EP.name = 'tSQLt.IsTempObject'
49+
AND EP.value = 1
4450
)
4551
SELECT @cmd =
4652
(
4753
SELECT
48-
ISNULL(CASE WHEN L.ParentId IS NULL THEN DC.cmd+';' END,'')+
54+
ISNULL(CASE
55+
WHEN L.ParentId IS NULL THEN
56+
CASE WHEN L.IsTempObject = 1
57+
THEN DC.cmd+';'
58+
ELSE 'RAISERROR(''Cannot drop UndoTestDoublesTests.SimpleTable1 as it isn''''t marked as temporary. Use @Force = 1 to override.'',16,10);'
59+
END
60+
ELSE NULL
61+
END,'')+
4962
'EXEC tSQLt.Private_RenameObject '''+L.SchemaName+''','''+L.CurrentName+''','''+L.OriginalName+''';'
5063
FROM L
5164
CROSS APPLY tSQLt.Private_GetDropItemCmd(QUOTENAME(L.SchemaName)+'.'+QUOTENAME(L.OriginalName),L.ObjectType) DC

Tests/UndoTestDoublesTests.class.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,19 @@ BEGIN
399399
END;
400400
END;
401401
GO
402+
CREATE PROCEDURE UndoTestDoublesTests.[test drops only objects that are marked as temporary (IsTempObject = 1)]
403+
AS
404+
BEGIN
405+
SELECT '1',@@TRANCOUNT,'test drops only objects that are marked as temporary (IsTempObject = 1)'testname
406+
CREATE TABLE UndoTestDoublesTests.SimpleTable1 (i INT);
407+
408+
EXEC tSQLt.RemoveObject @ObjectName = 'UndoTestDoublesTests.SimpleTable1';
409+
CREATE TABLE UndoTestDoublesTests.SimpleTable1 (i INT);
410+
411+
EXEC tSQLt.ExpectException @ExpectedMessage = 'Cannot drop UndoTestDoublesTests.SimpleTable1 as it isn''t marked as temporary. Use @Force = 1 to override.', @ExpectedSeverity = 16, @ExpectedState = 10;
412+
SELECT '2',@@TRANCOUNT
413+
EXEC tSQLt.UndoTestDoubles;
414+
SELECT '3',@@TRANCOUNT
415+
416+
END;
417+
GO

0 commit comments

Comments
 (0)