From d6ba62194ec53374cebdefa4f16e1481c5470aee Mon Sep 17 00:00:00 2001 From: Andrew Brobston Date: Mon, 20 Nov 2017 11:41:25 -0600 Subject: [PATCH] Display final row count for each table Addresses #12. --- soddi/Loaders/BulkCopyTask.cs | 4 ++-- soddi/Loaders/MsSql/MsSqlBulkInserter.cs | 11 +++++++++++ soddi/Loaders/MySql/MySqlBulkInserter.cs | 1 + soddi/Loaders/SQLite/SQLiteBulkInserter.cs | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/soddi/Loaders/BulkCopyTask.cs b/soddi/Loaders/BulkCopyTask.cs index 0763c72..19fac5f 100644 --- a/soddi/Loaders/BulkCopyTask.cs +++ b/soddi/Loaders/BulkCopyTask.cs @@ -137,8 +137,8 @@ public void Process() } _bc.RowsInserted += (s, e) => - { - _count += _bc.NotifyAfter; + { + _count = e.Count; e.Abort = OnRowsInserted(CopyEventType.Active); if (e.Abort) { diff --git a/soddi/Loaders/MsSql/MsSqlBulkInserter.cs b/soddi/Loaders/MsSql/MsSqlBulkInserter.cs index f1a335f..ff2a1ce 100644 --- a/soddi/Loaders/MsSql/MsSqlBulkInserter.cs +++ b/soddi/Loaders/MsSql/MsSqlBulkInserter.cs @@ -89,6 +89,17 @@ public override void WriteToServer(IDataReader reader) try { _inner.WriteToServer(reader); + using (var connection = new SqlConnection(_connectionString)) + { + connection.Open(); + using (var command = connection.CreateCommand()) + { + command.CommandType = CommandType.Text; + command.CommandText = $"SELECT COUNT_BIG(*) FROM {DestinationTableName}"; + var rowCount = (long) command.ExecuteScalar(); + OnRowsInserted(new BulkCopyEventArgs {Count = rowCount, Type = CopyEventType.Complete}); + } + } } finally { diff --git a/soddi/Loaders/MySql/MySqlBulkInserter.cs b/soddi/Loaders/MySql/MySqlBulkInserter.cs index f13c0b2..acdd14d 100644 --- a/soddi/Loaders/MySql/MySqlBulkInserter.cs +++ b/soddi/Loaders/MySql/MySqlBulkInserter.cs @@ -131,6 +131,7 @@ public override void WriteToServer(IDataReader reader) dbTrans.Commit(); } } + OnRowsInserted(new BulkCopyEventArgs {Count = totalRecords, Type = CopyEventType.Complete}); } } } diff --git a/soddi/Loaders/SQLite/SQLiteBulkInserter.cs b/soddi/Loaders/SQLite/SQLiteBulkInserter.cs index ef64060..9ac8332 100644 --- a/soddi/Loaders/SQLite/SQLiteBulkInserter.cs +++ b/soddi/Loaders/SQLite/SQLiteBulkInserter.cs @@ -130,6 +130,7 @@ public override void WriteToServer(IDataReader reader) dbTrans.Commit(); } } + OnRowsInserted(new BulkCopyEventArgs {Count = totalRecords, Type = CopyEventType.Complete}); } } }