コード例 #1
0
        /// <summary>
        /// expression :
        ///       cursor_expression
        ///     | logical_expression
        ///     | VARIABLE_SESSION
        ///     ;
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override object VisitExpression([NotNull] PlSqlParser.ExpressionContext context)
        {
            object result = null;

            var cursor_expression = context.cursor_expression();

            if (cursor_expression != null)
            {
                result = this.VisitCursor_expression(cursor_expression);
            }
            else
            {
                var logical_expression = context.logical_expression();
                if (logical_expression != null)
                {
                    result = this.VisitLogical_expression(logical_expression);
                }
                else
                {
                    var variable_session = context.VARIABLE_SESSION();
                    if (variable_session != null)
                    {
                        result = new OCodeVariableReferenceExpression()
                        {
                            Name = variable_session.GetCleanedText()
                        }
                    }
                    ;
                }
            }

            Debug.Assert(result != null);

            return(result);
        }
コード例 #2
0
        public override SqlExpression VisitExpression(PlSqlParser.ExpressionContext context)
        {
            var exps = context.logicalAndExpression().Select(Visit).ToArray();

            if (exps.Length == 1)
            {
                return(exps[0]);
            }

            SqlExpression last = null;

            foreach (var exp in exps)
            {
                if (last == null)
                {
                    last = exp;
                }
                else
                {
                    last = SqlExpression.Or(last, exp);
                }
            }

            return(last);
        }
コード例 #3
0
        /// <summary>
        /// datatype
        ///     : native_datatype_element precision_part? (WITH LOCAL? TIME ZONE | CHARACTER SET char_set_name)?
        ///     | INTERVAL(YEAR | DAY) ('(' expression ')')? TO(MONTH | SECOND) ('(' expression ')')?
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override object VisitDatatype([NotNull] PlSqlParser.DatatypeContext context)
        {
            var result = new OracleType()
            {
            };

            var native_datatype_element = context.native_datatype_element();

            if (native_datatype_element != null)
            {
                result.Name = (string)native_datatype_element.Accept <object>(this);

                var precision_part = context.precision_part();
                if (precision_part != null)
                {
                    //  '(' numeric (',' numeric)? (CHAR | BYTE)? ')'

                    var values = precision_part.numeric().Select(c => c.Accept <object>(this)).Cast <int>().ToList();

                    if (values.Count == 1)
                    {
                        result.DataPrecision = values[0];
                    }
                    else if (values.Count == 2)
                    {
                        var _dec  = (System.Math.Pow(10, (double)values[1].ToString().Length));
                        var _dec2 = (values[1]) / _dec;
                        result.DataPrecision = new decimal(values[0]) + new decimal(_dec2);
                    }
                    else
                    {
                        Stop();
                    }
                }

                if (context.WITH() != null)
                {
                    result.Name += " WITH";
                    if (context.LOCAL() != null)
                    {
                        result.Name += " LOCAL";
                    }

                    if (context.TIME() != null && context.ZONE() != null)
                    {
                        result.Name += " TIME ZONE";
                    }
                }
                else if (context.CHARACTER() != null && context.SET() != null)
                {
                    Stop();
                    context.char_set_name();
                }
            }
            else
            {
                Stop();

                if (context.INTERVAL() != null)
                {
                    var day  = context.DAY() != null;
                    var year = context.YEAR() != null;
                }

                PlSqlParser.ExpressionContext expression1 = null;
                PlSqlParser.ExpressionContext expression2 = null;

                var expressions = context.expression();

                var to     = context.TO();
                var month  = context.MONTH();
                var second = context.SECOND();

                if (expressions.Length == 2)
                {
                    Stop();
                    expression1 = expressions[0];
                    expression2 = expressions[1];
                }
                if (expressions.Length == 1)
                {
                    Stop();
                    expression1 = expressions[0];
                    if (expression1.Start.StartIndex > to.Symbol.StartIndex)
                    {
                        expression2 = expression1;
                        expression1 = null;
                    }
                }
                else
                {
                    Stop();
                }
            }

            return(result);
        }