@@ -69,6 +69,32 @@ public override void SetupOptionsContent(Control Parent, EventHandler changedHan
69
69
Parent . Controls . Add ( checkBox ) ;
70
70
}
71
71
72
+ {
73
+ CheckBox checkBox = new CheckBox ( ) ;
74
+ checkBox . Text = "values" ;
75
+ checkBox . Name = "option_values" ;
76
+ checkBox . CheckedChanged += changedHandler ;
77
+ Parent . Controls . Add ( checkBox ) ;
78
+ }
79
+
80
+ {
81
+ CheckBox checkBox = new CheckBox ( ) ;
82
+ checkBox . Text = "include default columns" ;
83
+ checkBox . Name = "option_default" ;
84
+ checkBox . Checked = true ;
85
+ checkBox . CheckedChanged += changedHandler ;
86
+ Parent . Controls . Add ( checkBox ) ;
87
+ }
88
+
89
+ {
90
+ CheckBox checkBox = new CheckBox ( ) ;
91
+ checkBox . Text = "not already exists" ;
92
+ checkBox . Name = "option_notalready" ;
93
+ checkBox . Checked = false ;
94
+ checkBox . CheckedChanged += changedHandler ;
95
+ Parent . Controls . Add ( checkBox ) ;
96
+ }
97
+
72
98
}
73
99
74
100
public override string TranslateExt ( CreateTableStatement createTableStatement , object options )
@@ -115,6 +141,36 @@ public override string TranslateExt(CreateTableStatement createTableStatement, o
115
141
}
116
142
}
117
143
144
+ bool bOptionValues = false ;
145
+ if ( options is Control )
146
+ {
147
+ var r = ( ( Control ) options ) . Controls . Find ( "option_values" , true ) ;
148
+ if ( r . Length > 0 )
149
+ {
150
+ bOptionValues = ( r [ 0 ] as CheckBox ) . Checked ;
151
+ }
152
+ }
153
+
154
+ bool bOptionDefault = true ;
155
+ if ( options is Control )
156
+ {
157
+ var r = ( ( Control ) options ) . Controls . Find ( "option_default" , true ) ;
158
+ if ( r . Length > 0 )
159
+ {
160
+ bOptionDefault = ( r [ 0 ] as CheckBox ) . Checked ;
161
+ }
162
+ }
163
+
164
+ bool bNotAlready = false ;
165
+ if ( options is Control )
166
+ {
167
+ var r = ( ( Control ) options ) . Controls . Find ( "option_notalready" , true ) ;
168
+ if ( r . Length > 0 )
169
+ {
170
+ bNotAlready = ( r [ 0 ] as CheckBox ) . Checked ;
171
+ }
172
+ }
173
+
118
174
string keywordSep = bOptionInline ? " " : Environment . NewLine ;
119
175
string optionAllias = optionAllias0 ;
120
176
string optionAlliasDest = optionAlliasDest0 ;
@@ -132,6 +188,7 @@ public override string TranslateExt(CreateTableStatement createTableStatement, o
132
188
sep = null ;
133
189
foreach ( ColumnDefinition columnDefinition in tableDefinition . ColumnDefinitions )
134
190
{
191
+ if ( ! bOptionDefault && TSQLHelper . ColumnIsDefault ( columnDefinition ) ) continue ;
135
192
string ident = TSQLHelper . Identifier2Value ( columnDefinition . ColumnIdentifier ) ;
136
193
//if (!bOptionInline)
137
194
result . Append ( $ "{ columnIdent } { sep } { ident } { sColumnSeparator } ") ;
@@ -140,12 +197,32 @@ public override string TranslateExt(CreateTableStatement createTableStatement, o
140
197
}
141
198
result . Append ( $ "){ Environment . NewLine } ") ;
142
199
}
200
+
201
+ if ( bOptionValues )
202
+ {
203
+ result . Append ( $ "values(") ;
204
+ sep = null ;
205
+ foreach ( ColumnDefinition columnDefinition in tableDefinition . ColumnDefinitions )
206
+ {
207
+ if ( ! bOptionDefault && TSQLHelper . ColumnIsDefault ( columnDefinition ) ) continue ;
208
+ string ident = TSQLHelper . Identifier2Value ( columnDefinition . ColumnIdentifier ) ;
209
+ if ( bOptionExplicitNames )
210
+ {
211
+ result . Append ( $ "{ columnIdent } { sep } { optionAllias } { ident } /*{ ident } */{ sColumnSeparator } ") ;
212
+ }
213
+ else result . Append ( $ "{ columnIdent } { sep } { optionAllias } { ident } { sColumnSeparator } ") ;
214
+ if ( String . IsNullOrEmpty ( sep ) ) sep = ", " ;
215
+ }
216
+ result . Append ( $ "){ Environment . NewLine } ") ;
217
+ }
218
+ else
143
219
// select
144
220
{
145
221
result . Append ( $ "select{ keywordSep } ") ;
146
222
sep = null ;
147
223
foreach ( ColumnDefinition columnDefinition in tableDefinition . ColumnDefinitions )
148
224
{
225
+ if ( ! bOptionDefault && TSQLHelper . ColumnIsDefault ( columnDefinition ) ) continue ;
149
226
string ident = TSQLHelper . Identifier2Value ( columnDefinition . ColumnIdentifier ) ;
150
227
if ( bOptionExplicitNames )
151
228
{
@@ -159,6 +236,25 @@ public override string TranslateExt(CreateTableStatement createTableStatement, o
159
236
160
237
result . Append ( $ "{ keywordSep } from { optionAllias0 } { Environment . NewLine } ") ;
161
238
}
239
+
240
+
241
+ if ( bNotAlready )
242
+ {
243
+ result . Append ( $ "where not exists(select 1 from { tableName } t with (nolock) where") ;
244
+ int i = 0 ;
245
+ foreach ( ColumnDefinition columnDefinition in tableDefinition . ColumnDefinitions )
246
+ {
247
+ i ++ ;
248
+ if ( ! bOptionDefault && TSQLHelper . ColumnIsDefault ( columnDefinition ) ) continue ;
249
+ string ident = TSQLHelper . Identifier2Value ( columnDefinition . ColumnIdentifier ) ;
250
+ if ( i > 1 )
251
+ result . Append ( $ " and") ;
252
+ result . Append ( $ " t.{ ident } = { optionAllias } { ident } ") ;
253
+ }
254
+ result . Append ( $ ")") ;
255
+ }
256
+
257
+ result . Append ( $ ";") ;
162
258
return result . ToString ( ) ;
163
259
}
164
260
}
0 commit comments