@@ -94,37 +94,74 @@ public SchemaExport SetDelimiter(string delimiter)
94
94
/// <summary>
95
95
/// Run the schema creation script
96
96
/// </summary>
97
- /// <param name="script "><see langword="true" /> if the ddl should be outputted in the Console.</param>
98
- /// <param name="export "><see langword="true" /> if the ddl should be executed against the Database.</param>
97
+ /// <param name="useStdOut "><see langword="true" /> if the ddl should be outputted in the Console.</param>
98
+ /// <param name="execute "><see langword="true" /> if the ddl should be executed against the Database.</param>
99
99
/// <remarks>
100
100
/// This is a convenience method that calls <see cref="Execute(bool, bool, bool)"/> and sets
101
101
/// the justDrop parameter to false.
102
102
/// </remarks>
103
- public void Create ( bool script , bool export )
103
+ public void Create ( bool useStdOut , bool execute )
104
104
{
105
- Execute ( script , export , false ) ;
105
+ Execute ( useStdOut , execute , false ) ;
106
106
}
107
107
108
- public void Create ( Action < string > scriptAction , bool export )
108
+ /// <summary>
109
+ /// Run the schema creation script
110
+ /// </summary>
111
+ /// <param name="scriptAction"> an action that will be called for each line of the generated ddl.</param>
112
+ /// <param name="execute"><see langword="true" /> if the ddl should be executed against the Database.</param>
113
+ /// <remarks>
114
+ /// This is a convenience method that calls <see cref="Execute(bool, bool, bool)"/> and sets
115
+ /// the justDrop parameter to false.
116
+ /// </remarks>
117
+ public void Create ( Action < string > scriptAction , bool execute )
109
118
{
110
- Execute ( scriptAction , export , false ) ;
119
+ Execute ( scriptAction , execute , false ) ;
120
+ }
121
+
122
+ /// <summary>
123
+ /// Run the schema creation script
124
+ /// </summary>
125
+ /// <param name="exportOutput"> if non-null, the ddl will be written to this TextWriter.</param>
126
+ /// <param name="execute"><see langword="true" /> if the ddl should be executed against the Database.</param>
127
+ /// <remarks>
128
+ /// This is a convenience method that calls <see cref="Execute(bool, bool, bool)"/> and sets
129
+ /// the justDrop parameter to false.
130
+ /// </remarks>
131
+ public void Create ( TextWriter exportOutput , bool execute )
132
+ {
133
+ Execute ( null , execute , false , exportOutput ) ;
111
134
}
112
135
113
136
/// <summary>
114
137
/// Run the drop schema script
115
138
/// </summary>
116
- /// <param name="script "><see langword="true" /> if the ddl should be outputted in the Console.</param>
117
- /// <param name="export "><see langword="true" /> if the ddl should be executed against the Database.</param>
139
+ /// <param name="useStdOut "><see langword="true" /> if the ddl should be outputted in the Console.</param>
140
+ /// <param name="execute "><see langword="true" /> if the ddl should be executed against the Database.</param>
118
141
/// <remarks>
119
142
/// This is a convenience method that calls <see cref="Execute(bool, bool, bool)"/> and sets
120
143
/// the justDrop parameter to true.
121
144
/// </remarks>
122
- public void Drop ( bool script , bool export )
145
+ public void Drop ( bool useStdOut , bool execute )
123
146
{
124
- Execute ( script , export , true ) ;
147
+ Execute ( useStdOut , execute , true ) ;
125
148
}
126
149
127
- private void Execute ( Action < string > scriptAction , bool export , bool throwOnError , TextWriter exportOutput ,
150
+ /// <summary>
151
+ /// Run the drop schema script
152
+ /// </summary>
153
+ /// <param name="exportOutput"> if non-null, the ddl will be written to this TextWriter.</param>
154
+ /// <param name="execute"><see langword="true" /> if the ddl should be executed against the Database.</param>
155
+ /// <remarks>
156
+ /// This is a convenience method that calls <see cref="Execute(Action<string>, bool, bool, TextWriter)"/> and sets
157
+ /// the justDrop parameter to true.
158
+ /// </remarks>
159
+ public void Drop ( TextWriter exportOutput , bool execute )
160
+ {
161
+ Execute ( null , execute , true , exportOutput ) ;
162
+ }
163
+
164
+ private void Execute ( Action < string > scriptAction , bool execute , bool throwOnError , TextWriter exportOutput ,
128
165
IDbCommand statement , string sql )
129
166
{
130
167
Initialize ( ) ;
@@ -145,7 +182,7 @@ private void Execute(Action<string> scriptAction, bool export, bool throwOnError
145
182
{
146
183
exportOutput . WriteLine ( formatted ) ;
147
184
}
148
- if ( export )
185
+ if ( execute )
149
186
{
150
187
ExecuteSql ( statement , sql ) ;
151
188
}
@@ -187,8 +224,8 @@ private void ExecuteSql(IDbCommand cmd, string sql)
187
224
/// <summary>
188
225
/// Executes the Export of the Schema in the given connection
189
226
/// </summary>
190
- /// <param name="script "><see langword="true" /> if the ddl should be outputted in the Console.</param>
191
- /// <param name="export "><see langword="true" /> if the ddl should be executed against the Database.</param>
227
+ /// <param name="useStdOut "><see langword="true" /> if the ddl should be outputted in the Console.</param>
228
+ /// <param name="execute "><see langword="true" /> if the ddl should be executed against the Database.</param>
192
229
/// <param name="justDrop"><see langword="true" /> if only the ddl to drop the Database objects should be executed.</param>
193
230
/// <param name="connection">
194
231
/// The connection to use when executing the commands when export is <see langword="true" />.
@@ -200,30 +237,30 @@ private void ExecuteSql(IDbCommand cmd, string sql)
200
237
/// This overload is provided mainly to enable use of in memory databases.
201
238
/// It does NOT close the given connection!
202
239
/// </remarks>
203
- public void Execute ( bool script , bool export , bool justDrop , IDbConnection connection ,
240
+ public void Execute ( bool useStdOut , bool execute , bool justDrop , IDbConnection connection ,
204
241
TextWriter exportOutput )
205
242
{
206
- if ( script )
243
+ if ( useStdOut )
207
244
{
208
- Execute ( Console . WriteLine , export , justDrop , connection , exportOutput ) ;
245
+ Execute ( Console . WriteLine , execute , justDrop , connection , exportOutput ) ;
209
246
}
210
247
else
211
248
{
212
- Execute ( null , export , justDrop , connection , exportOutput ) ;
249
+ Execute ( null , execute , justDrop , connection , exportOutput ) ;
213
250
}
214
251
}
215
252
216
- public void Execute ( Action < string > scriptAction , bool export , bool justDrop , IDbConnection connection ,
253
+ public void Execute ( Action < string > scriptAction , bool execute , bool justDrop , IDbConnection connection ,
217
254
TextWriter exportOutput )
218
255
{
219
256
Initialize ( ) ;
220
257
IDbCommand statement = null ;
221
258
222
- if ( export && connection == null )
259
+ if ( execute && connection == null )
223
260
{
224
261
throw new ArgumentNullException ( "connection" , "When export is set to true, you need to pass a non null connection" ) ;
225
262
}
226
- if ( export )
263
+ if ( execute )
227
264
{
228
265
statement = connection . CreateCommand ( ) ;
229
266
}
@@ -232,14 +269,14 @@ public void Execute(Action<string> scriptAction, bool export, bool justDrop, IDb
232
269
{
233
270
for ( int i = 0 ; i < dropSQL . Length ; i ++ )
234
271
{
235
- Execute ( scriptAction , export , false , exportOutput , statement , dropSQL [ i ] ) ;
272
+ Execute ( scriptAction , execute , false , exportOutput , statement , dropSQL [ i ] ) ;
236
273
}
237
274
238
275
if ( ! justDrop )
239
276
{
240
277
for ( int j = 0 ; j < createSQL . Length ; j ++ )
241
278
{
242
- Execute ( scriptAction , export , true , exportOutput , statement , createSQL [ j ] ) ;
279
+ Execute ( scriptAction , execute , true , exportOutput , statement , createSQL [ j ] ) ;
243
280
}
244
281
}
245
282
}
@@ -273,59 +310,66 @@ public void Execute(Action<string> scriptAction, bool export, bool justDrop, IDb
273
310
/// <summary>
274
311
/// Executes the Export of the Schema.
275
312
/// </summary>
276
- /// <param name="script "><see langword="true" /> if the ddl should be outputted in the Console.</param>
277
- /// <param name="export "><see langword="true" /> if the ddl should be executed against the Database.</param>
313
+ /// <param name="useStdOut "><see langword="true" /> if the ddl should be outputted in the Console.</param>
314
+ /// <param name="execute "><see langword="true" /> if the ddl should be executed against the Database.</param>
278
315
/// <param name="justDrop"><see langword="true" /> if only the ddl to drop the Database objects should be executed.</param>
279
316
/// <remarks>
280
317
/// This method allows for both the drop and create ddl script to be executed.
281
318
/// </remarks>
282
- public void Execute ( bool script , bool export , bool justDrop )
319
+ public void Execute ( bool useStdOut , bool execute , bool justDrop )
283
320
{
284
- if ( script )
321
+ if ( useStdOut )
285
322
{
286
- Execute ( Console . WriteLine , export , justDrop ) ;
323
+ Execute ( Console . WriteLine , execute , justDrop ) ;
287
324
}
288
325
else
289
326
{
290
- Execute ( null , export , justDrop ) ;
327
+ Execute ( null , execute , justDrop ) ;
291
328
}
292
329
}
293
330
294
- public void Execute ( Action < string > scriptAction , bool export , bool justDrop )
331
+
332
+ public void Execute ( Action < string > scriptAction , bool execute , bool justDrop )
333
+ {
334
+ Execute ( scriptAction , execute , justDrop , null ) ;
335
+ }
336
+
337
+
338
+ public void Execute ( Action < string > scriptAction , bool execute , bool justDrop , TextWriter exportOutput )
295
339
{
296
340
Initialize ( ) ;
297
341
IDbConnection connection = null ;
298
- StreamWriter fileOutput = null ;
342
+ TextWriter fileOutput = exportOutput ;
299
343
IConnectionProvider connectionProvider = null ;
300
344
301
- var props = new Dictionary < string , string > ( ) ;
302
- foreach ( var de in dialect . DefaultProperties )
303
- {
304
- props [ de . Key ] = de . Value ;
305
- }
306
-
307
- if ( configProperties != null )
308
- {
309
- foreach ( var de in configProperties )
310
- {
311
- props [ de . Key ] = de . Value ;
312
- }
313
- }
314
-
315
345
try
316
346
{
317
- if ( outputFile != null )
347
+ if ( fileOutput != null && outputFile != null )
318
348
{
319
349
fileOutput = new StreamWriter ( outputFile ) ;
320
350
}
321
351
322
- if ( export )
352
+ if ( execute )
323
353
{
354
+ var props = new Dictionary < string , string > ( ) ;
355
+ foreach ( var de in dialect . DefaultProperties )
356
+ {
357
+ props [ de . Key ] = de . Value ;
358
+ }
359
+
360
+ if ( configProperties != null )
361
+ {
362
+ foreach ( var de in configProperties )
363
+ {
364
+ props [ de . Key ] = de . Value ;
365
+ }
366
+ }
367
+
324
368
connectionProvider = ConnectionProviderFactory . NewConnectionProvider ( props ) ;
325
369
connection = connectionProvider . GetConnection ( ) ;
326
370
}
327
371
328
- Execute ( scriptAction , export , justDrop , connection , fileOutput ) ;
372
+ Execute ( scriptAction , execute , justDrop , connection , fileOutput ) ;
329
373
}
330
374
catch ( HibernateException )
331
375
{
0 commit comments