aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs')
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/SqliteDataBase.cs58
1 files changed, 58 insertions, 0 deletions
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();