Parse() public static method

public static Parse ( PlSqlParser context ) : SqlType
context PlSqlParser
return SqlType
        public override SqlStatement VisitVariableDeclaration(PlSqlParser.VariableDeclarationContext context)
        {
            var name = Name.Simple(context.variable_name());
            var type = SqlTypeParser.Parse(context.datatype());

            bool notNull  = context.NOT() != null && context.NULL() != null;
            bool constant = context.CONSTANT() != null;

            if (constant)
            {
                notNull = true;
            }

            SqlExpression defaultValue = null;

            if (context.defaultValuePart() != null)
            {
                defaultValue = Expression.Build(context.defaultValuePart().expression());
            }

            return(new DeclareVariableStatement(name, type)
            {
                DefaultExpression = defaultValue,
                IsNotNull = notNull,
                IsConstant = constant
            });
        }
Esempio n. 2
0
            public static CursorParameter Form(PlSqlParser.ParameterSpecContext context)
            {
                var paramName = Name.Simple(context.parameter_name());
                var type      = SqlTypeParser.Parse(context.datatype());

                return(new CursorParameter(paramName, type));
            }
        public override SqlStatement VisitCreateTypeStatement(PlSqlParser.CreateTypeStatementContext context)
        {
            var        orReplace  = context.OR() != null && context.REPLACE() != null;
            var        typeName   = Name.Object(context.objectName());
            ObjectName parentType = null;

            if (context.underClause() != null)
            {
                parentType = Name.Object(context.underClause().objectName());
            }

            bool isSealed = true, isAbstract = false;

            if (context.INSTANTIABLE() != null)
            {
                if (context.NOT() != null)
                {
                    isAbstract = true;
                }
                else
                {
                    isAbstract = false;
                }
            }
            else if (context.FINAL() != null)
            {
                if (context.NOT() != null)
                {
                    isSealed = false;
                }
                else
                {
                    isSealed = true;
                }
            }

            var members = new List <UserTypeMember>();

            foreach (var attributeContext in context.typeAttribute())
            {
                var memberName = Name.Simple(attributeContext.id());
                var memberType = SqlTypeParser.Parse(attributeContext.datatype());

                members.Add(new UserTypeMember(memberName, memberType));
            }

            return(new CreateTypeStatement(typeName, members.ToArray(), orReplace)
            {
                ParentTypeName = parentType,
                IsSealed = isSealed,
                IsAbstract = isAbstract
            });
        }
        public override SqlExpression VisitCastFunction(PlSqlParser.CastFunctionContext context)
        {
            if (context.MULTISET() != null)
            {
                throw new NotImplementedException();
            }

            var destType       = SqlTypeParser.Parse(context.datatype());
            var destTypeString = destType.ToString();

            var value = Visit(context.concatenationWrapper());

            return(SqlExpression.FunctionCall("SQL_CAST", new[] { value, SqlExpression.Constant(destTypeString) }));
        }
Esempio n. 5
0
        public static RoutineParameter Routine(PlSqlParser.ParameterContext context)
        {
            var paramName = Name.Simple(context.parameter_name());
            var paramType = SqlTypeParser.Parse(context.datatype());

            var paramDir = ParameterDirection.Input;

            if (context.IN() != null)
            {
                if (context.OUT() != null)
                {
                    paramDir = ParameterDirection.InputOutput;
                }
                else
                {
                    paramDir = ParameterDirection.Input;
                }
            }
            else if (context.OUT() != null)
            {
                paramDir = ParameterDirection.Output;
            }
            else if (context.INOUT() != null)
            {
                paramDir = ParameterDirection.InputOutput;
            }

            SqlExpression defaultValue = null;
            var           defaultPart  = context.defaultValuePart();

            if (defaultPart != null)
            {
                defaultValue = Expression.Build(defaultPart.expression());
            }

            // TODO: Support default in RoutineParameter
            return(new RoutineParameter(paramName, paramType, paramDir));
        }
Esempio n. 6
0
        public static SqlTableColumn Form(PlSqlParser.TableColumnContext context, List <ColumnConstraint> constraints)
        {
            var columnName = Name.Simple(context.columnName());
            var columnType = SqlTypeParser.Parse(context.datatype());

            if (columnType == null)
            {
                throw new ParseCanceledException("No type was found for table.");
            }

            SqlExpression defaultExpression = null;
            bool          identity          = false;
            bool          nullable          = true;
            string        indexType         = null;

            if (context.IDENTITY() != null)
            {
                if (!(columnType is NumericType))
                {
                    throw new InvalidOperationException("Cannot have an identity column that has not a numeric type");
                }

                identity = true;
            }
            else
            {
                var columnConstraints = context.columnConstraint();
                if (columnConstraints != null &&
                    columnConstraints.Length > 0)
                {
                    foreach (var constraintContext in columnConstraints)
                    {
                        if (constraintContext.PRIMARY() != null)
                        {
                            constraints.Add(new ColumnConstraint {
                                ColumnName = columnName,
                                Type       = ConstraintType.PrimaryKey
                            });
                        }
                        else if (constraintContext.UNIQUE() != null)
                        {
                            constraints.Add(new ColumnConstraint {
                                Type       = ConstraintType.Unique,
                                ColumnName = columnName
                            });
                        }
                        else if (constraintContext.NOT() != null &&
                                 constraintContext.NULL() != null)
                        {
                            nullable = false;
                        }
                    }
                }

                if (context.defaultValuePart() != null)
                {
                    defaultExpression = Expression.Build(context.defaultValuePart().expression());
                }

                if (context.columnIndex() != null)
                {
                    var columnIndex = context.columnIndex();
                    if (columnIndex.BLIST() != null)
                    {
                        indexType = DefaultIndexTypes.InsertSearch;
                    }
                    else if (columnIndex.NONE() != null)
                    {
                        indexType = DefaultIndexTypes.BlindSearch;
                    }
                    else if (columnIndex.id() != null)
                    {
                        indexType = Name.Simple(columnIndex.id());
                    }
                    else if (columnIndex.CHAR_STRING() != null)
                    {
                        indexType = InputString.AsNotQuoted(columnIndex.CHAR_STRING());
                    }
                }
            }

            return(new SqlTableColumn(columnName, columnType)
            {
                IsNotNull = !nullable,
                IsIdentity = identity,
                DefaultExpression = defaultExpression,
                IndexType = indexType
            });
        }