From 5bec920df45bb79e5912a97f2d0afc1a849adbd2 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 23 Dec 2018 09:34:03 +0200 Subject: Fixed some issues with observables generator. --- .../Components/DataBaseDescriptionsHelper.cs | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'Software/Visual_Studio/Tango.Core/Components') diff --git a/Software/Visual_Studio/Tango.Core/Components/DataBaseDescriptionsHelper.cs b/Software/Visual_Studio/Tango.Core/Components/DataBaseDescriptionsHelper.cs index 0f1193c6c..620fe9dbc 100644 --- a/Software/Visual_Studio/Tango.Core/Components/DataBaseDescriptionsHelper.cs +++ b/Software/Visual_Studio/Tango.Core/Components/DataBaseDescriptionsHelper.cs @@ -18,6 +18,12 @@ namespace Tango.Core.Components public String ColumnDescription { get; set; } } + public class ForeignKeyDescription + { + public String TableName { get; set; } + public String ColumnName { get; set; } + } + public static List GetDescriptions(DbConnection connection) { List dbDescriptions = new List(); @@ -67,5 +73,30 @@ ORDER BY t.name, c.colorder"; return dbDescriptions; } + + public static List GetForeignKeys(DbConnection connection) + { + List keys = new List(); + + var command = connection.CreateCommand(); + command.CommandText = "SELECT a.TABLE_NAME, a.COLUMN_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS b JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE a ON a.CONSTRAINT_CATALOG = b.CONSTRAINT_CATALOG AND a.CONSTRAINT_NAME = b.CONSTRAINT_NAME"; + + DataTable table = new DataTable(); + table.Load(command.ExecuteReader()); + + foreach (var row in table.Rows.OfType()) + { + String table_name = row.ItemArray.GetValue(0).ToString(); + String column_name = row.ItemArray.GetValue(1).ToString(); + + keys.Add(new ForeignKeyDescription() + { + TableName = table_name, + ColumnName = column_name + }); + } + + return keys; + } } } -- cgit v1.3.1