/// <summary>
        /// Creates a field definition from a field metadata row.
        /// </summary>
        /// <param name="parentModule">The module that contains the field.</param>
        /// <param name="token">The token to initialize the field for.</param>
        /// <param name="row">The metadata table row to base the field definition on.</param>
        public SerializedFieldDefinition(SerializedModuleDefinition parentModule, MetadataToken token, FieldDefinitionRow row)
            : base(token)
        {
            _parentModule = parentModule ?? throw new ArgumentNullException(nameof(parentModule));
            _row          = row;

            Attributes = row.Attributes;
        }
Exemple #2
0
        /// <summary>
        /// Allocates metadata rows for the provided field definitions in the buffer.
        /// </summary>
        /// <param name="fields">The fields to define.</param>
        public void DefineFields(IEnumerable <FieldDefinition> fields)
        {
            var table = Metadata.TablesStream.GetTable <FieldDefinitionRow>(TableIndex.Field);

            foreach (var field in fields)
            {
                var row = new FieldDefinitionRow(
                    field.Attributes,
                    Metadata.StringsStream.GetStringIndex(field.Name),
                    Metadata.BlobStream.GetBlobIndex(this, field.Signature, DiagnosticBag));

                var token = table.Add(row);
                _tokenMapping.Register(field, token);
            }
        }
        private void SetDbDataTypeName(FieldDefinitionRow c, DataRow row)
        {
            DataTypeDefinitionRow fieldDataType = c.DataTypeDefinitionRow;
            string name;
            int typID = 0;

            if (fieldDataType != null)
            {
                #region find type "sql." that matches oledb
                DataTypeDefinitionRow datatyp = fieldDataType.FindBaseTypeByPrefix(sqlPrefix);

                while ((typID == 0) && (datatyp != null) && (datatyp != datatyp.DataTypeDefinitionRowParent))
                {
                    name = datatyp.DataTypeName.Substring(sqlPrefix.Length);
                    typID = Mapping.GetOleDbTypeIDFromOleDbTypeName(name);
                    if (typID == 0)
                    {
                        datatyp = datatyp.DataTypeDefinitionRowParent;
                        datatyp = datatyp.FindBaseTypeByPrefix(sqlPrefix);
                    }
                }
                #endregion

                #region if not found find typ "System." that has a mapping to oledb
                if (typID == 0)
                {
                    datatyp = fieldDataType.FindBaseTypeByPrefix(systemPrefix);

                    while ((typID == 0) && (datatyp != null) && (datatyp != datatyp.DataTypeDefinitionRowParent))
                    {
                        name = datatyp.DataTypeName.Substring(systemPrefix.Length);
                        typID = Mapping.GetOleDbTypeIDFromSystemTypeName(name);
                        if (typID == 0)
                        {
                            datatyp = datatyp.DataTypeDefinitionRowParent;
                            datatyp = datatyp.FindBaseTypeByPrefix(systemPrefix);
                        }
                    }
                }
                #endregion
                if (typID != 0)
                {
                    setAndCreate(row, "DATA_TYPE", typID);
                    set(row, "PARAMETER_TYPE", typID);
                    name = ((OleDbType)typID).ToString();
                }
                else
                {
                    name = fieldDataType.DataTypeName;
                }

            }
            else // else (fieldDataType === null)
            {
                name = c.DataType.Substring(systemPrefix.Length);
            }
            set(row, "TYPE_NAME", name);
            int len = c.GetDataTypStringLen();
            if (len > 0)
                name += "(" + len.ToString() + ")";
            set(row, "TYPE_NAME_COMPLETE", name);

        }
