private static DataTypeDefinitionRow GetType(IColumn srcCol, DataTypeDefinitionDataTable types) { // DataTypeName=Hyperlink, DataTypeNameComplete=Text (255) String dataTypeNameComplete = srcCol.DataTypeNameComplete .Replace(" ", "") .Replace("(", "_") .Replace(")", "_"); String dataTypeName = srcCol.DataTypeName .Replace(" ", "") .Replace("(", "_") .Replace(")", "_"); if (dataTypeNameComplete.Length == 0) { dataTypeNameComplete = dataTypeName; } if (dataTypeName.Length == 0) { dataTypeName = dataTypeNameComplete; } int baseTypeId = srcCol.DataType; if (baseTypeId == 0) { baseTypeId = Mapping.GetOleDbTypeIDFromOleDbTypeName(dataTypeNameComplete); } if (baseTypeId == 0) { baseTypeId = Mapping.GetOleDbTypeIDFromOleDbTypeName(dataTypeName); } // include System.XXXX DataTypeDefinitionRow baseType = types.IncludeDataTypeDefinition(Mapping.GetSystemTypeFromOleDBTypeID(baseTypeId), null); string oleTypeName = (baseTypeId != 0) ? Mapping.GetOleDBTypeNameFromID(baseTypeId) : null; if (oleTypeName != null) { baseType = types.IncludeDataTypeDefinition("sql." + oleTypeName, baseType.DataTypeName); } if (dataTypeName.Length > 0) { baseType = types.IncludeDataTypeDefinition("sql." + dataTypeName, baseType.DataTypeName); } if (srcCol.CharacterMaxLength > 0) { dataTypeNameComplete += "_" + srcCol.CharacterMaxLength.ToString() + "_"; } baseType = types.IncludeDataTypeDefinition("app." + dataTypeNameComplete, baseType.DataTypeName); if (srcCol.CharacterMaxLength > 0) { baseType.StringSize = srcCol.CharacterMaxLength; } return(baseType); }
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; * */ }
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; * */ }
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); }