/// <summary>
 /// Initializes a new instance of the <see cref="ViewField"/> class.
 /// </summary>
 /// <param name="Target">The target.</param>
 public ViewField(ViewField Target)
     : base(Target)
 {
 }
Example #2
0
        /// <summary>
        /// Gets the view data.
        /// </summary>
        /// <param name="Target">The target.</param>
        /// <param name="config">The config.</param>
        public void GetViewData(View Target, Configuration config)
        {
            SqlConnection myConnection = Connection.connect();

            if (myConnection == null)
            {
                return;
            }

            Target.FieldCont = new ViewFieldContainer(Target);

            Table TableList = ConnectionAdapter.executeSelect
                              (
                myConnection,
                String.Format
                (
                    "SELECT name, object_id, parent_object_id FROM sys.objects WHERE type_desc='VIEW' and name='{0}'",
                    Target.Name
                )
                              );

            String table_name       = TableList.Rows[0].Values[0].Data;
            String object_id        = TableList.Rows[0].Values[1].Data;
            String parent_object_id = TableList.Rows[0].Values[2].Data;

            String query = String.Format
                           (
                "SELECT sys.columns.name, sys.types.name, sys.columns.max_length, sys.columns.is_nullable, sys.columns.is_identity " +
                "FROM sys.columns " +
                // "INNER JOIN sys.types ON sys.columns.system_type_id=sys.types.system_type_id " +
                "INNER JOIN sys.types " +
                "ON sys.columns.system_type_id=sys.types.system_type_id " +
                "AND sys.columns.user_type_id=sys.types.user_type_id " +
                "WHERE sys.columns.object_id='{0}'",
                object_id
                           );

            Table ColumnList = ConnectionAdapter.executeSelect(myConnection, query);

            foreach (Row col in ColumnList.Rows)
            {
                String type     = col.Values[1].Data;
                String num      = col.Values[2].Data;
                String nullable = col.Values[3].Data;
                String identity = col.Values[4].Data;

                if
                (
                    IsTextType(type) == true &&
                    num != String.Empty &&
                    num != "NULL"
                )
                {
                    type += "(" + num + ")";
                }

                ViewField f = new ViewField(col.Values[0].Data, type, nullable.ToLower() == "true" ? true : false, identity.ToLower() == "true" ? true : false);
                f.Parent = Target;

                Target.FieldCont.Fields.Add(f);
            }

            myConnection.Close();
        }