예제 #1
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);
        }
예제 #2
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
            };
        }