@@ -18,10 +18,61 @@ public string BuildTableCommandText(Checkpoint checkpoint)
1818
1919 if ( checkpoint . TablesToIgnore . Any ( ) )
2020 {
21- var args = string . Join ( "," , checkpoint . TablesToIgnore . Select ( t => $ "'{ t } '") ) ;
22-
23- commandText += " AND t.tabname NOT IN (" + args + ")" ;
21+ var tablesToIgnoreGroups = checkpoint . TablesToIgnore
22+ . GroupBy (
23+ t => t . Schema != null ,
24+ t => t ,
25+ ( hasSchema , tables ) => new
26+ {
27+ HasSchema = hasSchema ,
28+ Tables = tables
29+ } )
30+ . ToList ( ) ;
31+ foreach ( var tableGroup in tablesToIgnoreGroups )
32+ {
33+ if ( tableGroup . HasSchema )
34+ {
35+ var args = string . Join ( "," , tableGroup . Tables . Select ( table => $ "'{ table . Schema } .{ table . Name } '") ) ;
36+
37+ commandText += " AND t.owner + '.' + t.tabname NOT IN (" + args + ")" ;
38+ }
39+ else
40+ {
41+ var args = string . Join ( "," , tableGroup . Tables . Select ( table => $ "'{ table . Name } '") ) ;
42+
43+ commandText += " AND t.tabname NOT IN (" + args + ")" ;
44+ }
45+ }
46+ }
47+ if ( checkpoint . TablesToInclude . Any ( ) )
48+ {
49+ var tablesToIncludeGroups = checkpoint . TablesToInclude
50+ . GroupBy (
51+ t => t . Schema != null ,
52+ t => t ,
53+ ( hasSchema , tables ) => new
54+ {
55+ HasSchema = hasSchema ,
56+ Tables = tables
57+ } )
58+ . ToList ( ) ;
59+ foreach ( var tableGroup in tablesToIncludeGroups )
60+ {
61+ if ( tableGroup . HasSchema )
62+ {
63+ var args = string . Join ( "," , tableGroup . Tables . Select ( table => $ "'{ table . Schema } .{ table . Name } '") ) ;
64+
65+ commandText += " AND t.owner + '.' + t.tabname IN (" + args + ")" ;
66+ }
67+ else
68+ {
69+ var args = string . Join ( "," , tableGroup . Tables . Select ( table => $ "'{ table . Name } '") ) ;
70+
71+ commandText += " AND t.tabname IN (" + args + ")" ;
72+ }
73+ }
2474 }
75+
2576 if ( checkpoint . SchemasToExclude . Any ( ) )
2677 {
2778 var args = string . Join ( "," , checkpoint . SchemasToExclude . Select ( t => $ "'{ t } '") ) ;
@@ -54,9 +105,59 @@ INNER JOIN systables T2
54105
55106 if ( checkpoint . TablesToIgnore . Any ( ) )
56107 {
57- var args = string . Join ( "," , checkpoint . TablesToIgnore . Select ( t => $ "'{ t } '") ) ;
58-
59- commandText += " AND T2.tabname NOT IN (" + args + ")" ;
108+ var tablesToIgnoreGroups = checkpoint . TablesToIgnore
109+ . GroupBy (
110+ t => t . Schema != null ,
111+ t => t ,
112+ ( hasSchema , tables ) => new
113+ {
114+ HasSchema = hasSchema ,
115+ Tables = tables
116+ } )
117+ . ToList ( ) ;
118+ foreach ( var tableGroup in tablesToIgnoreGroups )
119+ {
120+ if ( tableGroup . HasSchema )
121+ {
122+ var args = string . Join ( "," , tableGroup . Tables . Select ( table => $ "'{ table . Schema } .{ table . Name } '") ) ;
123+
124+ commandText += " AND T2.owner + '.' + T2.tabname NOT IN (" + args + ")" ;
125+ }
126+ else
127+ {
128+ var args = string . Join ( "," , tableGroup . Tables . Select ( table => $ "'{ table . Name } '") ) ;
129+
130+ commandText += " AND T2.tabname NOT IN (" + args + ")" ;
131+ }
132+ }
133+ }
134+ if ( checkpoint . TablesToInclude . Any ( ) )
135+ {
136+ var tablesToIncludeGroups = checkpoint . TablesToInclude
137+ . GroupBy (
138+ t => t . Schema != null ,
139+ t => t ,
140+ ( hasSchema , tables ) => new
141+ {
142+ HasSchema = hasSchema ,
143+ Tables = tables
144+ } )
145+ . ToList ( ) ;
146+ foreach ( var tableGroup in tablesToIncludeGroups )
147+ {
148+ if ( tableGroup . HasSchema )
149+ {
150+ var args = string . Join ( "," , tableGroup . Tables . Select ( table => $ "'{ table . Schema } .{ table . Name } '") ) ;
151+
152+ commandText += " AND T2.owner + '.' + T2.tabname IN (" + args + ")" ;
153+ }
154+ else
155+ {
156+ var args = string . Join ( "," , tableGroup . Tables . Select ( table => $ "'{ table . Name } '") ) ;
157+
158+ commandText += " AND T2.tabname IN (" + args + ")" ;
159+ }
160+ }
60161 }
61162 if ( checkpoint . SchemasToExclude . Any ( ) )
62163 {
0 commit comments