Skip to content

Commit e8b515b

Browse files
committed
SET ANSI_NULLS OFF / SET QUOTED_IDENTIFIER OFF not filtered
The fix adds "SET ANSI_NULLS OFF" and "SET QUOTED_IDENTIFIER OFF" to the IsSet filter in SqlScriptBuilder.cs:208-213. The new SchemaAnsiNullsOff test creates a proc with both settings OFF and verifies they don't appear in the snapshot output.
1 parent 211e103 commit e8b515b

10 files changed

Lines changed: 114 additions & 15 deletions

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This test:
5050
```cs
5151
await Verify(connection);
5252
```
53-
<sup><a href='/src/Tests/Tests.cs#L300-L304' title='Snippet source file'>snippet source</a> | <a href='#snippet-SqlServerSchema' title='Start of snippet'>anchor</a></sup>
53+
<sup><a href='/src/Tests/Tests.cs#L317-L321' title='Snippet source file'>snippet source</a> | <a href='#snippet-SqlServerSchema' title='Start of snippet'>anchor</a></sup>
5454
<!-- endSnippet -->
5555

5656
Will result in the following verified file:
@@ -69,7 +69,7 @@ await Verify(connection)
6969
// include only tables and views
7070
.SchemaIncludes(DbObjects.Tables | DbObjects.Views);
7171
```
72-
<sup><a href='/src/Tests/Tests.cs#L666-L672' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaInclude' title='Start of snippet'>anchor</a></sup>
72+
<sup><a href='/src/Tests/Tests.cs#L683-L689' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaInclude' title='Start of snippet'>anchor</a></sup>
7373
<!-- endSnippet -->
7474

7575
Available values:
@@ -107,7 +107,7 @@ await Verify(connection)
107107
_ => _ is TableViewBase ||
108108
_.Name == "MyTrigger");
109109
```
110-
<sup><a href='/src/Tests/Tests.cs#L691-L699' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
110+
<sup><a href='/src/Tests/Tests.cs#L708-L716' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
111111
<!-- endSnippet -->
112112

113113

@@ -129,7 +129,7 @@ command.CommandText = "select Value from MyTable";
129129
var value = await command.ExecuteScalarAsync();
130130
await Verify(value!);
131131
```
132-
<sup><a href='/src/Tests/Tests.cs#L475-L485' title='Snippet source file'>snippet source</a> | <a href='#snippet-Recording' title='Start of snippet'>anchor</a></sup>
132+
<sup><a href='/src/Tests/Tests.cs#L492-L502' title='Snippet source file'>snippet source</a> | <a href='#snippet-Recording' title='Start of snippet'>anchor</a></sup>
133133
<!-- endSnippet -->
134134

135135
Will result in the following verified file:
@@ -184,7 +184,7 @@ await Verify(
184184
sqlEntries = entries
185185
});
186186
```
187-
<sup><a href='/src/Tests/Tests.cs#L552-L582' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
187+
<sup><a href='/src/Tests/Tests.cs#L569-L599' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
188188
<!-- endSnippet -->
189189

190190

@@ -212,7 +212,7 @@ var sqlErrorsViaType = entries
212212
.Select(_ => _.Data)
213213
.OfType<ErrorEntry>();
214214
```
215-
<sup><a href='/src/Tests/Tests.cs#L608-L627' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
215+
<sup><a href='/src/Tests/Tests.cs#L625-L644' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
216216
<!-- endSnippet -->
217217

218218

src/Tests/Tests.Schema.verified.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Tables
1+
## Tables
22

33
### ChildTable
44

@@ -281,6 +281,16 @@ BEGIN
281281
END;
282282
```
283283

284+
### ProcWithAnsiNullsOff
285+
286+
```sql
287+
CREATE PROCEDURE ProcWithAnsiNullsOff
288+
AS
289+
BEGIN
290+
SELECT Value FROM MyTable;
291+
END;
292+
```
293+
284294
### ProcWithParams
285295

286296
```sql
@@ -390,4 +400,4 @@ CREATE SYNONYM [dbo].[synonym2] FOR [ParentTable]
390400

391401
```sql
392402
CREATE SYNONYM [TestSchema].[SchemaSynonym] FOR [TestSchema].[SchemaTable]
393-
```
403+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## StoredProcedures
2+
3+
### ProcWithAnsiNullsOff
4+
5+
```sql
6+
CREATE PROCEDURE ProcWithAnsiNullsOff
7+
AS
8+
BEGIN
9+
SELECT Value FROM MyTable;
10+
END;
11+
```

src/Tests/Tests.SchemaAsMarkdown.verified.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Tables
1+
## Tables
22

33
### ChildTable
44

@@ -281,6 +281,16 @@ BEGIN
281281
END;
282282
```
283283

284+
### ProcWithAnsiNullsOff
285+
286+
```sql
287+
CREATE PROCEDURE ProcWithAnsiNullsOff
288+
AS
289+
BEGIN
290+
SELECT Value FROM MyTable;
291+
END;
292+
```
293+
284294
### ProcWithParams
285295