Exemple #4
0
        public static void ImportField(IColumn srcCol, TableDefinitionRow destTab)
        {
            DataTypeDefinitionRow dataType = GetType(srcCol, destTab.Table.DataSet.DataTypeDefinition);

            FieldDefinitionRow destField = destTab.FindFieldByAliasOrName(srcCol.Name); // destTab.Table.DataSet.FieldDefinition destTabs.FindByTableName(srcTab.Name);

            if (destField == null)
            {
                destField = destTab.FindFieldByAliasOrName(srcCol.Alias);
            }
            if (destField == null)
            {
                destField = destTab.AddFieldDefinitionRow(srcCol.Name, dataType.DataTypeName);
            }
            else
            {
                destField.DataTypeDefinitionRow = dataType;
            }

            // destField.DBFieldType = "TAB_FIELD"; // default value
            destField.FieldAlias = srcCol.Alias;
            if (srcCol.Description.Length > 0)
            {
                destField.FieldComment = srcCol.Description;
            }
            destField.AllowDBNull   = srcCol.IsNullable;
            destField.AutoIncrement = srcCol.IsAutoKey;
            if (srcCol.IsAutoKey)
            {
                destField.AutoIncrementSeed = srcCol.AutoKeySeed;
                destField.AutoIncrementStep = srcCol.AutoKeyIncrement;
            }
            System.Diagnostics.Debug.WriteLine(string.Format(
                                                   "FeldName={4}.{3}, DataTypeName={0}, DataTypeNameComplete={1}, DbTargetType={2}"
                                                   , srcCol.DataTypeName
                                                   , srcCol.DataTypeNameComplete
                                                   , srcCol.DbTargetType
                                                   , srcCol.Name
                                                   , destTab.TableName));

            /* destField.DataType = ???;
             * srcCol.DataType; // int
             * srcCol.DataTypeName;
             * srcCol.DataTypeNameComplete;
             * srcCol.DbTargetType;
             */


            // srcCol.ForeignKeys;
            if (srcCol.HasDefault)
            {
                destField.DefaultValue = srcCol.Default;
            }
            else
            {
                destField.SetDefaultValueNull();
            }
            destField.OriginalName = GetOriginalName(srcCol.Guid, srcCol.Name);
            destField.ReadOnly     = srcCol.IsComputed; //  || srcCol.???
            // destField.StringSize = srcCol.CharacterMaxLength; moved to DataTypeDefinition
            destField.Unique = srcCol.IsAutoKey;        // || ??? the only PK or the only FK
            if (srcCol.IsInPrimaryKey)
            {
                if (srcCol.Ordinal > 0)
                {
                    destField.PrimaryKeyNumber = srcCol.Ordinal;
                }
                else
                {
                    destField.PrimaryKeyNumber = nextPkNumber++;
                }
            }

            /** unsupported properties
             * destField.FieldExpression = srcCol.???
             * destField.NullValue = srcCol.??? // nullvaluereplacement
             * destField.XmlFieldType = ???; // default is Attribute
             *
             * // srcCol.AllProperties;
             * srcCol.CharacterOctetLength;
             * srcCol.CharacterSetCatalog;
             * srcCol.CharacterSetName;
             * srcCol.CharacterSetSchema;
             * srcCol.CompFlags;
             * srcCol.Flags;
             * srcCol.GlobalProperties;
             *
             * srcCol.DateTimePrecision; // int
             * srcCol.HasDomain;
             * srcCol.Domain; // IDomain
             * srcCol.DomainCatalog;
             * srcCol.DomainName;
             * srcCol.DomainSchema;
             * srcCol.LanguageType;
             * srcCol.LCID;
             * srcCol.NumericPrecision;
             * srcCol.NumericScale;
             * srcCol.Ordinal;
             * srcCol.Properties;
             * srcCol.PropID;
             * srcCol.SortID;
             * srcCol.TDSCollation;
             * srcCol.TypeGuid;
             * srcCol.UserDataXPath;
             *
             */
        }
