Skip to content

Commit edd4a6d

Browse files
authored
Merge pull request #431 from DataObjects-NET/7.1-filter-ms-tables
MS SQL Server: Filter out database objects created by microsoft
2 parents 93adc35 + 47c2bb9 commit edd4a6d

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

ChangeLog/7.1.5_dev.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[main] Addressed certain cases of overlaping server-side error by new one when temporary tables are used in query
22
[postgresql] Improved .Milliseconds translation for types which have this part
3-
[postgresql] Improved TimeSpan.TotalMilliseconds translation
3+
[postgresql] Improved TimeSpan.TotalMilliseconds translation
4+
[sqlserver] Database schema objects which are "microsoft shipped", e.g. created for replication mechanisms, etc., are excluded on schema extraction

Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v09/Extractor.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public ExtractionContext(Catalog catalog, IReadOnlyCollection<string> targetSche
7272
}
7373

7474
protected const string SysTablesFilterPlaceholder = "{SYSTABLE_FILTER}";
75+
protected const string SysObjectFilterPlaceholder = "{SYSOBJECT_FILTER}";
7576
protected const string CatalogPlaceholder = "{CATALOG}";
7677
protected const string SchemaFilterPlaceholder = "{SCHEMA_FILTER}";
7778

@@ -125,6 +126,7 @@ protected virtual void RegisterReplacements(ExtractionContext context)
125126
{
126127
context.RegisterReplacement(SchemaFilterPlaceholder, MakeSchemaFilter(context));
127128
context.RegisterReplacement(SysTablesFilterPlaceholder, "1 > 0");
129+
context.RegisterReplacement(SysObjectFilterPlaceholder, "is_ms_shipped = 0");
128130
}
129131

130132
private ExtractionContext CreateContext(string catalogName, string[] schemaNames)
@@ -303,14 +305,15 @@ private string BuildExtractTablesAndViewsQuery(ExtractionContext context)
303305
name,
304306
0 type
305307
FROM {CATALOG}.sys.tables
306-
WHERE {SYSTABLE_FILTER}
308+
WHERE {SYSTABLE_FILTER} AND {SYSOBJECT_FILTER}
307309
UNION
308310
SELECT
309311
schema_id,
310312
object_id,
311313
name,
312314
1 type
313315
FROM {CATALOG}.sys.views
316+
WHERE {SYSOBJECT_FILTER}
314317
) AS t
315318
WHERE t.schema_id {SCHEMA_FILTER}
316319
ORDER BY t.schema_id, t.object_id";
@@ -411,13 +414,14 @@ INNER JOIN (
411414
object_id,
412415
0 as type
413416
FROM {CATALOG}.sys.tables
414-
WHERE {SYSTABLE_FILTER}
417+
WHERE {SYSTABLE_FILTER} AND {SYSOBJECT_FILTER}
415418
UNION
416419
SELECT
417420
schema_id,
418421
object_id,
419422
1 AS type
420423
FROM {CATALOG}.sys.views
424+
WHERE {SYSOBJECT_FILTER}
421425
) AS t ON c.object_id = t.object_id
422426
LEFT OUTER JOIN {CATALOG}.sys.default_constraints AS dc
423427
ON c.object_id = dc.parent_object_id
@@ -501,6 +505,7 @@ WHERE seed_value IS NOT NULL
501505
AND increment_value IS NOT NULL
502506
AND {SYSTABLE_FILTER}
503507
AND t.schema_id {SCHEMA_FILTER}
508+
AND t.{SYSOBJECT_FILTER}
504509
ORDER BY
505510
t.schema_id,
506511
ic.object_id";
@@ -560,13 +565,14 @@ INNER JOIN (
560565
object_id,
561566
0 AS type
562567
FROM {CATALOG}.sys.tables
563-
WHERE {SYSTABLE_FILTER}
568+
WHERE {SYSTABLE_FILTER} AND {SYSOBJECT_FILTER}
564569
UNION
565570
SELECT
566571
schema_id,
567572
object_id,
568573
1 AS type
569574
FROM {CATALOG}.sys.views
575+
WHERE {SYSOBJECT_FILTER}
570576
) AS t
571577
ON i.object_id = t.object_id
572578
INNER JOIN {CATALOG}.sys.index_columns ic
@@ -839,7 +845,7 @@ INNER JOIN {CATALOG}.sys.indexes AS i
839845
ON fic.object_id = i.object_id
840846
AND fi.unique_index_id = i.index_id
841847
WHERE {SYSTABLE_FILTER}
842-
AND t.schema_id {SCHEMA_FILTER}
848+
AND t.schema_id {SCHEMA_FILTER} AND t.{SYSOBJECT_FILTER}
843849
ORDER BY
844850
t.schema_id,
845851
fic.object_id,

Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v10/Extractor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ INNER JOIN (
3636
object_id,
3737
0 AS type
3838
FROM {CATALOG}.sys.tables
39-
WHERE {SYSTABLE_FILTER}
39+
WHERE {SYSTABLE_FILTER} AND {SYSOBJECT_FILTER}
4040
UNION
4141
SELECT
4242
schema_id,
4343
object_id,
4444
1 AS type
4545
FROM {CATALOG}.sys.views
46+
WHERE {SYSOBJECT_FILTER}
4647
) AS t
4748
ON i.object_id = t.object_id
4849
INNER JOIN {CATALOG}.sys.index_columns ic

Orm/Xtensive.Orm.SqlServer/Sql.Drivers.SqlServer/v11/Extractor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private string BuildExtractSequencesQuery(ExtractionContext context)
6868
is_cycling,
6969
current_value
7070
FROM {CATALOG}.sys.sequences
71-
WHERE schema_id {SCHEMA_FILTER}
71+
WHERE schema_id {SCHEMA_FILTER} AND {SYSOBJECT_FILTER}
7272
ORDER BY
7373
schema_id,
7474
object_id";

0 commit comments

Comments
 (0)