using Tango.Synchronization; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tango.Synchronization.Local { /// /// Contains Database comparison and synchronization extension methods. /// internal static class SQLExtensions { /// /// Gets the type of the SQL column. /// /// The column. /// public static String GetSQLType(this DataColumn column) { return column.ExtendedProperties[Constants.COLUMN_TYPE].ToString(); } /// /// Gets the information table. /// /// The table. /// public static DataTable GetInfoTable(this DataTable table) { return table.ExtendedProperties[Constants.TABLE_INFO] as DataTable; } /// /// Determines whether column is marked NOT NULL. /// /// The column. public static bool IsNotNull(this DataColumn column) { int value = int.Parse(column.ExtendedProperties[Constants.IS_NOT_NULL].ToString()); return value == 0 ? false : true; } /// /// Gets the column default value. /// /// The column. /// public static String GetDefaultValue(this DataColumn column) { String def = column.ExtendedProperties[Constants.DEFAULT_VALUE].ToString(); double num = -1; if (double.TryParse(def, out num)) { return num.ToString(); } else { if (def.ToLower().Contains("randomblob") || def.ToLower().Contains("datetime ('now')")) { def = def.Insert(0, "("); def = def.Insert(def.Length - 1, ")"); } return def; } } /// /// Determines whether column definition has default value. /// /// The column. public static bool HasDefaultValue(this DataColumn column) { return !String.IsNullOrWhiteSpace(column.ExtendedProperties[Constants.DEFAULT_VALUE].ToString()); } /// /// Converts the DateTime instance to SQLite DateTime string. /// /// The date. /// public static String ToSQLiteDateString(this DateTime date) { return date.ToString("yyyy-MM-dd HH:mm:ss.fff"); } } }