Пример #1
0
        private void ResolveParameterDeclarations(OraclePlSqlProgram program)
        {
            StatementGrammarNode parameterSourceNode;

            switch (program.RootNode.Id)
            {
            case NonTerminals.CreateFunction:
                parameterSourceNode = program.RootNode[NonTerminals.PlSqlFunctionSource];
                break;

            case NonTerminals.CreateProcedure:
                parameterSourceNode = program.RootNode;
                break;

            default:
                parameterSourceNode = program.RootNode[0];
                break;
            }

            var returnParameterNode = parameterSourceNode?[NonTerminals.PlSqlDataTypeWithoutConstraint];
            var parameterPosition   = 0;

            if (returnParameterNode != null)
            {
                program.ReturnParameter =
                    new OraclePlSqlParameter
                {
                    DefinitionNode = parameterSourceNode,
                    Direction      = ParameterDirection.ReturnValue,
                    Nullable       = true,
                    DataTypeNode   = returnParameterNode
                };

                var returnTypeName = String.Concat(returnParameterNode.Terminals.Select(t => t.Token.Value));
                program.Metadata.AddParameter(new OracleProgramParameterMetadata(null, parameterPosition, parameterPosition, 0, ParameterDirection.ReturnValue, returnTypeName, OracleObjectIdentifier.Empty, false));
                parameterPosition++;
            }

            var parameterDeclarationList = parameterSourceNode?[NonTerminals.ParenthesisEnclosedParameterDeclarationList, NonTerminals.ParameterDeclarationList];

            if (parameterDeclarationList == null)
            {
                return;
            }

            var parameterDeclarations = StatementGrammarNode.GetAllChainedClausesByPath(parameterDeclarationList, null, NonTerminals.ParameterDeclarationListChained, NonTerminals.ParameterDeclarationList)
                                        .Select(n => n[NonTerminals.ParameterDeclaration]);

            foreach (var parameterDeclaration in parameterDeclarations)
            {
                var parameter = ResolveParameter(parameterDeclaration);
                program.Parameters.Add(parameter);

                var parameterMetadata = new OracleProgramParameterMetadata(parameter.Name, parameterPosition, parameterPosition, 0, parameter.Direction, parameter.DataType.IsPrimitive ? parameter.DataType.FullyQualifiedName.NormalizedName : null, parameter.DataType.IsPrimitive ? OracleObjectIdentifier.Empty : parameter.DataType.FullyQualifiedName, parameter.DefaultExpressionNode != null);
                program.Metadata.AddParameter(parameterMetadata);

                parameterPosition++;
            }
        }
        private static Grid BuildParameterDescription(OracleProgramParameterMetadata parameterMetadata)
        {
            var descriptionContent = new Grid();

            descriptionContent.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star), SharedSizeGroup = "ParameterName"
            });
            descriptionContent.ColumnDefinitions.Add(new ColumnDefinition {
                Width = GridLength.Auto, SharedSizeGroup = "DataType"
            });
            descriptionContent.ColumnDefinitions.Add(new ColumnDefinition {
                Width = GridLength.Auto, SharedSizeGroup = "Optional"
            });

            var columnNameLabel = new TextBlock {
                Text = parameterMetadata.Name.ToSimpleIdentifier()
            };

            descriptionContent.Children.Add(columnNameLabel);

            var dataTypeLabel =
                new TextBlock
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                Text   = parameterMetadata.FullDataTypeName,
                Margin = new Thickness(20, 0, 0, 0)
            };

            if (parameterMetadata.IsOptional)
            {
                var optionalLabel =
                    new TextBlock
                {
                    HorizontalAlignment = HorizontalAlignment.Right,
                    Margin = new Thickness(4, 0, 0, 0),
                    Text   = "(optional)"
                };

                Grid.SetColumn(optionalLabel, 2);
                descriptionContent.Children.Add(optionalLabel);
            }

            Grid.SetColumn(dataTypeLabel, 1);

            descriptionContent.Children.Add(dataTypeLabel);

            return(descriptionContent);
        }
Пример #3
0
        private static OracleProgramParameterMetadata MapSqlParameterMetadata(IDataRecord reader, IReadOnlyDictionary <int, OracleProgramMetadata> metadataDictionary)
        {
            var functionId = Convert.ToInt32(reader["FUNCTION_ID"]);

            if (!metadataDictionary.TryGetValue(functionId, out OracleProgramMetadata metadata))
            {
                return(null);
            }

            var position = Convert.ToInt32(reader["POSITION"]);
            var dataType = (string)reader["DATATYPE"];

            var parameterMetadata = new OracleProgramParameterMetadata(null, position, position, 0, ParameterDirection.Input, dataType, OracleObjectIdentifier.Empty, false);

            metadata.AddParameter(parameterMetadata);

            return(parameterMetadata);
        }
Пример #4
0
		private static string BuildParameterLabel(OracleProgramParameterMetadata parameterMetadata)
		{
			string parameterName;
			string dataType;
			if (String.IsNullOrEmpty(parameterMetadata.Name))
			{
				parameterName = parameterMetadata.FullDataTypeName;
				dataType = null;
			}
			else
			{
				parameterName = parameterMetadata.Name.ToSimpleIdentifier();
				dataType = parameterMetadata.FullDataTypeName;
			}

			var isPartialMetadata = String.IsNullOrEmpty(parameterMetadata.FullDataTypeName) || dataType == null;
			var parameterLabel = $"{parameterName}{(isPartialMetadata ? null : ": ")}{dataType}";
			if (parameterMetadata.IsOptional)
			{
				parameterLabel = $"[{parameterLabel}]";
			}

			return parameterLabel;
		}