aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Synchronization/Local
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2017-11-29 20:37:05 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2017-11-29 20:37:05 +0200
commitcfb92ea5e80b1af847829a76ab3c9ed7f52ae2c4 (patch)
tree10aae33b609f8adc654f00597fcd902faeee8fd9 /Software/Visual_Studio/Tango.Synchronization/Local
parent1348ceabdd5d93b78f7f0d9295a5b3424ae93962 (diff)
downloadTango-cfb92ea5e80b1af847829a76ab3c9ed7f52ae2c4.tar.gz
Tango-cfb92ea5e80b1af847829a76ab3c9ed7f52ae2c4.zip
Fixed an issue with boolean values on local DB sync.
Added support for SYNC_CONFIGURATION table on for local DB sync. Fixed an issue with multiple row updates on remote DB sync. Added warning for missing destination property on remote DB sync. Throw exception when no remote machine found on remote DB sync.
Diffstat (limited to 'Software/Visual_Studio/Tango.Synchronization/Local')
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs3
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs12
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs32
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs58
4 files changed, 103 insertions, 2 deletions
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs b/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
index ed8084301..5557c43c8 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/Constants.cs
@@ -14,6 +14,9 @@ namespace Tango.Synchronization.Local
public const String COLUMN_TYPE = "type";
public const String IS_NOT_NULL = "notnull";
public const String DEFAULT_VALUE = "dflt_value";
+ public const String SYNC_CONFIGURATIONS_TABLE_NAME = "SYNC_CONFIGURATION";
+ public const String SYNC_CONFIGURATION_TABLE_NAME_COLUMN = "TABLE_NAME";
+ public const String SYNC_CONFIGURATION_SYNC_TYPE_COLUMN = "SYNC_TYPE";
//Must Column Names.
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs b/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
index 7e53aeb1c..66b111467 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/ILocalDataBase.cs
@@ -37,6 +37,18 @@ namespace Tango.Synchronization.Local
DataTable CloneTableFrom(ILocalDataBase otherDB, DataTable otherTable);
/// <summary>
+ /// Replaces the table data with the data from another table.
+ /// </summary>
+ /// <param name="otherTable">The other table.</param>
+ void ReplaceTableData(ILocalDataBase otherDB, DataTable otherTable);
+
+ /// <summary>
+ /// Replaces the table data with the data from another table.
+ /// </summary>
+ /// <param name="otherTable">The other table.</param>
+ String GetReplaceTableDataCommand(ILocalDataBase otherDB, DataTable otherTable);
+
+ /// <summary>
/// Gets the SQL command for <see cref="CloneTableFrom(ILocalDataBase, DataTable)"/>.
/// </summary>
/// <param name="otherDB">The other database.</param>
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs b/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
index 63f2ecfaa..7883f9cc8 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/LocalDBComparer.cs
@@ -13,7 +13,7 @@ namespace Tango.Synchronization.Local
/// Represents an <see cref="ILocalDataBase"/> synchronization engine.
/// </summary>
/// <seealso cref="System.IDisposable" />
- public class LocalDBComparer : IDisposable
+ public class LocalDBComparer : IDBComparer
{
/// <summary>
/// Gets the master SQL.
@@ -52,7 +52,35 @@ namespace Tango.Synchronization.Local
List<Diff> diffs = new List<Diff>();
- foreach (var masterTable in MasterSQL.Tables)
+ DataTable sync_table = MasterSQL.Tables.Single(x => x.TableName == Constants.SYNC_CONFIGURATIONS_TABLE_NAME);
+
+ List<DataTable> sync_tables = new List<DataTable>();
+ List<DataTable> overwrite_tables = new List<DataTable>();
+
+ foreach (var row in sync_table.AsEnumerable())
+ {
+ if ((SyncConfiguration)row.Field<Int64>(Constants.SYNC_CONFIGURATION_SYNC_TYPE_COLUMN) == SyncConfiguration.Synchronize)
+ {
+ sync_tables.Add(MasterSQL.Tables.Single(x => x.TableName == row.Field<String>(Constants.SYNC_CONFIGURATION_TABLE_NAME_COLUMN)));
+ }
+ else
+ {
+ overwrite_tables.Add(MasterSQL.Tables.Single(x => x.TableName == row.Field<String>(Constants.SYNC_CONFIGURATION_TABLE_NAME_COLUMN)));
+ }
+ }
+
+ foreach (var masterTable in overwrite_tables)
+ {
+ LogManager.Log("Generating table overwrite difference for table " + masterTable.TableName);
+ diffs.Add(new Diff(DiffAction.ReplaceTableDataInSlave, "Replace all rows on slave table " + masterTable.TableName, () =>
+ {
+
+ SlaveSQL.ReplaceTableData(MasterSQL, masterTable);
+
+ }, SlaveSQL.GetReplaceTableDataCommand(MasterSQL, masterTable)));
+ }
+
+ foreach (var masterTable in sync_tables)
{
LogManager.Log("Comparing table " + masterTable.TableName);
LogManager.Log("Searching table " + masterTable.TableName + " on slave...");
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs b/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
index 35e54c66a..83a14b493 100644
--- a/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
@@ -148,6 +148,44 @@ namespace Tango.Synchronization.Local
}
/// <summary>
+ /// Replaces the table data with the data from another table.
+ /// </summary>
+ /// <param name="otherTable">The other table.</param>
+ public void ReplaceTableData(ILocalDataBase otherDB, DataTable otherTable)
+ {
+ var dropCommand = _connection.CreateCommand();
+ dropCommand.CommandText = String.Format("DELETE FROM {0};", otherTable.TableName);
+ dropCommand.ExecuteNonQuery();
+
+ var attacheCommand = _connection.CreateCommand();
+ attacheCommand.CommandText = String.Format("ATTACH DATABASE '{0}' AS other;", otherDB.Source);
+ attacheCommand.ExecuteNonQuery();
+
+ var copyCommand = _connection.CreateCommand();
+ copyCommand.CommandText = String.Format("INSERT INTO main.{0} SELECT * FROM {1}.{0};", otherTable.TableName, "other");
+ copyCommand.ExecuteNonQuery();
+
+ var detacheCommand = _connection.CreateCommand();
+ detacheCommand.CommandText = "DETACH other;";
+ detacheCommand.ExecuteNonQuery();
+ }
+
+ /// <summary>
+ /// Gets the SQL command for <see cref="ReplaceTableData(ILocalDataBase, DataTable)"/>.
+ /// </summary>
+ /// <param name="otherDB"></param>
+ /// <param name="otherTable">The other table.</param>
+ /// <returns></returns>
+ public string GetReplaceTableDataCommand(ILocalDataBase otherDB, DataTable otherTable)
+ {
+ String cmd = String.Format("DELETE FROM {0};", otherTable.TableName) + Environment.NewLine;
+ cmd += String.Format("ATTACH DATABASE '{0}' AS other;", otherDB.Source) + Environment.NewLine;
+ cmd += String.Format("INSERT INTO main.{0} SELECT * FROM {1}.{0};", otherTable.TableName, "other") + Environment.NewLine;
+ cmd += "DETACH other;" + Environment.NewLine;
+ return cmd;
+ }
+
+ /// <summary>
/// Gets the SQL command for <see cref="CloneTableFrom(ILocalDataBase, DataTable)" />.
/// </summary>
/// <param name="otherDB">The other database.</param>
@@ -252,6 +290,11 @@ namespace Tango.Synchronization.Local
double num = 0;
+ if (row.ItemArray[i].GetType() == typeof(bool))
+ {
+ value = ((bool)row.ItemArray[i]) ? 1.ToString() : 0.ToString();
+ }
+
if (row.ItemArray[i].GetType() == typeof(DateTime))
{
value = ((DateTime)row.ItemArray[i]).ToSQLiteDateString();
@@ -288,6 +331,11 @@ namespace Tango.Synchronization.Local
double num = 0;
+ if (row.ItemArray[i].GetType() == typeof(bool))
+ {
+ value = ((bool)row.ItemArray[i]) ? 1.ToString() : 0.ToString();
+ }
+
if (row.ItemArray[i].GetType() == typeof(DateTime))
{
value = ((DateTime)row.ItemArray[i]).ToSQLiteDateString();
@@ -322,6 +370,11 @@ namespace Tango.Synchronization.Local
double num = 0;
+ if (row.ItemArray[i].GetType() == typeof(bool))
+ {
+ value = ((bool)row.ItemArray[i]) ? 1.ToString() : 0.ToString();
+ }
+
if (row.ItemArray[i].GetType() == typeof(DateTime))
{
value = ((DateTime)row.ItemArray[i]).ToSQLiteDateString();
@@ -382,6 +435,11 @@ namespace Tango.Synchronization.Local
double num = 0;
+ if (row.ItemArray[i].GetType() == typeof(bool))
+ {
+ value = ((bool)row.ItemArray[i]) ? 1.ToString() : 0.ToString();
+ }
+
if (row.ItemArray[i].GetType() == typeof(DateTime))
{
value = ((DateTime)row.ItemArray[i]).ToSQLiteDateString();