aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs')
-rw-r--r--Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs88
1 files changed, 88 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs b/Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs
new file mode 100644
index 000000000..8746f9146
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Synchronization/Local/ExtensionMethods.cs
@@ -0,0 +1,88 @@
+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
+{
+ internal static class SQLExtensions
+ {
+ /// <summary>
+ /// Gets the type of the SQL column.
+ /// </summary>
+ /// <param name="column">The column.</param>
+ /// <returns></returns>
+ public static String GetSQLType(this DataColumn column)
+ {
+ return column.ExtendedProperties[Constants.COLUMN_TYPE].ToString();
+ }
+
+ /// <summary>
+ /// Gets the information table.
+ /// </summary>
+ /// <param name="table">The table.</param>
+ /// <returns></returns>
+ public static DataTable GetInfoTable(this DataTable table)
+ {
+ return table.ExtendedProperties[Constants.TABLE_INFO] as DataTable;
+ }
+
+ /// <summary>
+ /// Determines whether column is marked NOT NULL.
+ /// </summary>
+ /// <param name="column">The column.</param>
+ public static bool IsNotNull(this DataColumn column)
+ {
+ int value = int.Parse(column.ExtendedProperties[Constants.IS_NOT_NULL].ToString());
+ return value == 0 ? false : true;
+ }
+
+ /// <summary>
+ /// Gets the column default value.
+ /// </summary>
+ /// <param name="column">The column.</param>
+ /// <returns></returns>
+ 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.Contains("randomblob") || def.Contains("localtime"))
+ {
+ def = def.Insert(0, "(");
+ def = def.Insert(def.Length - 1, ")");
+ }
+ return def;
+ }
+ }
+
+ /// <summary>
+ /// Determines whether column definition has default value.
+ /// </summary>
+ /// <param name="column">The column.</param>
+ public static bool HasDefaultValue(this DataColumn column)
+ {
+ return !String.IsNullOrWhiteSpace(column.ExtendedProperties[Constants.DEFAULT_VALUE].ToString());
+ }
+
+ /// <summary>
+ /// Converts the DateTime instance to SQLite DateTime string.
+ /// </summary>
+ /// <param name="date">The date.</param>
+ /// <returns></returns>
+ public static String ToSQLiteDateString(this DateTime date)
+ {
+ return date.ToString("yyyy-MM-dd HH:mm:ss.fff");
+ }
+ }
+} \ No newline at end of file