public static ColumnInfo CreateColumnInfo(SystemColumnType systemColumnType, string columnName) { ColumnType columnType = GetColumnType(systemColumnType, columnName); ColumnInfo result = CreateColumnInfo(columnType); result.Name = columnName; result.SystemColumnType = systemColumnType; return(result); }
private static void TestCreateColumnInfo <TColumnInfo>(SystemColumnType systemColumnType, string columnName) where TColumnInfo : ColumnInfo { // Act TColumnInfo columnInfo = ColumnInfoHelper.CreateColumnInfo(systemColumnType, columnName) as TColumnInfo; // Assert Assert.IsNotNull(columnInfo); Assert.AreEqual(systemColumnType, columnInfo.SystemColumnType); Assert.AreEqual(columnName, columnInfo.Name); }
private static ColumnType GetColumnType(SystemColumnType systemColumnType, string columnName) { if (string.IsNullOrWhiteSpace(columnName)) { throw new ArgumentNullException(nameof(columnName)); } foreach (ColumnTypeDesc desc in ColumnTypeDescs) { if (systemColumnType != SystemColumnType.String && !desc.SystemColumnTypes.Contains(systemColumnType)) { continue; } foreach (string namePattern in desc.NamePatterns) { Regex regex = new Regex(namePattern); if (regex.IsMatch(columnName)) { return(desc.ColumnType); } } } switch (systemColumnType) { case SystemColumnType.Int: return(ColumnType.Int); case SystemColumnType.DateTime: return(ColumnType.DateTime); case SystemColumnType.Boolean: return(ColumnType.Boolean); case SystemColumnType.Money: return(ColumnType.Money); case SystemColumnType.Number: return(ColumnType.Number); case SystemColumnType.Guid: return(ColumnType.Guid); default: return(ColumnType.RandomText); } }
public void ProcessColumnDefinition(TSqlParser.Column_definitionContext context) { if (TableInfo == null) { return; } string columnName = context.id(0).GetText(); string columnTypeName = "int"; var dataTypeContext = context.data_type(); if (dataTypeContext != null) { columnTypeName = dataTypeContext.id().GetText(); } SystemColumnType systemColumnType = SqlServerHelper.SqlServerToSystemColumnType(columnTypeName); ColumnInfo columnInfo = ColumnInfoHelper.CreateColumnInfo(systemColumnType, columnName); columnInfo.IsComputed = context.AS()?.GetText().ToLower() == "as"; if (dataTypeContext != null) { string decimal1Text = dataTypeContext.DECIMAL(0)?.GetText(); string decimal2Text = dataTypeContext.DECIMAL(1)?.GetText(); int decimal1 = decimal1Text == null ? 0 : int.Parse(decimal1Text); int decimal2 = decimal2Text == null ? 0 : int.Parse(decimal2Text); columnInfo.IsIdentity = dataTypeContext.IDENTITY()?.GetText().ToLower() == "identity"; if (columnInfo.IsIdentity) { columnInfo.IdentitySeed = decimal1; columnInfo.IdentityIncrement = decimal2; } else { columnInfo.MaxLength = decimal1; columnInfo.SetMaxPrecision(columnInfo.MaxLength); columnInfo.Scale = decimal2; } } bool isNot = !string.IsNullOrWhiteSpace(context.null_notnull().NOT()?.GetText()); bool isNull = !string.IsNullOrWhiteSpace(context.null_notnull().NULL()?.GetText()); columnInfo.IsNullable = !(isNot && isNull); TableInfo.Columns.Add(columnInfo); }
/// <summary> /// Sets the system column type for the column. /// </summary> /// <param name="systemColumnType"> the system column type </param> /// <returns> the modify column builder </returns> public UpdateColumnBuilder SetSystemColumnType(SystemColumnType systemColumnType) { this.systemColumnType = systemColumnType; return(this); }
public void Add(SystemColumnType field, bool nullable = false, bool primaryKey = false) { Add(field.FieldName(), field.GetDataType(), nullable, primaryKey); }
/// <summary> /// Sets the system column Type. /// </summary> /// <param name="systemColumnType"> the system column Type </param> /// <returns> the CreateSheetColumnBuilder </returns> public virtual CreateSheetColumnBuilder SetSystemColumnType(SystemColumnType? systemColumnType) { this.systemColumnType = systemColumnType; return this; }
/// <summary> /// Sets the system column Type. /// </summary> /// <param name="systemColumnType"> the system column Type </param> /// <returns> the adds the column To sheet builder </returns> public virtual AddColumnBuilder SetSystemColumnType(SystemColumnType? systemColumnType) { this.systemColumnType = systemColumnType; return this; }
/// <summary> /// Sets the system column Type for the column. /// </summary> /// <param name="systemColumnType"> the system column Type </param> /// <returns> the modify column builder </returns> public virtual UpdateColumnBuilder SetSystemColumnType(SystemColumnType systemColumnType) { this.systemColumnType = systemColumnType; return this; }