diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-10 15:24:06 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-10 15:24:06 +0300 |
| commit | 5d795170b304199383ac967583830acaf313ff05 (patch) | |
| tree | f8888b3ae72410a02a4b7361c235540138950ac8 /Software/Visual_Studio/Tango.Core/Components | |
| parent | 9244c34a40d572f071cdf1c00ad6428132e1ab5c (diff) | |
| download | Tango-5d795170b304199383ac967583830acaf313ff05.tar.gz Tango-5d795170b304199383ac967583830acaf313ff05.zip | |
Some work on PPC.
Implemented retrieval of column description for auto generated observables & pmr's.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/Components')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Components/DataBaseDescriptionsHelper.cs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Components/DataBaseDescriptionsHelper.cs b/Software/Visual_Studio/Tango.Core/Components/DataBaseDescriptionsHelper.cs new file mode 100644 index 000000000..0f1193c6c --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Components/DataBaseDescriptionsHelper.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.Components +{ + public static class DataBaseDescriptionsHelper + { + public class DbDescription + { + public String TableName { get; set; } + public String ColumnName { get; set; } + public String TableDescription { get; set; } + public String ColumnDescription { get; set; } + } + + public static List<DbDescription> GetDescriptions(DbConnection connection) + { + List<DbDescription> dbDescriptions = new List<DbDescription>(); + + var command = connection.CreateCommand(); + command.CommandText = @"SELECT u.name + '.' + t.name AS [table], + td.value AS [table_desc], + c.name AS [column], + cd.value AS [column_desc] +FROM sysobjects t +INNER JOIN sysusers u + ON u.uid = t.uid +LEFT OUTER JOIN sys.extended_properties td + ON td.major_id = t.id + AND td.minor_id = 0 + AND td.name = 'MS_Description' +INNER JOIN syscolumns c + ON c.id = t.id +LEFT OUTER JOIN sys.extended_properties cd + ON cd.major_id = c.id + AND cd.minor_id = c.colid + AND cd.name = 'MS_Description' +WHERE t.type = 'u' +ORDER BY t.name, c.colorder"; + + DataTable table = new DataTable(); + table.Load(command.ExecuteReader()); + + foreach (var row in table.Rows.OfType<DataRow>()) + { + String table_name = row.ItemArray.GetValue(0).ToString().Replace("dbo.", ""); + String table_decription = row.ItemArray.GetValue(1).ToString(); + String column_name = row.ItemArray.GetValue(2).ToString(); + String column_description = row.ItemArray.GetValue(3).ToString(); + + if (!String.IsNullOrWhiteSpace(table_decription) || !String.IsNullOrWhiteSpace(column_description)) + { + dbDescriptions.Add(new DbDescription() + { + TableName = table_name, + TableDescription = table_decription, + ColumnName = column_name, + ColumnDescription = column_description, + }); + } + } + + return dbDescriptions; + } + } +} |
