Skip to content

Commit 5fca51c

Browse files
committed
Clean up from Pull Request Review
1 parent 8b181cc commit 5fca51c

File tree

4 files changed

+52
-121
lines changed

4 files changed

+52
-121
lines changed

Build/CreateDropClassStatement.ps1

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -41,70 +41,13 @@ $DropClassStatement = ($RawDropClassStatement.trim()|Where-Object {$_ -ne "" -an
4141

4242
Set-Content -Path $OutputFilePath -Value $DropClassStatement;
4343

44-
<#
45-
TODO --> Test this: Empty File TempDropClass.sql file should throw an error
46-
TODO --> Test this: If the $tempPath does not exist, BuildHelper.exe seems to currently throw an error, but does that stop the build?
47-
TODO --> Test this: If the $sourcePath does not exist, BuildHelper.exe seems to currently throw an error, but does that stop the build?
48-
#>
49-
50-
<#
51-
# Read file and remove all empty lines
52-
$fileContent = (Get-Content -path ($tempPath+"TempDropClass.sql")).trim() | Where-Object {$_ -ne "" -and $_ -notmatch "^GO(\s.*)?"};
53-
54-
# Make sure that the file is not empty
55-
if($fileContent.length -eq 0) {
56-
throw "Length of fileContent is zero";
57-
}
58-
59-
# trim lines and jam them all together with a space in between
60-
$singleLineContent = $fileContent -join " ";
61-
62-
<replaceregexp match="^.*?BEGIN" replace="---Build+${line.separator}DECLARE @ClassName NVARCHAR(MAX) ='tSQLt';BEGIN" flags="gm" byline="false" file="temp/tSQLtBuild/TempDropClass.sql" />
63-
64-
#>
65-
66-
<#
67-
if ($LoginTrimmed -match '((.*[-]U)|(.*[-]P))+.*'){
68-
$AuthenticationString = $LoginTrimmed -replace '^((\s*([-]U\s+)(?<user>\w+)\s*)|(\s*([-]P\s+)(?<password>\S+)\s*))+$', 'User Id=${user};Password="${password}"'
69-
}
70-
#>
71-
72-
<# We need to replace this target with a exec target which calls a ps1 to do this work.
73-
In addition, we will add a replace which will "in line" the relevant text of tSQLt.Private_GetDropItemCmd.
74-
75-
"suggested (◔_◔)" regex: tSQLt.Private_GetDropItemCmd(Ds.FullName, Ds.ItemType)
76-
'tSQLt\s*.\s*Private_GetDropItemCmd\s*\(\s*([^,]*)\s*,\s*([^)]*)\s*\)'
77-
78-
It should look like this:
79-
80-
81-
82-
DECLARE @ClassName NVARCHAR(MAX) ='tSQLt';BEGIN DECLARE @Cmd NVARCHAR(MAX); WITH ObjectInfo(FullName, ItemType) AS ( SELECT QUOTENAME(SCHEMA_NAME(O.schema_id))+'.'+QUOTENAME(O.name), O.type FROM sys.objects AS O WHERE O.schema_id = SCHEMA_ID(@ClassName) ), TypeInfo(FullName, ItemType) AS ( SELECT QUOTENAME(SCHEMA_NAME(T.schema_id))+'.'+QUOTENAME(T.name), 'type' FROM sys.types AS T WHERE T.schema_id = SCHEMA_ID(@ClassName) ), XMLSchemaInfo(FullName, ItemType) AS ( SELECT QUOTENAME(SCHEMA_NAME(XSC.schema_id))+'.'+QUOTENAME(XSC.name), 'xml_schema_collections' FROM sys.xml_schema_collections AS XSC WHERE XSC.schema_id = SCHEMA_ID(@ClassName) ), SchemaInfo(FullName, ItemType) AS ( SELECT QUOTENAME(S.name), 'schema' FROM sys.schemas AS S WHERE S.schema_id = SCHEMA_ID(PARSENAME(@ClassName,1)) ), DropStatements(no,FullName,ItemType) AS ( SELECT 10, FullName, ItemType FROM ObjectInfo UNION ALL SELECT 20, FullName, ItemType FROM TypeInfo UNION ALL SELECT 30, FullName, ItemType FROM XMLSchemaInfo UNION ALL SELECT 10000, FullName, ItemType FROM SchemaInfo ), StatementBlob(xml)AS ( SELECT GDIC.cmd [text()] FROM DropStatements DS CROSS APPLY
83-
(
84-
SELECT
85-
'DROP ' +
86-
CASE @ItemType
87-
WHEN 'P' THEN 'PROCEDURE'
88-
WHEN 'PC' THEN 'PROCEDURE'
89-
WHEN 'U' THEN 'TABLE'
90-
WHEN 'IF' THEN 'FUNCTION'
91-
WHEN 'TF' THEN 'FUNCTION'
92-
WHEN 'FN' THEN 'FUNCTION'
93-
WHEN 'FT' THEN 'FUNCTION'
94-
WHEN 'V' THEN 'VIEW'
95-
WHEN 'type' THEN 'TYPE'
96-
WHEN 'xml_schema_collection' THEN 'XML SCHEMA COLLECTION'
97-
WHEN 'schema' THEN 'SCHEMA'
98-
END+
99-
' ' +
100-
@FullName +
101-
';' AS cmd
102-
)
103-
GDIC ORDER BY no FOR XML PATH(''), TYPE ) SELECT @Cmd = xml.value('/', 'NVARCHAR(MAX)') FROM StatementBlob; EXEC(@Cmd); END;
104-
105-
#>
106-
10744
Log-Output '<#--=======================================================================-->'
10845
Log-Output '<!--======== End CreateDropClassStatement.ps1 =========-->'
10946
Log-Output '<#--=======================================================================-->'
110-
47+
48+
49+
<# TODO
50+
--> Test this: Empty File TempDropClass.sql file should throw an error
51+
--> Test this: If the $tempPath does not exist, BuildHelper.exe seems to currently throw an error, but does that stop the build?
52+
--> Test this: If the $sourcePath does not exist, BuildHelper.exe seems to currently throw an error, but does that stop the build?
53+
#>

Source/tSQLt.Private_GetDropItemCmd.sfn.sql

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,46 @@ SELECT
3333
@FullName +
3434
';' AS cmd
3535
/*SnipEnd: CreateDropClassStatement.ps1*/
36-
GO
36+
GO
37+
---Build-
38+
/*
39+
Object type:
40+
AF = Aggregate function (CLR)
41+
- C = CHECK constraint
42+
- D = DEFAULT (constraint or stand-alone)
43+
- F = FOREIGN KEY constraint
44+
+ FN = SQL scalar function
45+
FS = Assembly (CLR) scalar-function
46+
+ FT = Assembly (CLR) table-valued function
47+
+ IF = SQL inline table-valued function
48+
IT = Internal table
49+
+ P = SQL Stored Procedure
50+
+ PC = Assembly (CLR) stored-procedure
51+
- PG = Plan guide
52+
- PK = PRIMARY KEY constraint
53+
? R = Rule (old-style, stand-alone)
54+
RF = Replication-filter-procedure
55+
- S = System base table
56+
SN = Synonym
57+
SO = Sequence object
58+
+ U = Table (user-defined)
59+
+ V = View
60+
- EC = Edge constraint
61+
62+
Applies to: SQL Server 2012 (11.x) and later.
63+
SQ = Service queue
64+
- TA = Assembly (CLR) DML trigger
65+
+ TF = SQL table-valued-function
66+
- TR = SQL DML trigger
67+
TT = Table type
68+
- UQ = UNIQUE constraint
69+
? X = Extended stored procedure
70+
71+
Applies to: SQL Server 2014 (12.x) and later, Azure SQL Database, Azure Synapse Analytics, Analytics Platform System (PDW).
72+
? ST = STATS_TREE
73+
74+
Applies to: SQL Server 2016 (13.x) and later, Azure SQL Database, Azure Synapse Analytics, Analytics Platform System (PDW).
75+
ET = External Table
76+
77+
Also think about schema bound objects (an exercise in sorting?? because they need to be dropped in the correct order so that you don't drop parent objects before the child objects)
78+
*/

Tests/DropClassTests.class.sql

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -129,61 +129,6 @@ CREATE FUNCTION MyTestClass.AClrTvf(@p1 NVARCHAR(MAX), @p2 NVARCHAR(MAX))
129129
END
130130
END;
131131
GO
132-
--CASE type *WHEN 'P' THEN 'PROCEDURE'
133-
-- *WHEN 'PC' THEN 'PROCEDURE'
134-
-- *WHEN 'U' THEN 'TABLE'
135-
-- WHEN 'IF' THEN 'FUNCTION'
136-
-- *WHEN 'TF' THEN 'FUNCTION'
137-
-- WHEN 'FN' THEN 'FUNCTION'
138-
-- *WHEN 'FT' THEN 'FUNCTION'
139-
-- *WHEN 'V' THEN 'VIEW'
140-
-- *XML
141-
-- *UDDT
142-
/*
143-
Object type:
144-
AF = Aggregate function (CLR)
145-
- C = CHECK constraint
146-
- D = DEFAULT (constraint or stand-alone)
147-
- F = FOREIGN KEY constraint
148-
+ FN = SQL scalar function
149-
FS = Assembly (CLR) scalar-function
150-
+ FT = Assembly (CLR) table-valued function
151-
+ IF = SQL inline table-valued function
152-
IT = Internal table
153-
+ P = SQL Stored Procedure
154-
+ PC = Assembly (CLR) stored-procedure
155-
- PG = Plan guide
156-
- PK = PRIMARY KEY constraint
157-
? R = Rule (old-style, stand-alone)
158-
RF = Replication-filter-procedure
159-
- S = System base table
160-
SN = Synonym
161-
SO = Sequence object
162-
+ U = Table (user-defined)
163-
+ V = View
164-
- EC = Edge constraint
165-
166-
Applies to: SQL Server 2012 (11.x) and later.
167-
SQ = Service queue
168-
- TA = Assembly (CLR) DML trigger
169-
+ TF = SQL table-valued-function
170-
- TR = SQL DML trigger
171-
TT = Table type
172-
- UQ = UNIQUE constraint
173-
? X = Extended stored procedure
174-
175-
Applies to: SQL Server 2014 (12.x) and later, Azure SQL Database, Azure Synapse Analytics, Analytics Platform System (PDW).
176-
? ST = STATS_TREE
177-
178-
Applies to: SQL Server 2016 (13.x) and later, Azure SQL Database, Azure Synapse Analytics, Analytics Platform System (PDW).
179-
ET = External Table
180-
181-
Also think about schema bound objects (an exercise in sorting?? because they need to be dropped in the correct order so that you don't drop parent objects before the child objects)
182-
*/
183-
184-
/*-- random line because someone can't use ctrl-9 through zoom
185-
EXEC tSQLt.Run DropClassTests
186-
--*/
187132
CREATE PROC DropClassTests.[test removes SSPs]
188133
AS
189134
BEGIN

Tests/FakeFunctionTests.class.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ BEGIN
661661
EXEC tSQLt.AssertEqualsTable 'FakeFunctionTests.Expected', @NewTable;
662662
END;
663663
GO
664-
-- THIS CODE FEELS UNNECESSARY
664+
-- THIS CODE CREATES THE SNAPSHOT.
665+
-- When we revisit creating something like FakeFunctionWithSnapshot, we should refer back.
665666
-- DECLARE @newTbleName NVARCHAR(MAX);
666667
-- EXEC tSQLt.Private_PrepareFakeFunctionOutputTable @FakeDataSource, @newTbleName OUTPUT;
667668

0 commit comments

Comments
 (0)