PositiveInteger() public static method

public static PositiveInteger ( ITerminalNode node ) : int?
node ITerminalNode
return int?
Exemplo n.º 1
0
        public override DataTypeInfo VisitInteger_type(PlSqlParser.Integer_typeContext context)
        {
            var         size = Number.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 DataTypeInfo(typeCode.ToString().ToUpperInvariant(), new [] { new DataTypeMeta("Size", size.ToString()) }));
        }
Exemplo n.º 2
0
        public static SqlStatement Build(PlSqlParser.DeleteStatementContext context)
        {
            var tableName   = Name.Object(context.objectName());
            var whereClause = WhereClause.Form(context.whereClause());

            if (whereClause.CurrentOf != null)
            {
                return(new DeleteCurrentStatement(tableName, whereClause.CurrentOf));
            }

            var statement = new DeleteStatement(tableName, whereClause.Expression);

            if (context.deleteLimit() != null)
            {
                var limit = Number.PositiveInteger(context.deleteLimit().numeric());
                if (limit == null)
                {
                    throw new ParseCanceledException("Invalid delete limit.");
                }

                statement.Limit = limit.Value;
            }

            return(statement);
        }
        public override SqlStatement VisitSetLockTimeout(PlSqlParser.SetLockTimeoutContext context)
        {
            var value = Number.PositiveInteger(context.numeric());

            if (value == null)
            {
                throw new ParseCanceledException("Invalid timeout value specified.");
            }

            return(new SetStatement(TransactionSettingKeys.LockTimeout, SqlExpression.Constant(value.Value)));
        }
Exemplo n.º 4
0
        public static UpdateStatement Build(PlSqlParser.UpdateStatementContext context)
        {
            var tableName   = Name.Object(context.objectName());
            var setClause   = context.updateSetClause();
            var limitClause = context.updateLimitClause();

            if (setClause != null)
            {
                var assignments = new List <SqlColumnAssignment>();
                var whereClause = context.whereClause();
                int limit       = -1;

                if (limitClause != null)
                {
                    limit = Number.PositiveInteger(limitClause.numeric()) ?? -1;
                }

                SqlExpression whereExpression = null;
                if (whereClause != null)
                {
                    whereExpression = Expression.Build(whereClause.conditionWrapper());
                }

                if (setClause.VALUE() != null)
                {
                    var columnName = Name.Simple(setClause.columnName());
                    var value      = Expression.Build(setClause.expression());

                    assignments.Add(new SqlColumnAssignment(columnName, value));
                }
                else
                {
                    var pairs = setClause.columnBasedUpdateClause().Select(x => new {
                        columnName = Name.Simple(x.columnName()),
                        value      = Expression.Build(x.expression())
                    });

                    assignments = pairs.Select(x => new SqlColumnAssignment(x.columnName, x.value)).ToList();
                }

                return(new UpdateStatement(tableName, whereExpression, assignments)
                {
                    Limit = limit
                });
            }
            if (context.updateFromClause() != null)
            {
                var query = Subquery.Form(context.updateFromClause().subquery());
            }

            throw new NotSupportedException();
        }
        public override SqlStatement VisitLockTableStatement(PlSqlParser.LockTableStatementContext context)
        {
            var         tableNames = context.objectName().Select(Name.Object).ToArray();
            LockingMode mode;

            if (context.SHARED() != null)
            {
                mode = LockingMode.Shared;
            }
            else if (context.EXCLUSIVE() != null)
            {
                mode = LockingMode.Exclusive;
            }
            else
            {
                throw new ParseCanceledException("Invalid locking mode");
            }

            int timeout = Timeout.Infinite;

            if (context.WAIT() != null)
            {
                var wait = Number.PositiveInteger(context.numeric());
                if (wait == null)
                {
                    throw new ParseCanceledException("Invalid timeout wait value");
                }

                timeout = wait.Value;
            }
            else if (context.NOWAIT() != null)
            {
                timeout = 0;
            }

            if (tableNames.Length == 1)
            {
                return(new LockTableStatement(tableNames[0], mode, timeout));
            }

            var seq = new SequenceOfStatements();

            foreach (var tableName in tableNames)
            {
                seq.Statements.Add(new LockTableStatement(tableName, mode, timeout));
            }

            return(seq);
        }
