Added method to apply delta SQL script including asynchronously
This commit is contained in:
16
Delta.cs
16
Delta.cs
@@ -2,6 +2,7 @@
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace DbTools {
|
namespace DbTools {
|
||||||
public class Delta {
|
public class Delta {
|
||||||
@@ -32,6 +33,21 @@ namespace DbTools {
|
|||||||
return BuildDelta(db1, db2, removeUnusedTables, removeUnusedColumns, removeUnusedTriggers, removeUnusedIndexes);
|
return BuildDelta(db1, db2, removeUnusedTables, removeUnusedColumns, removeUnusedTriggers, removeUnusedIndexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ApplyDeltaAsync(IDbConnection cn, string sql) {
|
||||||
|
return await Task.Run(() => {
|
||||||
|
return ApplyDelta(cn, sql);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ApplyDelta(IDbConnection cn, string sql) {
|
||||||
|
bool success = false;
|
||||||
|
using (var cmd = cn.CreateCommand()) {
|
||||||
|
cmd.CommandText = sql;
|
||||||
|
success = cmd.ExecuteNonQuery() > 0;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
private string BuildDelta(Database db1, Database db2, bool removeUnusedTables, bool removeUnusedColumns, bool removeUnusedTriggers, bool removeUnusedIndexes) {
|
private string BuildDelta(Database db1, Database db2, bool removeUnusedTables, bool removeUnusedColumns, bool removeUnusedTriggers, bool removeUnusedIndexes) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user