Exemple #5
0
        public static void ImportResultColumn(IResultColumn srcCol, TableDefinitionRow destTab)
        {
            DataTypeDefinitionRow dataType = GetType(srcCol, destTab.Table.DataSet.DataTypeDefinition);

            FieldDefinitionRow destField = destTab.FindFieldByAliasOrName(srcCol.Name); // destTab.Table.DataSet.FieldDefinition destTabs.FindByTableName(srcTab.Name);

            if (destField == null)
            {
                destField = destTab.FindFieldByAliasOrName(srcCol.Alias);
            }
            if (destField == null)
            {
                destField = destTab.AddFieldDefinitionRow(srcCol.Name, dataType.DataTypeName);
            }
            else
            {
                destField.DataTypeDefinitionRow = dataType;
            }

            destField.DBFieldType = "PROC_RETURN";
            // destField.ReadOnly = true;

            //Exception on accessing srcCol.Alias
            destField.FieldAlias = srcCol.Alias;

            System.Diagnostics.Debug.WriteLine(string.Format(
                                                   "FeldName={4}.{3}, DataTypeName={0}, DataTypeNameComplete={1}, DbTargetType={2}"
                                                   , srcCol.DataTypeName
                                                   , srcCol.DataTypeNameComplete
                                                   , srcCol.DbTargetType
                                                   , srcCol.Name
                                                   , destTab.TableName));

            /* destField.DataType = ???;
             * srcCol.DataType; // int
             * srcCol.DataTypeName;
             * srcCol.DataTypeNameComplete;
             * srcCol.DbTargetType;
             */


            destField.SetDefaultValueNull();
            destField.OriginalName = srcCol.Name;

            /** unsupported properties
             * destField.FieldExpression = srcCol.???
             * destField.NullValue = srcCol.??? // nullvaluereplacement
             * destField.XmlFieldType = ???; // default is Attribute
             *
             * // srcCol.AllProperties;
             * srcCol.CharacterOctetLength;
             * srcCol.CharacterSetCatalog;
             * srcCol.CharacterSetName;
             * srcCol.CharacterSetSchema;
             * srcCol.CompFlags;
             * srcCol.Flags;
             * srcCol.GlobalProperties;
             *
             * srcCol.DateTimePrecision; // int
             * srcCol.HasDomain;
             * srcCol.Domain; // IDomain
             * srcCol.DomainCatalog;
             * srcCol.DomainName;
             * srcCol.DomainSchema;
             * srcCol.LanguageType;
             * srcCol.LCID;
             * srcCol.NumericPrecision;
             * srcCol.NumericScale;
             * srcCol.Ordinal;
             * srcCol.Properties;
             * srcCol.PropID;
             * srcCol.SortID;
             * srcCol.TDSCollation;
             * srcCol.TypeGuid;
             * srcCol.UserDataXPath;
             *
             */
        }
Exemple #6
0
        private void SetDbDataTypeName(FieldDefinitionRow c, DataRow row)
        {
            DataTypeDefinitionRow fieldDataType = c.DataTypeDefinitionRow;
            string name;
            int    typID = 0;

            if (fieldDataType != null)
            {
                #region find type "sql." that matches oledb
                DataTypeDefinitionRow datatyp = fieldDataType.FindBaseTypeByPrefix(sqlPrefix);

                while ((typID == 0) && (datatyp != null) && (datatyp != datatyp.DataTypeDefinitionRowParent))
                {
                    name  = datatyp.DataTypeName.Substring(sqlPrefix.Length);
                    typID = Mapping.GetOleDbTypeIDFromOleDbTypeName(name);
                    if (typID == 0)
                    {
                        datatyp = datatyp.DataTypeDefinitionRowParent;
                        datatyp = datatyp.FindBaseTypeByPrefix(sqlPrefix);
                    }
                }
                #endregion

                #region if not found find typ "System." that has a mapping to oledb
                if (typID == 0)
                {
                    datatyp = fieldDataType.FindBaseTypeByPrefix(systemPrefix);

                    while ((typID == 0) && (datatyp != null) && (datatyp != datatyp.DataTypeDefinitionRowParent))
                    {
                        name  = datatyp.DataTypeName.Substring(systemPrefix.Length);
                        typID = Mapping.GetOleDbTypeIDFromSystemTypeName(name);
                        if (typID == 0)
                        {
                            datatyp = datatyp.DataTypeDefinitionRowParent;
                            datatyp = datatyp.FindBaseTypeByPrefix(systemPrefix);
                        }
                    }
                }
                #endregion
                if (typID != 0)
                {
                    setAndCreate(row, "DATA_TYPE", typID);
                    set(row, "PARAMETER_TYPE", typID);
                    name = ((OleDbType)typID).ToString();
                }
                else
                {
                    name = fieldDataType.DataTypeName;
                }
            }
            else // else (fieldDataType === null)
            {
                name = c.DataType.Substring(systemPrefix.Length);
            }
            set(row, "TYPE_NAME", name);
            int len = c.GetDataTypStringLen();
            if (len > 0)
            {
                name += "(" + len.ToString() + ")";
            }
            set(row, "TYPE_NAME_COMPLETE", name);
        }