Exemplo n.º 6
0
        public override DataTypeInfo VisitNumeric_type(PlSqlParser.Numeric_typeContext context)
        {
            var precision = Number.PositiveInteger(context.precision) ?? -1;
            var scale     = Number.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[] {
                new DataTypeMeta("Precision", precision.ToString()),
                new DataTypeMeta("Scale", scale.ToString()),
            };

            return(new DataTypeInfo(typeCode.ToString().ToUpperInvariant(), meta));
        }
Exemplo n.º 7
0
        public override DataTypeInfo VisitBinary_type(PlSqlParser.Binary_typeContext context)
        {
            string maxSize;

            if (context.MAX() != null)
            {
                maxSize = "MAX";
            }
            else
            {
                var size = Number.PositiveInteger(context.numeric()) ?? -1;
                maxSize = size.ToString();
            }

            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.long_varbinary().IsEmpty)
            {
                typeCode = SqlTypeCode.LongVarBinary;
            }
            else
            {
                throw new ParseCanceledException("Invalid binary type.");
            }

            return(new DataTypeInfo(typeCode.ToString().ToUpperInvariant(), new[] { new DataTypeMeta("MaxSize", maxSize) }));
        }
Exemplo n.º 8
0
        public static SqlStatement Build(PlSqlParser.SelectStatementContext context)
        {
            IntoClause into;
            var        query = Subquery.Form(context.subquery(), out into);

            if (into != null)
            {
                SqlExpression reference;
                if (into.TableName != null)
                {
                    reference = SqlExpression.Reference(into.TableName);
                }
                else
                {
                    var vars = into.Variables;
                    reference = SqlExpression.Tuple(vars.Select(SqlExpression.VariableReference).Cast <SqlExpression>().ToArray());
                }

                return(new SelectIntoStatement(query, reference));
            }

            var statement = new SelectStatement(query);

            var orderBy   = context.orderByClause();
            var forUpdate = context.forUpdateClause();

            if (orderBy != null)
            {
                var sortColumns = orderBy.orderByElements().orderByElement().Select(x => {
                    bool asc = x.DESC() == null;
                    var exp  = Expression.Build(x.expression());
                    return(new SortColumn(exp, asc));
                });

                statement.OrderBy = sortColumns;
            }

            statement.ForUpdate = forUpdate != null;

            var limit = context.queryLimitClause();

            if (limit != null)
            {
                var n1 = Number.PositiveInteger(limit.n1);
                var n2 = Number.PositiveInteger(limit.n2);

                if (n1 == null)
                {
                    throw new ParseCanceledException("Invalid LIMIT clause");
                }

                if (n2 != null)
                {
                    statement.Limit = new QueryLimit(n1.Value, n2.Value);
                }
                else
                {
                    statement.Limit = new QueryLimit(n1.Value);
                }
            }

            return(statement);
        }
        public override SqlStatement VisitFetchStatement(PlSqlParser.FetchStatementContext context)
        {
            string         cursorName = Name.Simple(context.cursor_name());
            FetchDirection direction  = FetchDirection.Next;
            int            offset     = -1;

            var fetchDirection = context.fetchDirection();

            if (fetchDirection != null)
            {
                if (fetchDirection.ABSOLUTE() != null)
                {
                    var value = Number.PositiveInteger(fetchDirection.numeric());
                    if (value == null)
                    {
                        throw new ParseCanceledException("FETCH ABSOLUTE requires a numeric offset.");
                    }

                    direction = FetchDirection.Absolute;
                    offset    = value.Value;
                }
                else if (fetchDirection.RELATIVE() != null)
                {
                    var value = Number.PositiveInteger(fetchDirection.numeric());
                    if (value == null)
                    {
                        throw new ParseCanceledException("FETCH RELATIVE requires a numeric offset.");
                    }

                    direction = FetchDirection.Relative;
                    offset    = value.Value;
                }
                else if (fetchDirection.NEXT() != null)
                {
                    direction = FetchDirection.Next;
                }
                else if (fetchDirection.PRIOR() != null)
                {
                    direction = FetchDirection.Prior;
                }
                else if (fetchDirection.FIRST() != null)
                {
                    direction = FetchDirection.First;
                }
                else if (fetchDirection.LAST() != null)
                {
                    direction = FetchDirection.Last;
                }
            }

            var offsetExp = offset == -1 ? null : SqlExpression.Constant(offset);

            if (context.INTO() != null)
            {
                SqlExpression refExpression;
                var           tableName = Name.Object(context.objectName());
                var           varNames  = context.variable_name().Select(Name.Simple).ToArray();
                if (tableName != null)
                {
                    refExpression = SqlExpression.Reference(tableName);
                }
                else
                {
                    refExpression = SqlExpression.Tuple(varNames.Select(SqlExpression.VariableReference).Cast <SqlExpression>().ToArray());
                }

                return(new FetchIntoStatement(cursorName, direction, offsetExp, refExpression));
            }

            return(new FetchStatement(cursorName, direction, offsetExp));
        }
