From 3cdec4743a6742bc8b2d2a9ea2d35a5b0be6a0ff Mon Sep 17 00:00:00 2001 From: ErikEJ Date: Fri, 31 Mar 2017 19:09:29 +0200 Subject: [PATCH] R# fixes --- src/DestinationTableDefaultMetadata.cs | 7 +- src/ForeignKeyLib/ColumnList.cs | 2 +- src/ForeignKeyLib/Constraint.cs | 2 +- src/ForeignKeyLib/DBRepository.cs | 24 +-- src/ForeignKeyLib/ForeignKeyRepository.cs | 25 ++- src/ForeignKeyLib/Generator.cs | 8 +- src/ForeignKeyLib/IGenerator.cs | 2 +- src/ForeignKeyLib/IRepository.cs | 2 +- src/ForeignKeyLib/RepositoryHelper.cs | 4 +- src/ISqlCeBulkCopyInsertAdapter.cs | 6 +- src/SqlCeBulkCopy.cs | 182 +++++++++++----------- src/SqlCeBulkCopyColumnMapping.cs | 10 +- src/SqlCeBulkCopyDataReaderAdapter.cs | 4 +- src/SqlCeBulkCopyDataTableAdapter.cs | 3 - src/SqlCeBulkCopyMappingCollection.cs | 4 +- src/SqlCeBulkCopyTableHelpers.cs | 5 +- src/SqlCeRowsCopiedEventArgs.cs | 4 - src/Test/SqlCeBulkCopyTest.cs | 3 +- 18 files changed, 135 insertions(+), 162 deletions(-) diff --git a/src/DestinationTableDefaultMetadata.cs b/src/DestinationTableDefaultMetadata.cs index 5360c17..487f8ca 100644 --- a/src/DestinationTableDefaultMetadata.cs +++ b/src/DestinationTableDefaultMetadata.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; using System.Data; using System.Data.SqlServerCe; using System.Globalization; @@ -30,9 +29,9 @@ public bool HasDefault public DestinationTableDefaultMetadata(IDataReader reader) { - this.ColumnName = (reader.GetString(0) ?? string.Empty).ToUpper(CultureInfo.InvariantCulture); - this.IsNullable = reader.GetString(1).Equals("YES", StringComparison.OrdinalIgnoreCase) ? true : false; - this.HasDefault = reader.GetBoolean(2); + ColumnName = (reader.GetString(0) ?? string.Empty).ToUpper(CultureInfo.InvariantCulture); + IsNullable = reader.GetString(1).Equals("YES", StringComparison.OrdinalIgnoreCase); + HasDefault = reader.GetBoolean(2); } public static List GetDataForTable(SqlCeConnection conn, SqlCeTransaction transaction, string tableName) diff --git a/src/ForeignKeyLib/ColumnList.cs b/src/ForeignKeyLib/ColumnList.cs index cbf0a72..1a8a4ce 100644 --- a/src/ForeignKeyLib/ColumnList.cs +++ b/src/ForeignKeyLib/ColumnList.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Text; -namespace ErikEJ.SqlCeScripting +namespace ErikEJ.SqlCe.ForeignKeyLib { public class ColumnList : List { diff --git a/src/ForeignKeyLib/Constraint.cs b/src/ForeignKeyLib/Constraint.cs index 622109f..8a33745 100644 --- a/src/ForeignKeyLib/Constraint.cs +++ b/src/ForeignKeyLib/Constraint.cs @@ -1,4 +1,4 @@ -namespace ErikEJ.SqlCeScripting +namespace ErikEJ.SqlCe.ForeignKeyLib { public class Constraint { diff --git a/src/ForeignKeyLib/DBRepository.cs b/src/ForeignKeyLib/DBRepository.cs index f926e71..ebc5256 100644 --- a/src/ForeignKeyLib/DBRepository.cs +++ b/src/ForeignKeyLib/DBRepository.cs @@ -1,21 +1,21 @@ using System.Collections.Generic; using System.Data.SqlServerCe; -namespace ErikEJ.SqlCeScripting +namespace ErikEJ.SqlCe.ForeignKeyLib { - public sealed class DBRepository : IRepository + internal class DbRepository : IRepository { - private SqlCeConnection cn; + private SqlCeConnection _cn; private delegate void AddToListDelegate(ref List list, SqlCeDataReader dr); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The connection string. - public DBRepository(string connectionString) + public DbRepository(string connectionString) { - cn = new SqlCeConnection(connectionString); - cn.Open(); + _cn = new SqlCeConnection(connectionString); + _cn.Open(); } /// @@ -23,10 +23,10 @@ public DBRepository(string connectionString) /// public void Dispose() { - if (cn != null) + if (_cn != null) { - cn.Close(); - cn = null; + _cn.Close(); + _cn = null; } } @@ -55,7 +55,7 @@ private static void AddToListConstraints(ref List list, SqlCeDataRea private List ExecuteReader(string commandText, AddToListDelegate AddToListMethod) { List list = new List(); - using (var cmd = new SqlCeCommand(commandText, cn)) + using (var cmd = new SqlCeCommand(commandText, _cn)) { using (var dr = cmd.ExecuteReader()) { @@ -124,7 +124,7 @@ public void RunCommand(string sql) { using (SqlCeCommand cmd = new SqlCeCommand()) { - cmd.Connection = cn; + cmd.Connection = _cn; cmd.CommandText = sql; cmd.ExecuteNonQuery(); } diff --git a/src/ForeignKeyLib/ForeignKeyRepository.cs b/src/ForeignKeyLib/ForeignKeyRepository.cs index 8c09024..2c99583 100644 --- a/src/ForeignKeyLib/ForeignKeyRepository.cs +++ b/src/ForeignKeyLib/ForeignKeyRepository.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; -using System.Text; -using ErikEJ.SqlCeScripting; using System.Linq; -namespace ErikEJ.SqlCeScripting +namespace ErikEJ.SqlCe.ForeignKeyLib { public class ForeignKeyRepository { @@ -21,7 +19,7 @@ protected ForeignKeyRepository() { } public List GetConstraints() { - using (var repo = new DBRepository(_connectionString)) + using (var repo = new DbRepository(_connectionString)) { return repo.GetAllForeignKeys().Where(c => c.ConstraintTableName == _tableName).ToList(); } @@ -29,12 +27,12 @@ public List GetConstraints() public void DropConstraints() { - using (var repo = new DBRepository(_connectionString)) + using (var repo = new DbRepository(_connectionString)) { var constraints = repo.GetAllForeignKeys().Where(c => c.ConstraintTableName == _tableName).ToArray(); foreach (var constraint in constraints) { - var generator = new Generator(repo); + var generator = new Generator(); generator.GenerateForeignKeyDrop(constraint); repo.RunCommand(generator.GeneratedScript); } @@ -44,25 +42,22 @@ public void DropConstraints() public string GetAddConstraintStatements(List constraints) { var script = string.Empty; - using (var repo = new DBRepository(_connectionString)) + foreach (var constraint in constraints) { - foreach (var constraint in constraints) - { - var generator = new Generator(repo); - generator.GenerateForeignKey(constraint); - script = script + generator.GeneratedScript + Environment.NewLine; - } + var generator = new Generator(); + generator.GenerateForeignKey(constraint); + script = script + generator.GeneratedScript + Environment.NewLine; } return script; } public void AddConstraints(List constraints) { - using (var repo = new DBRepository(_connectionString)) + using (var repo = new DbRepository(_connectionString)) { foreach (var constraint in constraints) { - var generator = new Generator(repo); + var generator = new Generator(); generator.GenerateForeignKey(constraint); repo.RunCommand(generator.GeneratedScript); } diff --git a/src/ForeignKeyLib/Generator.cs b/src/ForeignKeyLib/Generator.cs index 4ce71b5..601b3cc 100644 --- a/src/ForeignKeyLib/Generator.cs +++ b/src/ForeignKeyLib/Generator.cs @@ -1,8 +1,7 @@ using System; -using System.Collections.Generic; using System.Text; -namespace ErikEJ.SqlCeScripting +namespace ErikEJ.SqlCe.ForeignKeyLib { /// /// Class for generating scripts @@ -11,12 +10,9 @@ namespace ErikEJ.SqlCeScripting public class Generator : IGenerator { private readonly StringBuilder _sbScript; - private readonly List _allForeignKeys; - - public Generator(IRepository repository) + public Generator() { _sbScript = new StringBuilder(10485760); - _allForeignKeys = repository.GetAllForeignKeys(); } public void GenerateForeignKey(Constraint constraint) diff --git a/src/ForeignKeyLib/IGenerator.cs b/src/ForeignKeyLib/IGenerator.cs index 984615b..6fc8ed5 100644 --- a/src/ForeignKeyLib/IGenerator.cs +++ b/src/ForeignKeyLib/IGenerator.cs @@ -1,4 +1,4 @@ -namespace ErikEJ.SqlCeScripting +namespace ErikEJ.SqlCe.ForeignKeyLib { public interface IGenerator { diff --git a/src/ForeignKeyLib/IRepository.cs b/src/ForeignKeyLib/IRepository.cs index 0c9a837..e84ac26 100644 --- a/src/ForeignKeyLib/IRepository.cs +++ b/src/ForeignKeyLib/IRepository.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace ErikEJ.SqlCeScripting +namespace ErikEJ.SqlCe.ForeignKeyLib { public interface IRepository : IDisposable { diff --git a/src/ForeignKeyLib/RepositoryHelper.cs b/src/ForeignKeyLib/RepositoryHelper.cs index b358a73..c04306f 100644 --- a/src/ForeignKeyLib/RepositoryHelper.cs +++ b/src/ForeignKeyLib/RepositoryHelper.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.Linq; -namespace ErikEJ.SqlCeScripting +namespace ErikEJ.SqlCe.ForeignKeyLib { - public class RepositoryHelper + internal class RepositoryHelper { // Contrib from hugo on CodePlex - thanks! public static List GetGroupForeingKeys(List foreignKeys, List allTables) diff --git a/src/ISqlCeBulkCopyInsertAdapter.cs b/src/ISqlCeBulkCopyInsertAdapter.cs index d8db55d..d56ac70 100644 --- a/src/ISqlCeBulkCopyInsertAdapter.cs +++ b/src/ISqlCeBulkCopyInsertAdapter.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace ErikEJ.SqlCe +namespace ErikEJ.SqlCe { /// /// Interface used by the adapters so we are able to remove the duplicate code. diff --git a/src/SqlCeBulkCopy.cs b/src/SqlCeBulkCopy.cs index c7f219f..d87528d 100644 --- a/src/SqlCeBulkCopy.cs +++ b/src/SqlCeBulkCopy.cs @@ -4,6 +4,8 @@ using System.Globalization; using System.Collections.Generic; using System.Collections; +using ErikEJ.SqlCe.ForeignKeyLib; +using Constraint = ErikEJ.SqlCe.ForeignKeyLib.Constraint; #if PocketPC #else using Salient.Data; @@ -16,22 +18,22 @@ namespace ErikEJ.SqlCe [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Ce")] public class SqlCeBulkCopy : IDisposable { - private static readonly Type DbNullType = typeof(System.DBNull); + private static readonly Type DbNullType = typeof(DBNull); private SqlCeBulkCopyColumnMappingCollection mappings = new SqlCeBulkCopyColumnMappingCollection(); - private int notifyAfter; - private long autoIncNext; - private readonly SqlCeConnection conn; - private readonly SqlCeTransaction trans; - private readonly bool ownsConnection; - private bool ownsTransaction; - private readonly bool keepNulls; - private readonly bool keepIdentity; - private string destination; - private readonly SqlCeBulkCopyOptions options; + private int _notifyAfter; + private long _autoIncNext; + private readonly SqlCeConnection _conn; + private readonly SqlCeTransaction _trans; + private readonly bool _ownsConnection; + private bool _ownsTransaction; + private readonly bool _keepNulls; + private readonly bool _keepIdentity; + private string _destination; + private readonly SqlCeBulkCopyOptions _sqlCeBulkCopyOptions; #if PocketPC #else - private List savedConstraints; - private bool disableConstraints; + private List _savedConstraints; + private readonly bool _disableConstraints; #endif /// /// Initializes a new instance of the SqlCeBulkCopy class using the specified open instance of SqlCeConnection. @@ -39,7 +41,7 @@ public class SqlCeBulkCopy : IDisposable /// public SqlCeBulkCopy(SqlCeConnection connection) { - conn = connection; + _conn = connection; } /// /// Initializes a new instance of the SqlCeBulkCopy class using the specified open instance of SqlCeConnection and the specified active SqlCeTransaction. @@ -48,8 +50,8 @@ public SqlCeBulkCopy(SqlCeConnection connection) /// public SqlCeBulkCopy(SqlCeConnection connection, SqlCeTransaction transaction) { - conn = connection; - trans = transaction; + _conn = connection; + _trans = transaction; } /// @@ -59,13 +61,13 @@ public SqlCeBulkCopy(SqlCeConnection connection, SqlCeTransaction transaction) /// public SqlCeBulkCopy(SqlCeConnection connection, SqlCeBulkCopyOptions copyOptions) { - conn = connection; - options = copyOptions; - keepNulls = IsCopyOption(SqlCeBulkCopyOptions.KeepNulls); - keepIdentity = IsCopyOption(SqlCeBulkCopyOptions.KeepIdentity); + _conn = connection; + _sqlCeBulkCopyOptions = copyOptions; + _keepNulls = IsCopyOption(SqlCeBulkCopyOptions.KeepNulls); + _keepIdentity = IsCopyOption(SqlCeBulkCopyOptions.KeepIdentity); #if PocketPC #else - disableConstraints = IsCopyOption(SqlCeBulkCopyOptions.DisableConstraints); + _disableConstraints = IsCopyOption(SqlCeBulkCopyOptions.DisableConstraints); #endif } @@ -77,14 +79,14 @@ public SqlCeBulkCopy(SqlCeConnection connection, SqlCeBulkCopyOptions copyOption /// public SqlCeBulkCopy(SqlCeConnection connection, SqlCeBulkCopyOptions copyOptions, SqlCeTransaction transaction) { - conn = connection; - trans = transaction; - options = copyOptions; - keepNulls = IsCopyOption(SqlCeBulkCopyOptions.KeepNulls); - keepIdentity = IsCopyOption(SqlCeBulkCopyOptions.KeepIdentity); + _conn = connection; + _trans = transaction; + _sqlCeBulkCopyOptions = copyOptions; + _keepNulls = IsCopyOption(SqlCeBulkCopyOptions.KeepNulls); + _keepIdentity = IsCopyOption(SqlCeBulkCopyOptions.KeepIdentity); #if PocketPC #else - disableConstraints = IsCopyOption(SqlCeBulkCopyOptions.DisableConstraints); + _disableConstraints = IsCopyOption(SqlCeBulkCopyOptions.DisableConstraints); #endif } @@ -94,8 +96,8 @@ public SqlCeBulkCopy(SqlCeConnection connection, SqlCeBulkCopyOptions copyOption /// public SqlCeBulkCopy(string connectionString) { - conn = new SqlCeConnection(connectionString); - ownsConnection = true; + _conn = new SqlCeConnection(connectionString); + _ownsConnection = true; } /// /// Initializes a new instance of the SqlCeBulkCopy class, using the specified connection string and options @@ -104,14 +106,14 @@ public SqlCeBulkCopy(string connectionString) /// public SqlCeBulkCopy(string connectionString, SqlCeBulkCopyOptions copyOptions) { - conn = new SqlCeConnection(connectionString); - ownsConnection = true; - options = copyOptions; - keepNulls = IsCopyOption(SqlCeBulkCopyOptions.KeepNulls); - keepIdentity = IsCopyOption(SqlCeBulkCopyOptions.KeepIdentity); + _conn = new SqlCeConnection(connectionString); + _ownsConnection = true; + _sqlCeBulkCopyOptions = copyOptions; + _keepNulls = IsCopyOption(SqlCeBulkCopyOptions.KeepNulls); + _keepIdentity = IsCopyOption(SqlCeBulkCopyOptions.KeepIdentity); #if PocketPC #else - disableConstraints = IsCopyOption(SqlCeBulkCopyOptions.DisableConstraints); + _disableConstraints = IsCopyOption(SqlCeBulkCopyOptions.DisableConstraints); #endif } @@ -122,11 +124,11 @@ public string DestinationTableName { get { - return destination; + return _destination; } set { - destination = value; + _destination = value; } } /// @@ -158,7 +160,7 @@ public int NotifyAfter { get { - return notifyAfter; + return _notifyAfter; } set { @@ -166,7 +168,7 @@ public int NotifyAfter { throw new ArgumentOutOfRangeException("value", "Must be > 0"); } - notifyAfter = value; + _notifyAfter = value; } } @@ -181,9 +183,9 @@ public int NotifyAfter /// public void Close() { - if (ownsConnection && conn != null) + if (_ownsConnection && _conn != null) { - conn.Dispose(); + _conn.Dispose(); } } @@ -234,7 +236,7 @@ public void WriteToServer(IDataReader reader) /// IEnumerable<>. For IEnumerable use other constructor and specify type. public void WriteToServer(IEnumerable collection) { - using (var reader = new Salient.Data.EnumerableDataReader(collection)) + using (var reader = new EnumerableDataReader(collection)) { WriteToServer(new SqlCeBulkCopyDataReaderAdapter(reader)); } @@ -252,7 +254,7 @@ public void WriteToServer(IEnumerable collection, Type elementType) { throw new ArgumentNullException("collection"); } - using (var reader = new Salient.Data.EnumerableDataReader(collection, elementType)) + using (var reader = new EnumerableDataReader(collection, elementType)) { WriteToServer(new SqlCeBulkCopyDataReaderAdapter(reader)); } @@ -262,37 +264,37 @@ private void WriteToServer(ISqlCeBulkCopyInsertAdapter adapter) { CheckDestination(); - if (conn.State != ConnectionState.Open) + if (_conn.State != ConnectionState.Open) { - conn.Open(); + _conn.Open(); } GetAndDropConstraints(); - List> map = null; + List> map; int totalRows = 0; - SqlCeTransaction localTrans = trans ?? conn.BeginTransaction(); + SqlCeTransaction localTrans = _trans ?? _conn.BeginTransaction(); if (ColumnMappings.Count > 0) { //mapping are set, and should be validated - map = ColumnMappings.ValidateCollection(conn, localTrans, adapter, options, destination); + map = ColumnMappings.ValidateCollection(_conn, localTrans, adapter, _sqlCeBulkCopyOptions, _destination); } else { //create default column mappings - map = SqlCeBulkCopyColumnMappingCollection.Create(conn, localTrans, adapter, options, destination); + map = SqlCeBulkCopyColumnMappingCollection.Create(_conn, localTrans, adapter, _sqlCeBulkCopyOptions, _destination); } - using (SqlCeCommand cmd = new SqlCeCommand(destination, conn, localTrans)) + using (var cmd = new SqlCeCommand(_destination, _conn, localTrans)) { cmd.CommandType = CommandType.TableDirect; - using (SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable)) + using (var rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable)) { - int idOrdinal = SqlCeBulkCopyTableHelpers.IdentityOrdinal(conn, localTrans, destination); - SqlCeUpdatableRecord rec = rs.CreateRecord(); + var idOrdinal = SqlCeBulkCopyTableHelpers.IdentityOrdinal(_conn, localTrans, _destination); + var rec = rs.CreateRecord(); - int rowCounter = 0; + var rowCounter = 0; IdInsertOn(localTrans, idOrdinal); //Converting to an array removed the perf issue of a list and foreach statement. @@ -303,14 +305,14 @@ private void WriteToServer(ISqlCeBulkCopyInsertAdapter adapter) if (adapter.SkipRow()) continue; - for (int i = 0; i < cm.Length; i++) + for (var i = 0; i < cm.Length; i++) { //caching the values this way do not cause a perf issue. var sourceIndex = cm[i].Key; var destIndex = cm[i].Value; // Let the destination assign identity values - if (!keepIdentity && destIndex == idOrdinal) + if (!_keepIdentity && destIndex == idOrdinal) continue; //determine if we should ever allow this in the map. @@ -326,10 +328,10 @@ private void WriteToServer(ISqlCeBulkCopyInsertAdapter adapter) else { //we can't write to an auto number column so continue - if (keepNulls && destIndex == idOrdinal) + if (_keepNulls && destIndex == idOrdinal) continue; - if (keepNulls) + if (_keepNulls) { rec.SetValue(destIndex, DBNull.Value); } @@ -344,13 +346,13 @@ private void WriteToServer(ISqlCeBulkCopyInsertAdapter adapter) rowCounter++; totalRows++; rs.Insert(rec); - if (RowsCopied != null && notifyAfter > 0 && rowCounter == notifyAfter) + if (RowsCopied != null && _notifyAfter > 0 && rowCounter == _notifyAfter) { FireRowsCopiedEvent(totalRows); rowCounter = 0; } } - IdInsertOff(localTrans, idOrdinal, totalRows); + IdInsertOff(localTrans, idOrdinal); if (RowsCopied != null) { FireRowsCopiedEvent(totalRows); @@ -359,7 +361,7 @@ private void WriteToServer(ISqlCeBulkCopyInsertAdapter adapter) } //if we have our own transaction, we will commit it - if (trans == null) + if (_trans == null) { localTrans.Commit(CommitMode.Immediate); localTrans.Dispose(); @@ -370,21 +372,21 @@ private void WriteToServer(ISqlCeBulkCopyInsertAdapter adapter) private void CheckDestination() { - if (string.IsNullOrEmpty(destination)) + if (string.IsNullOrEmpty(_destination)) { throw new ArgumentException("DestinationTable not specified"); } - ownsTransaction = (trans == null); + _ownsTransaction = (_trans == null); } private void GetAndDropConstraints() { #if PocketPC #else - if (disableConstraints) + if (_disableConstraints) { - var fkRepo = new ErikEJ.SqlCeScripting.ForeignKeyRepository(conn.ConnectionString, destination); - savedConstraints = fkRepo.GetConstraints(); + var fkRepo = new ForeignKeyRepository(_conn.ConnectionString, _destination); + _savedConstraints = fkRepo.GetConstraints(); fkRepo.DropConstraints(); } #endif @@ -394,42 +396,42 @@ private void RestoreConstraints() { #if PocketPC #else - var fkRepo = new ErikEJ.SqlCeScripting.ForeignKeyRepository(conn.ConnectionString, destination); + var fkRepo = new ForeignKeyRepository(_conn.ConnectionString, _destination); try { - if (disableConstraints) + if (_disableConstraints) { - fkRepo.AddConstraints(savedConstraints); + fkRepo.AddConstraints(_savedConstraints); } } catch (SqlCeException ex) { - throw new Exception(ex.Message + Environment.NewLine + fkRepo.GetAddConstraintStatements(savedConstraints), ex); + throw new Exception(ex.Message + Environment.NewLine + fkRepo.GetAddConstraintStatements(_savedConstraints), ex); } #endif } private void IdInsertOn(SqlCeTransaction localTrans, int idOrdinal) { - if (keepIdentity && idOrdinal >= 0) + if (_keepIdentity && idOrdinal >= 0) { - using (var idCmd = AdoNetUtils.CreateCommand(conn, localTrans, string.Format(CultureInfo.InvariantCulture, "SET IDENTITY_INSERT [{0}] ON", DestinationTableName))) + using (var idCmd = AdoNetUtils.CreateCommand(_conn, localTrans, string.Format(CultureInfo.InvariantCulture, "SET IDENTITY_INSERT [{0}] ON", DestinationTableName))) { idCmd.ExecuteNonQuery(); } - if (trans == null) + if (_trans == null) { - autoIncNext = SqlCeBulkCopyTableHelpers.GetAutoIncNext(conn, DestinationTableName); + _autoIncNext = SqlCeBulkCopyTableHelpers.GetAutoIncNext(_conn, DestinationTableName); } } } - private void IdInsertOff(SqlCeTransaction localTrans, int idOrdinal, int totalRows) + private void IdInsertOff(SqlCeTransaction localTrans, int idOrdinal) { - if (keepIdentity && idOrdinal >= 0) + if (_keepIdentity && idOrdinal >= 0) { - using (var idCmd = AdoNetUtils.CreateCommand(conn, localTrans, string.Format(CultureInfo.InvariantCulture, "SET IDENTITY_INSERT [{0}] OFF", DestinationTableName))) + using (var idCmd = AdoNetUtils.CreateCommand(_conn, localTrans, string.Format(CultureInfo.InvariantCulture, "SET IDENTITY_INSERT [{0}] OFF", DestinationTableName))) { idCmd.ExecuteNonQuery(); } @@ -441,25 +443,25 @@ private void ResetSeed(int totalRows) if (totalRows == 0) return; - if (!keepIdentity) + if (!_keepIdentity) return; //Cannot run re-seed when using user supplied transaction, so fail silently - if (keepIdentity && trans != null) + if (_keepIdentity && _trans != null) { return; } - var newAutoIncNext = SqlCeBulkCopyTableHelpers.GetAutoIncNext(conn, DestinationTableName); + var newAutoIncNext = SqlCeBulkCopyTableHelpers.GetAutoIncNext(_conn, DestinationTableName); - if (autoIncNext != newAutoIncNext) + if (_autoIncNext != newAutoIncNext) return; - using (var transact = conn.BeginTransaction()) + using (var transact = _conn.BeginTransaction()) { // Get Identity column string idCol = null; - using (var ainCmd = AdoNetUtils.CreateCommand(conn, transact, string.Format(CultureInfo.InvariantCulture, + using (var ainCmd = AdoNetUtils.CreateCommand(_conn, transact, string.Format(CultureInfo.InvariantCulture, "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{0}' AND AUTOINC_INCREMENT IS NOT NULL", DestinationTableName))) { object res = ainCmd.ExecuteScalar(); @@ -473,7 +475,7 @@ private void ResetSeed(int totalRows) // Get Max value if the column long? maxVal = null; - using (var ainCmd = AdoNetUtils.CreateCommand(conn, transact, string.Format(CultureInfo.InvariantCulture, + using (var ainCmd = AdoNetUtils.CreateCommand(_conn, transact, string.Format(CultureInfo.InvariantCulture, "SELECT CAST(MAX([{0}]) AS bigint) FROM [{1}]", idCol, DestinationTableName))) { object res = ainCmd.ExecuteScalar(); @@ -486,7 +488,7 @@ private void ResetSeed(int totalRows) return; //Reseed - using (var ainCmd = AdoNetUtils.CreateCommand(conn, transact, string.Format(CultureInfo.InvariantCulture, + using (var ainCmd = AdoNetUtils.CreateCommand(_conn, transact, string.Format(CultureInfo.InvariantCulture, "ALTER TABLE [{0}] ALTER COLUMN [{1}] IDENTITY ({2},1);", DestinationTableName, idCol, maxVal + 1))) { ainCmd.ExecuteNonQuery(); @@ -511,7 +513,7 @@ private void FireRowsCopiedEvent(long rowsCopied) private bool IsCopyOption(SqlCeBulkCopyOptions copyOption) { - return ((options & copyOption) == copyOption); + return ((_sqlCeBulkCopyOptions & copyOption) == copyOption); } #region IDisposable Members @@ -524,13 +526,13 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - if (ownsConnection && conn != null) + if (_ownsConnection && _conn != null) { - conn.Dispose(); + _conn.Dispose(); } - if (ownsTransaction && trans != null) + if (_ownsTransaction && _trans != null) { - trans.Dispose(); + _trans.Dispose(); } } } diff --git a/src/SqlCeBulkCopyColumnMapping.cs b/src/SqlCeBulkCopyColumnMapping.cs index dd290db..b865ccd 100644 --- a/src/SqlCeBulkCopyColumnMapping.cs +++ b/src/SqlCeBulkCopyColumnMapping.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace ErikEJ.SqlCe { @@ -26,8 +24,8 @@ public SqlCeBulkCopyColumnMapping() /// /// Creates a new column mapping, using column ordinals to refer to source and destination columns. /// - /// - /// + /// + /// public SqlCeBulkCopyColumnMapping(int sourceColumnIndex, int destinationColumnIndex) { SourceOrdinal = sourceColumnIndex; @@ -37,7 +35,7 @@ public SqlCeBulkCopyColumnMapping(int sourceColumnIndex, int destinationColumnIn /// /// Creates a new column mapping, using a column ordinal to refer to the source column and a column name for the target column. /// - /// + /// /// public SqlCeBulkCopyColumnMapping(int sourceColumnIndex, string destinationColumn) { @@ -49,7 +47,7 @@ public SqlCeBulkCopyColumnMapping(int sourceColumnIndex, string destinationColum /// Creates a new column mapping, using a column name to refer to the source column and a column ordinal for the target column. /// /// - /// + /// public SqlCeBulkCopyColumnMapping(string sourceColumn, int destinationColumnIndex) { SourceColumn = sourceColumn; diff --git a/src/SqlCeBulkCopyDataReaderAdapter.cs b/src/SqlCeBulkCopyDataReaderAdapter.cs index ae8d643..0b05b13 100644 --- a/src/SqlCeBulkCopyDataReaderAdapter.cs +++ b/src/SqlCeBulkCopyDataReaderAdapter.cs @@ -1,13 +1,11 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Data; namespace ErikEJ.SqlCe { internal sealed class SqlCeBulkCopyDataReaderAdapter : ISqlCeBulkCopyInsertAdapter { - private readonly IDataReader _reader = null; + private readonly IDataReader _reader; public int FieldCount { diff --git a/src/SqlCeBulkCopyDataTableAdapter.cs b/src/SqlCeBulkCopyDataTableAdapter.cs index ec7781b..28b2719 100644 --- a/src/SqlCeBulkCopyDataTableAdapter.cs +++ b/src/SqlCeBulkCopyDataTableAdapter.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Text; using System.Data; -using System.Collections; namespace ErikEJ.SqlCe { diff --git a/src/SqlCeBulkCopyMappingCollection.cs b/src/SqlCeBulkCopyMappingCollection.cs index 62d2903..4e0856c 100644 --- a/src/SqlCeBulkCopyMappingCollection.cs +++ b/src/SqlCeBulkCopyMappingCollection.cs @@ -1,9 +1,7 @@ using System; using System.Collections.ObjectModel; using System.Collections.Generic; -using System.Data; using System.Data.SqlServerCe; -using System.Collections; using System.Globalization; namespace ErikEJ.SqlCe @@ -131,7 +129,7 @@ internal List> ValidateCollection(SqlCeConnection conn, S var sourceColumns = GetSourceColumns(adapter); var destColumns = ToColumnNames(DestinationTableDefaultMetadata.GetDataForTable(conn, transaction, tableName)); - foreach (SqlCeBulkCopyColumnMapping mapping in this.Items) + foreach (SqlCeBulkCopyColumnMapping mapping in Items) { var sourceColumnName = (mapping.SourceColumn ?? string.Empty).ToUpper(CultureInfo.InvariantCulture); var destColumnName = (mapping.DestinationColumn ?? string.Empty).ToUpper(CultureInfo.InvariantCulture); diff --git a/src/SqlCeBulkCopyTableHelpers.cs b/src/SqlCeBulkCopyTableHelpers.cs index 31d0992..30e9df8 100644 --- a/src/SqlCeBulkCopyTableHelpers.cs +++ b/src/SqlCeBulkCopyTableHelpers.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Data.SqlServerCe; +using System.Data.SqlServerCe; using System.Globalization; namespace ErikEJ.SqlCe diff --git a/src/SqlCeRowsCopiedEventArgs.cs b/src/SqlCeRowsCopiedEventArgs.cs index 3f9996c..09d0099 100644 --- a/src/SqlCeRowsCopiedEventArgs.cs +++ b/src/SqlCeRowsCopiedEventArgs.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace ErikEJ.SqlCe { @@ -46,7 +44,5 @@ public bool Abort _abort = value; } } - } - } diff --git a/src/Test/SqlCeBulkCopyTest.cs b/src/Test/SqlCeBulkCopyTest.cs index ee69831..0cc70a6 100644 --- a/src/Test/SqlCeBulkCopyTest.cs +++ b/src/Test/SqlCeBulkCopyTest.cs @@ -8,6 +8,7 @@ using System.Globalization; using System.Collections.Generic; using System.Linq; +using ErikEJ.SqlCe.ForeignKeyLib; namespace ErikEJ.SqlCe { @@ -504,7 +505,7 @@ public void Test_DisableConstraints_Enabled_Timing() bc.WriteToServer(GetTestInvoiceLineTable(connString)); sw.Stop(); Debug.WriteLine("Without constraints: " + sw.ElapsedMilliseconds); - var fkRepo = new SqlCeScripting.ForeignKeyRepository(connString, "InvoiceLine"); + var fkRepo = new ForeignKeyRepository(connString, "InvoiceLine"); var savedConstraints = fkRepo.GetConstraints(); Assert.IsTrue(savedConstraints.Count == 2); }