예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
 /// <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);
 }
예제 #6
0
 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;
 }