コード例 #1
0
        public static string CreateTableFieldScript(MetaField field)
        {
            string SIZE = string.Empty;

            if (field.TypeName == "char"
                | field.TypeName == "nchar"
                | field.TypeName == "binary"
                | field.TypeName == "varchar"
                | field.TypeName == "nvarchar"
                | field.TypeName == "varbinary")
            {
                SIZE = (field.Length < 0) ? "(MAX)" : $"({field.Length})";
            }
            else if (field.Precision > 0 && field.TypeName != "bit")
            {
                SIZE = $"({field.Precision}, {field.Scale})";
            }
            string NULLABLE = field.IsNullable ? " NULL" : " NOT NULL";

            return($"[{field.Name}] [{field.TypeName}]{SIZE}{NULLABLE}");
        }
コード例 #2
0
        private void ReadSQLMetadata(MetaObject @object)
        {
            if (string.IsNullOrWhiteSpace(@object.TableName))
            {
                return;
            }

            List <FieldSqlInfo> sql_fields = GetSqlFields(@object.TableName);

            ClusteredIndexInfo indexInfo = this.GetClusteredIndexInfo(@object.TableName);

            foreach (FieldSqlInfo info in sql_fields)
            {
                bool found = false; MetaField field = null;
                foreach (MetaProperty p in @object.Properties)
                {
                    if (string.IsNullOrEmpty(p.DbName))
                    {
                        continue;
                    }

                    if (info.COLUMN_NAME.TrimStart('_') == DBToken.Periodicity)
                    {
                        continue;
                    }

                    if (info.COLUMN_NAME.TrimStart('_').StartsWith(p.DbName))
                    {
                        field = new MetaField()
                        {
                            Name    = info.COLUMN_NAME,
                            Purpose = SqlUtility.ParseFieldPurpose(info.COLUMN_NAME)
                        };
                        p.Fields.Add(field);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    string     propertyName  = string.Empty;
                    List <int> propertyTypes = null;

                    if (@object.Token == DBToken.AccumRgT && @object.Owner != null && @object.Owner.Token == DBToken.AccumRg)
                    {
                        // find property name in main table object by field name
                        foreach (MetaProperty ownerProperty in @object.Owner.Properties)
                        {
                            if (ownerProperty.Fields.Where(f => f.Name == info.COLUMN_NAME).FirstOrDefault() != null)
                            {
                                propertyName = ownerProperty.Name;
                                if (ownerProperty.PropertyTypes.Count > 0)
                                {
                                    propertyTypes = ownerProperty.PropertyTypes.ToList();
                                }
                                break;
                            }
                        }
                    }

                    MetaProperty property = @object.Properties.Where(p => p.Name == propertyName).FirstOrDefault();
                    if (property == null)
                    {
                        property = new MetaProperty()
                        {
                            Parent  = @object,
                            Name    = string.IsNullOrEmpty(propertyName) ? info.COLUMN_NAME : propertyName,
                            Purpose = MetaPropertyPurpose.System
                        };
                        @object.Properties.Add(property);

                        MatchFieldToProperty(info, property);

                        if (property.PropertyTypes.Count == 0 && propertyTypes != null)
                        {
                            property.PropertyTypes = propertyTypes;
                        }
                    }

                    field = new MetaField()
                    {
                        Name    = info.COLUMN_NAME,
                        Purpose = SqlUtility.ParseFieldPurpose(info.COLUMN_NAME)
                    };
                    property.Fields.Add(field);
                }
                field.TypeName   = info.DATA_TYPE;
                field.Length     = info.CHARACTER_MAXIMUM_LENGTH;
                field.Precision  = info.NUMERIC_PRECISION;
                field.Scale      = info.NUMERIC_SCALE;
                field.IsNullable = info.IS_NULLABLE;

                if (indexInfo != null)
                {
                    ClusteredIndexColumnInfo columnInfo = indexInfo.GetColumnByName(info.COLUMN_NAME);
                    if (columnInfo != null)
                    {
                        field.IsPrimaryKey = true;
                        field.KeyOrdinal   = columnInfo.KEY_ORDINAL;
                    }
                }
            }
        }
コード例 #3
0
        private void ReadSQLMetadata(MetaObject metaObject)
        {
            if (string.IsNullOrWhiteSpace(metaObject.TableName))
            {
                return;
            }

            List <FieldSqlInfo> sql_fields = GetSqlFields(metaObject.TableName);

            ClusteredIndexInfo indexInfo = GetClusteredIndexInfo(metaObject.TableName);

            foreach (FieldSqlInfo info in sql_fields)
            {
                bool found = false; MetaField field = null;
                foreach (MetaProperty p in metaObject.Properties)
                {
                    if (string.IsNullOrEmpty(p.Field))
                    {
                        continue;
                    }

                    if (info.COLUMN_NAME.TrimStart('_') == MetadataTokens.Periodicity)
                    {
                        continue;
                    }

                    if (info.COLUMN_NAME.TrimStart('_').StartsWith(p.Field))
                    {
                        field = new MetaField()
                        {
                            Name    = info.COLUMN_NAME,
                            Purpose = SqlUtility.ParseFieldPurpose(info.COLUMN_NAME)
                        };
                        p.Fields.Add(field);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    string propertyName = string.Empty;
                    int    propertyType = (int)DataTypes.NULL;

                    if (metaObject.Owner != null && // таблица итогов регистра накопления
                        metaObject.TypeName == MetaObjectTypes.AccumulationRegister &&
                        metaObject.Owner.TypeName == MetaObjectTypes.AccumulationRegister)
                    {
                        // find property name in main table object by field name
                        foreach (MetaProperty ownerProperty in metaObject.Owner.Properties)
                        {
                            if (ownerProperty.Fields.Where(f => f.Name == info.COLUMN_NAME).FirstOrDefault() != null)
                            {
                                propertyName = ownerProperty.Name;
                                if (ownerProperty.PropertyType == (int)DataTypes.Multiple)
                                {
                                    propertyType = (int)DataTypes.Multiple;
                                }
                                break;
                            }
                        }
                    }

                    MetaProperty property = metaObject.Properties.Where(p => p.Name == propertyName).FirstOrDefault();
                    if (property == null)
                    {
                        property = new MetaProperty()
                        {
                            Name    = string.IsNullOrEmpty(propertyName) ? info.COLUMN_NAME : propertyName,
                            Purpose = PropertyPurpose.System
                        };
                        metaObject.Properties.Add(property);

                        MatchFieldToProperty(info, property);

                        if (property.PropertyType == (int)DataTypes.NULL)
                        {
                            property.PropertyType = propertyType;
                        }
                    }

                    field = new MetaField()
                    {
                        Name    = info.COLUMN_NAME,
                        Purpose = SqlUtility.ParseFieldPurpose(info.COLUMN_NAME)
                    };
                    property.Fields.Add(field);
                }
                field.TypeName   = info.DATA_TYPE;
                field.Length     = info.CHARACTER_MAXIMUM_LENGTH;
                field.Precision  = info.NUMERIC_PRECISION;
                field.Scale      = info.NUMERIC_SCALE;
                field.IsNullable = info.IS_NULLABLE;

                if (indexInfo != null)
                {
                    ClusteredIndexColumnInfo columnInfo = indexInfo.GetColumnByName(info.COLUMN_NAME);
                    if (columnInfo != null)
                    {
                        field.IsPrimaryKey = true;
                        field.KeyOrdinal   = columnInfo.KEY_ORDINAL;
                    }
                }
            }
        }