Beispiel #1
0
            public override SqlTypeResolveInfo VisitIntegerType(PlSqlParser.IntegerTypeContext context)
            {
                var         size = SqlParseNumber.PositiveInteger(context.numeric()) ?? -1;
                SqlTypeCode typeCode;

                if (context.BIGINT() != null)
                {
                    typeCode = SqlTypeCode.BigInt;
                }
                else if (context.INT() != null ||
                         context.INTEGER() != null)
                {
                    typeCode = SqlTypeCode.Integer;
                }
                else if (context.SMALLINT() != null)
                {
                    typeCode = SqlTypeCode.SmallInt;
                }
                else if (context.TINYINT() != null)
                {
                    typeCode = SqlTypeCode.TinyInt;
                }
                else
                {
                    throw new ParseCanceledException("Invalid integer type");
                }

                return(new SqlTypeResolveInfo(typeCode.ToString().ToUpperInvariant(),
                                              new Dictionary <string, object> {
                    { "MaxSize", size }
                }));
            }
Beispiel #2
0
            public override SqlTypeResolveInfo VisitNumericType(PlSqlParser.NumericTypeContext context)
            {
                var precision = SqlParseNumber.PositiveInteger(context.precision) ?? -1;
                var scale     = SqlParseNumber.PositiveInteger(context.scale) ?? -1;

                if (scale > 0 && precision <= 0)
                {
                    throw new ParseCanceledException("Invalid precision set.");
                }
                if (scale > Byte.MaxValue - 1)
                {
                    throw new ParseCanceledException("Invalid scale value.");
                }

                SqlTypeCode typeCode;

                if (context.DECIMAL() != null)
                {
                    typeCode = SqlTypeCode.Decimal;
                }
                else if (context.REAL() != null)
                {
                    typeCode = SqlTypeCode.Real;
                }
                else if (context.FLOAT() != null)
                {
                    typeCode = SqlTypeCode.Float;
                }
                else if (context.DOUBLE() != null)
                {
                    typeCode = SqlTypeCode.Double;
                }
                else if (context.NUMERIC() != null)
                {
                    typeCode = SqlTypeCode.Numeric;
                }
                else
                {
                    throw new ParseCanceledException("Invalid numeric type");
                }

                var meta = new Dictionary <string, object> {
                    { "Precision", precision },
                    { "Scale", scale }
                };

                return(new SqlTypeResolveInfo(typeCode.ToString().ToUpperInvariant(), meta));
            }
Beispiel #3
0
            public override SqlTypeResolveInfo VisitBinaryType(PlSqlParser.BinaryTypeContext context)
            {
                int?maxSize = null;

                if (context.MAX() != null)
                {
                    maxSize = SqlBinaryType.DefaultMaxSize;
                }
                else if (context.numeric() != null)
                {
                    maxSize = SqlParseNumber.PositiveInteger(context.numeric());
                }

                SqlTypeCode typeCode;

                if (context.BINARY() != null)
                {
                    typeCode = SqlTypeCode.Binary;
                }
                else if (context.VARBINARY() != null)
                {
                    typeCode = SqlTypeCode.VarBinary;
                }
                else if (context.BLOB() != null)
                {
                    typeCode = SqlTypeCode.Blob;
                }
                else if (!context.longVarbinary().IsEmpty)
                {
                    typeCode = SqlTypeCode.LongVarBinary;
                }
                else
                {
                    throw new ParseCanceledException("Invalid binary type.");
                }

                return(new SqlTypeResolveInfo(typeCode.ToString().ToUpperInvariant(),
                                              new Dictionary <string, object> {
                    { "MaxSize", maxSize }, { "Size", maxSize }
                }));
            }
Beispiel #4
0
            public override SqlTypeResolveInfo VisitStringType(PlSqlParser.StringTypeContext context)
            {
                int?size = null;

                if (context.numeric() != null)
                {
                    size = SqlParseNumber.PositiveInteger(context.numeric());
                }
                else if (context.MAX() != null)
                {
                    size = SqlCharacterType.DefaultMaxSize;
                }

                SqlTypeCode typeCode;

                if (context.CHAR() != null)
                {
                    typeCode = SqlTypeCode.Char;
                }
                else if (context.VARCHAR() != null)
                {
                    typeCode = SqlTypeCode.VarChar;
                }
                else if (context.STRING() != null)
                {
                    typeCode = SqlTypeCode.String;
                }
                else if (context.CLOB() != null)
                {
                    typeCode = SqlTypeCode.Clob;
                }
                else if (!context.longVarchar().IsEmpty)
                {
                    typeCode = SqlTypeCode.LongVarChar;
                }
                else
                {
                    throw new ParseCanceledException("Invalid string type");
                }

                string locale = null;

                if (context.LOCALE() != null)
                {
                    locale = SqlParseInputString.AsNotQuoted(context.locale.Text);
                }

                var meta = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

                if (size != null)
                {
                    meta.Add("MaxSize", size);
                    meta.Add("Size", size);
                }
                if (locale != null)
                {
                    meta.Add("Locale", locale);
                }

                return(new SqlTypeResolveInfo(typeCode.ToString().ToUpperInvariant(), meta));
            }