public void TestReplicateMultipleRounds() { var srcConnStr = Settings.Default.SqlConnectionString; using var replicator = new SQLiteDataReplicator <SqlClientSourceAdapter>(srcConnStr, SQLiteConnectionString) { ParallelismLevel = 2 }; replicator.AddSourceTable(TableNameSITES, SelectFromSitesOrderByIid); replicator.AddSourceTable(TableNameTIME, SelectTop1000FromTimeOrderByIid); replicator.AddSourceTable(TableNameATimesheet, SelectTop1000FromATimesheetOrderBySeq); replicator.AddSourceTable(TableNameASchedule, SelectTop1000FromAScheduleOrderBySeq); replicator.AddSourceTable(TableNamePM_DIST, SelectTop1000FromPmDistOrderByIid, new [] { "CREATE INDEX PM_DIST_CEMPID ON PM_DIST(CEMPID)" }); var connection = new SqlConnection(srcConnStr); var pmLogCmd = new SqlCommand(SelectTop1000FromPmLogOrderByIid, connection); replicator.AddSourceTable(TableNamePM_LOG, pmLogCmd); // Here we Add a command to the list of tables. command could be created with extension method CreateBulkQueryCommand replicator.AddSourceTable(TableNameAUDITLOG, SelectTop1000FromAuditlogOrderByIid); replicator.AddSourceTable(TableNameAPPROVPR, SelectTop1000FromApprovprOrderByIid); replicator.Prepare(); Assert.AreEqual(8, replicator.SourceCommandCount); for (var i = 0; i < 5; i++) { // Can't use the Source Connection if a reader still open. Need to check readers before creating new commands // In this example we replace only the dataset index 1 replicator.CloseReader(1); var cmd = ((SqlConnection)replicator.SourceConnections[1]).CreateBulkQueryCommand("SELECT TOP 10 * FROM TIME WHERE IID IN (@@@Params) ORDER BY IID", new object[] { i + 18 }); replicator.SourceCommand[1] = cmd; // Every loop we can replace the source command with a new one linked to the new dataset we intend to replicate replicator.Replicate(1000, 1); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectFromSitesOrderByIid, SQLiteConnectionString, SelectFromSitesOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, $"SELECT TOP 10 * FROM TIME WHERE IID IN ({i + 18}) ORDER BY IID", SQLiteConnectionString, $"SELECT * FROM TIME WHERE IID IN ({i + 18}) ORDER BY IID"); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop1000FromATimesheetOrderBySeq, SQLiteConnectionString, SelectAllFromATimesheetOrderBySeq); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop1000FromAScheduleOrderBySeq, SQLiteConnectionString, SelectAllFromAScheduleOrderBySeq); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop1000FromPmDistOrderByIid, SQLiteConnectionString, SelectAllFromPmDistOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop1000FromPmLogOrderByIid, SQLiteConnectionString, SelectAllFromPmLogOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop1000FromAuditlogOrderByIid, SQLiteConnectionString, SelectAllFromAuditlogOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop1000FromApprovprOrderByIid, SQLiteConnectionString, SelectAllFromApprovprOrderByIid); } replicator.UnPrepare(); }
public void TestBasicReplicate() { using var baseConn = new SQLiteConnection(SQLiteConnectionString); baseConn.Open(); using var replicator = new SQLiteDataReplicator <SqlClientSourceAdapter>( Settings.Default.SqlConnectionString, SQLiteConnectionString) { ParallelismLevel = 2 }; replicator.AddSourceTable(SelectFromSitesOrderByIid); replicator.AddSourceTable(SelectTop10000FromTimeOrderByIid); replicator.AddSourceTable(SelectTop10000FromATimesheetOrderBySeq); replicator.AddSourceTable(SelectTop10000FromAScheduleOrderBySeq); replicator.AddSourceTable(SelectTop10000FromPmDistOrderByIid); replicator.AddSourceTable(SelectTop10000FromPmLogOrderByIid); replicator.AddSourceTable(SelectTop10000FromAuditlogOrderByIid); replicator.AddSourceTable(SelectTop10000FromApprovprOrderByIid); replicator.ReplicateMode = SQLiteDataReplicator <SqlClientSourceAdapter> .ReplicateModes.DropTableAndPump; replicator.Prepare(); replicator.Replicate(1000, 1); replicator.UnPrepare(); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectFromSitesOrderByIid, SQLiteConnectionString, SelectFromSitesOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop10000FromTimeOrderByIid, SQLiteConnectionString, SelectAllFromTimeOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop10000FromAScheduleOrderBySeq, SQLiteConnectionString, SelectAllFromAScheduleOrderBySeq); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop10000FromPmDistOrderByIid, SQLiteConnectionString, SelectAllFromPmDistOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop10000FromPmLogOrderByIid, SQLiteConnectionString, SelectAllFromPmLogOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop10000FromAuditlogOrderByIid, SQLiteConnectionString, SelectAllFromAuditlogOrderByIid); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectTop10000FromApprovprOrderByIid, SQLiteConnectionString, SelectAllFromApprovprOrderByIid); }
public void TestBasicReplicateWithoutTransactions() { using var baseConn = new SQLiteConnection(SQLiteConnectionString); baseConn.Open(); using var replicator = new SQLiteDataReplicator <SqlClientSourceAdapter>( Settings.Default.SqlConnectionString2ndDatabase, SQLiteConnectionString) { ParallelismLevel = 2 }; replicator.AddSourceTable(TableNameSITES, SelectFromSitesOrderByIid); replicator.UseTransaction = false; replicator.Prepare(); replicator.ReplicateMode = SQLiteDataReplicator <SqlClientSourceAdapter> .ReplicateModes.DropTableAndPump; replicator.Replicate(1000, 1); replicator.UnPrepare(); Assert.That.AreEqual <SqlClientSourceAdapter, SQLiteSourceAdapter>( Settings.Default.SqlConnectionString, SelectFromSitesOrderByIid, SQLiteConnectionString, SelectFromSitesOrderByIid); }