Esempio n. 1
0
        public static (string dataType, bool?isHashKey) VisitColumnDefinition(ColumnDefinitionContext context)
        {
            bool?isHashKey = null;

            if (context.columnConstraint() != null)
            {
                isHashKey = IsHashKey(context.columnConstraint());
            }

            return(context.dataType().GetText(), isHashKey);
        }
        /// <summary>
        /// Get Column detail from context
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static (string dataTypeName, int?dataLength, bool unsigned) ExtractColumnDataDefinition(this ColumnDefinitionContext context)
        {
            if (context == null)
            {
                throw new ArgumentOutOfRangeException($"{nameof(context)} is null");
            }

            // Normal route: id binary(16) NOT NULL
            var dimensionDataContext = context.GetChild <DimensionDataTypeContext>(0);

            if (dimensionDataContext != null)
            {
                return(ExtractColumnData(dimensionDataContext));
            }

            // get dimension data from string: char(32)
            var stringDataContext = context.GetChild <StringDataTypeContext>(0);

            if (stringDataContext != null)
            {
                return(ExtractColumnData(stringDataContext));
            }

            // get special Datatype `SERIAL`.
            var simpleDataTypeContext = context.GetChild <SimpleDataTypeContext>();

            if (simpleDataTypeContext != null)
            {
                return(ExtractColumnData(simpleDataTypeContext));
            }

            throw new ArgumentOutOfRangeException($"Could not retrieve column detail from {nameof(context)}");
        }