286296
```sql
@@ -390,4 +400,4 @@ CREATE SYNONYM [dbo].[synonym2] FOR [ParentTable]
390400

391401
```sql
392402
CREATE SYNONYM [TestSchema].[SchemaSynonym] FOR [TestSchema].[SchemaTable]
393-
```
403+
```

src/Tests/Tests.SchemaAsSql.verified.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ BEGIN
217217
WHERE (Value > 10);
218218
END;
219219

220+
CREATE PROCEDURE ProcWithAnsiNullsOff
221+
AS
222+
BEGIN
223+
SELECT Value FROM MyTable;
224+
END;
225+
220226
CREATE PROCEDURE ProcWithParams
221227
@Id int,
222228
@Name nvarchar(100),

src/Tests/Tests.SchemaInDynamic.verified.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ BEGIN
283283
END;
284284
```
285285

286+
### ProcWithAnsiNullsOff
287+
288+
```sql
289+
CREATE PROCEDURE ProcWithAnsiNullsOff
290+
AS
291+
BEGIN
292+
SELECT Value FROM MyTable;
293+
END;
294+
```
295+
286296
### ProcWithParams
287297

288298
```sql

src/Tests/Tests.SchemaIncludeAll.verified.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Tables
1+
## Tables
22

33
### ChildTable
44

@@ -281,6 +281,16 @@ BEGIN
281281
END;
282282
```
283283

284+
### ProcWithAnsiNullsOff
285+
286+
```sql
287+
CREATE PROCEDURE ProcWithAnsiNullsOff
288+
AS
289+
BEGIN
290+
SELECT Value FROM MyTable;
291+
END;
292+
```
293+
284294
### ProcWithParams
285295

286296
```sql
@@ -390,4 +400,4 @@ CREATE SYNONYM [dbo].[synonym2] FOR [ParentTable]
390400

391401
```sql
392402
CREATE SYNONYM [TestSchema].[SchemaSynonym] FOR [TestSchema].[SchemaTable]
393-
```
403+
```

src/Tests/Tests.SchemaIncludeStoredProceduresOnly.verified.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## StoredProcedures
1+
## StoredProcedures
22

33
### MyProcedure
44

@@ -13,6 +13,16 @@ BEGIN
1313
END;
1414
```
1515

16+
### ProcWithAnsiNullsOff
17+
18+
```sql
19+
CREATE PROCEDURE ProcWithAnsiNullsOff
20+
AS
21+
BEGIN
22+
SELECT Value FROM MyTable;
23+
END;
24+
```
25+
1626
### ProcWithParams
1727

1828
```sql
@@ -38,4 +48,4 @@ BEGIN
3848
SELECT Id, Name
3949
FROM TestSchema.SchemaTable;
4050
END;
41-
```
51+
```

src/Tests/Tests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,23 @@ FROM TestSchema.SchemaTable
287287
288288
create synonym TestSchema.SchemaSynonym
289289
for TestSchema.SchemaTable;
290+
GO
291+
292+
SET ANSI_NULLS OFF;
293+
GO
294+
SET QUOTED_IDENTIFIER OFF;
295+
GO
296+
297+
CREATE PROCEDURE ProcWithAnsiNullsOff
298+
AS
299+
BEGIN
300+
SELECT Value FROM MyTable;
301+
END;
302+
GO
303+
304+
SET ANSI_NULLS ON;
305+
GO
306+
SET QUOTED_IDENTIFIER ON;
290307
""");
291308
return Task.CompletedTask;
292309
});
@@ -789,4 +806,17 @@ public async Task SchemaAsMarkdown()
789806
await Verify(connection)
790807
.SchemaAsMarkdown();
791808
}
809+
810+
[Test]
811+
public async Task SchemaAnsiNullsOff()
812+
{
813+
await using var database = await sqlInstance.Build();
814+
var connection = database.Connection;
815+
816+
// ProcWithAnsiNullsOff was created with SET ANSI_NULLS OFF and SET QUOTED_IDENTIFIER OFF.
817+
// Verify the SET statements are stripped from the output.
818+
await Verify(connection)
819+
.SchemaFilter(_ => _.Name == "ProcWithAnsiNullsOff")
820+
.SchemaIncludes(DbObjects.StoredProcedures);
821+
}
792822
}

src/Verify.SqlServer/SchemaValidation/SqlScriptBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,7 @@ static List<string> ScriptLines<T>(ScriptingOptions options, T item)
208208
static bool IsSet(string script) =>
209209
script is
210210
"SET ANSI_NULLS ON" or
211-
"SET QUOTED_IDENTIFIER ON";
211+
"SET ANSI_NULLS OFF" or
212+
"SET QUOTED_IDENTIFIER ON" or
213+
"SET QUOTED_IDENTIFIER OFF";
212214
}

0 commit comments

Comments
 (0)