예제 #1
0
        private void ResolvePlSqlReferences(OraclePlSqlProgram program)
        {
            ResolveProgramReferences(program.ProgramReferences, true);

            foreach (var variableReference in program.PlSqlVariableReferences.Concat(program.SqlModels.SelectMany(m => m.AllReferenceContainers).SelectMany(c => c.PlSqlVariableReferences)))
            {
                TryResolveLocalReference(variableReference, program.AccessibleVariables, variableReference.Variables);
            }

            var sourceColumnReferences = program.ColumnReferences
                                         .Concat(
                program.SqlModels
                .SelectMany(m => m.AllReferenceContainers)
                .SelectMany(c => c.ColumnReferences)
                .Where(c => !c.ReferencesAllColumns && c.ColumnNodeColumnReferences.Count == 0 && c.ObjectNodeObjectReferences.Count == 0))
                                         .ToArray();

            foreach (var columnReference in sourceColumnReferences)
            {
                var variableReference =
                    new OraclePlSqlVariableReference
                {
                    PlSqlProgram   = program,
                    IdentifierNode = columnReference.ColumnNode
                };

                variableReference.CopyPropertiesFrom(columnReference);

                var elementSource    = variableReference.PlSqlProgram.AccessibleVariables.Concat(variableReference.PlSqlProgram.Parameters);
                var variableResolved = TryResolveLocalReference(variableReference, elementSource, variableReference.Variables);
                if (variableResolved)
                {
                    columnReference.Container.ColumnReferences.Remove(columnReference);
                }
                else
                {
                    variableResolved = !TryColumnReferenceAsProgramOrSequenceReference(columnReference, true);
                }

                if (variableResolved && !IsBooleanLiteral(columnReference))
                {
                    program.PlSqlVariableReferences.Add(variableReference);
                }
            }

            program.ColumnReferences.Clear();

            foreach (var exceptionReference in program.PlSqlExceptionReferences)
            {
                TryResolveLocalReference(exceptionReference, program.Exceptions, exceptionReference.Exceptions);
            }

            foreach (var dataTypeReference in program.DataTypeReferences)
            {
                OracleReferenceBuilder.ResolveSchemaType(dataTypeReference);
            }

            ResolveSubProgramReferences(program.SubPrograms);
        }
예제 #2
0
        private void FindPlSqlReferences(OraclePlSqlProgram program, StatementGrammarNode node)
        {
            if (node == null)
            {
                return;
            }

            var excludedIdentifiers = new HashSet <StatementGrammarNode>();

            switch (node.Id)
            {
            case NonTerminals.PlSqlRaiseStatement:
                var prefixedExceptionIdentifierNode = node[NonTerminals.PrefixedExceptionIdentifier];
                CreatePlSqlExceptionReference(program, prefixedExceptionIdentifierNode);
                break;

            case NonTerminals.PlSqlCursorForLoopStatement:
                var cursorIdentifier = node[Terminals.PlSqlIdentifier];
                var cursorScopeNode  = node[NonTerminals.PlSqlBasicLoopStatement];
                if (cursorIdentifier != null && cursorScopeNode != null)
                {
                    excludedIdentifiers.Add(cursorIdentifier);

                    var cursor =
                        new OraclePlSqlCursorVariable
                    {
                        Name           = cursorIdentifier.Token.Value.ToQuotedIdentifier(),
                        IsImplicit     = true,
                        Owner          = program,
                        DefinitionNode = cursorIdentifier,
                        ScopeNode      = cursorScopeNode
                    };

                    SetStatementModelIfFound(cursor, node[NonTerminals.CursorSource, NonTerminals.SelectStatement]);

                    program.Variables.Add(cursor);

                    var cursorReferenceIdentifier = node[NonTerminals.CursorSource, Terminals.CursorIdentifier];
                    if (cursorReferenceIdentifier != null)
                    {
                        var cursorReference =
                            new OraclePlSqlVariableReference
                        {
                            RootNode       = cursorReferenceIdentifier.ParentNode,
                            IdentifierNode = cursorReferenceIdentifier,
                            //ObjectNode = cursorIdentifierNode.ParentNode[NonTerminals.ObjectPrefix, Terminals.ObjectIdentifier],
                            //OwnerNode = cursorIdentifierNode.ParentNode[NonTerminals.SchemaPrefix, Terminals.SchemaIdentifier],
                            Container    = program,
                            PlSqlProgram = program
                        };

                        program.PlSqlVariableReferences.Add(cursorReference);
                    }
                }

                goto default;

            case NonTerminals.PlSqlForLoopStatement:
                var identifier = node[Terminals.PlSqlIdentifier];
                var scopeNode  = node[NonTerminals.PlSqlBasicLoopStatement];
                if (identifier != null && scopeNode != null)
                {
                    excludedIdentifiers.Add(identifier);

                    var variable =
                        new OraclePlSqlVariable
                    {
                        Name           = identifier.Token.Value.ToQuotedIdentifier(),
                        Owner          = program,
                        DefinitionNode = identifier,
                        DataType       = OracleDataType.BinaryIntegerType,
                        ScopeNode      = scopeNode
                    };

                    program.Variables.Add(variable);
                }

                goto default;

            default:
                var identifiers = node.GetPathFilterDescendants(NodeFilters.BreakAtPlSqlSubProgramOrSqlCommand, Terminals.Identifier, Terminals.PlSqlIdentifier, Terminals.RowIdPseudocolumn, Terminals.Level, Terminals.RowNumberPseudocolumn, Terminals.User)
                                  .Where(i => !excludedIdentifiers.Contains(i));

                ResolveColumnFunctionOrDataTypeReferencesFromIdentifiers(null, program, identifiers, StatementPlacement.None, null, null, GetFunctionCallNodes);

                var grammarSpecificFunctions = GetGrammarSpecificFunctionNodes(node);
                CreateGrammarSpecificFunctionReferences(grammarSpecificFunctions, program, null, StatementPlacement.None, null);
                break;
            }
        }
 public void VisitPlSqlVariableReference(OraclePlSqlVariableReference variableReference)
 {
     throw new NotSupportedException();
 }