Exemplo n.º 10
0
        public override DataTypeInfo VisitString_type(PlSqlParser.String_typeContext context)
        {
            string size = null;

            if (context.numeric() != null)
            {
                size = Number.PositiveInteger(context.numeric()).ToString();
            }
            else if (context.MAX() != null)
            {
                size = "MAX";
            }

            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.long_varchar().IsEmpty)
            {
                typeCode = SqlTypeCode.LongVarChar;
            }
            else
            {
                throw new ParseCanceledException("Invalid string type");
            }

            string encoding = null;

            if (context.ENCODING() != null)
            {
                encoding = InputString.AsNotQuoted(context.encoding.Text);
            }

            string locale = null;

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

            var meta = new List <DataTypeMeta>();

            if (size != null)
            {
                meta.Add(new DataTypeMeta("MaxSize", size));
            }
            if (locale != null)
            {
                meta.Add(new DataTypeMeta("Locale", locale));
            }
            if (encoding != null)
            {
                meta.Add(new DataTypeMeta("Encoding", encoding));
            }

            return(new DataTypeInfo(typeCode.ToString().ToUpperInvariant(), meta.ToArray()));
        }
Exemplo n.º 11
0
        public static SqlStatement Create(PlSqlParser.CreateSequenceStatementContext context)
        {
            var seqName = Name.Object(context.objectName());

            var statement = new CreateSequenceStatement(seqName);

            var startWith = context.sequenceStartClause();

            if (startWith != null)
            {
                statement.StartWith = SqlExpression.Constant(Number.PositiveInteger(startWith.UNSIGNED_INTEGER()));
            }

            var specs = context.sequenceSpec();

            if (specs != null && specs.Length > 0)
            {
                foreach (var spec in specs)
                {
                    if (spec.INCREMENT() != null &&
                        spec.BY() != null)
                    {
                        statement.IncrementBy = SqlExpression.Constant(Number.PositiveInteger(spec.UNSIGNED_INTEGER()));
                    }
                    else if (spec.MAXVALUE() != null)
                    {
                        statement.MaxValue = SqlExpression.Constant(Number.PositiveInteger(spec.UNSIGNED_INTEGER()));
                    }
                    else if (spec.NOMAXVALUE() != null)
                    {
                        statement.MaxValue = SqlExpression.Constant(null);
                    }
                    else if (spec.MINVALUE() != null)
                    {
                        statement.MinValue = SqlExpression.Constant(Number.PositiveInteger(spec.UNSIGNED_INTEGER()));
                    }
                    else if (spec.NOMINVALUE() != null)
                    {
                        statement.MinValue = SqlExpression.Constant(null);
                    }
                    else if (spec.CACHE() != null)
                    {
                        statement.Cache = SqlExpression.Constant(Number.PositiveInteger(spec.UNSIGNED_INTEGER()));
                    }
                    else if (spec.NOCACHE() != null)
                    {
                        statement.Cache = SqlExpression.Constant(null);
                    }
                    else if (spec.CYCLE() != null)
                    {
                        statement.Cycle = true;
                    }
                    else if (spec.NOCYCLE() != null)
                    {
                        statement.Cycle = false;
                    }
                }
            }

            return(statement);
        }