예제 #1
0
    public override void ExplicitVisit(ExecuteStatement node)
    {
        ExecuteSpecification         executeSpec      = node.ExecuteSpecification;
        ExecutableProcedureReference executableEntity = (ExecutableProcedureReference)executeSpec.ExecutableEntity;
        var tokenText = getTokenText(executableEntity.ProcedureReference);

        StatementTargets.Add($"Execute SP: {tokenText}");
    }
예제 #2
0
        public override void Visit(ExecuteSpecification node)
        {
            var proc = node.ExecutableEntity as ExecutableProcedureReference;

            if (proc == null)
            {
                base.Visit(node);
                return;
            }

            var ids = proc.ProcedureReference.ProcedureReference.Name.Identifiers;
            var par = proc.Parameters;

            if ((ids.Count == 1 && ids[0].Value == "sp_addextendedproperty") || (ids.Count == 2 && ids[0].Value == "sys" && ids[1].Value == "sp_addextendedproperty"))
            {
                var parDic = new Dictionary <string, string>();

                foreach (var p in par)
                {
                    var v = p.ParameterValue as StringLiteral;

                    if (v != null)
                    {
                        parDic[p.Variable.Name.Replace("@", "")] = v.Value;
                    }
                }

                if (!new string[] { "level0type", "level0name", "level1type", "level1name", "level2type", "level2name", "name", "value" }.Except(parDic.Keys).Any())
                {
                    if (parDic["name"].ToUpper() == "MS_DESCRIPTION" && parDic["level0type"].ToUpper() == "SCHEMA" && parDic["level1type"].ToUpper() == "TABLE" && parDic["level2type"].ToUpper() == "COLUMN")
                    {
                        this.AddColumnDescription(parDic["level0name"], parDic["level1name"], parDic["level2name"], parDic["value"]);
                    }
                    else
                    {
                        this.logger.LogWarning("Invalid level 2 EXEC sp_addextendedproperty: {0}", node);
                    }
                }
                else if (!new string[] { "level0type", "level0name", "level1type", "level1name", "name", "value" }.Except(parDic.Keys).Any())
                {
                    if (parDic["name"].ToUpper() == "MS_DESCRIPTION" && parDic["level0type"].ToUpper() == "SCHEMA" && parDic["level1type"].ToUpper() == "TABLE")
                    {
                        this.AddTableDescription(parDic["level0name"], parDic["level1name"], parDic["value"]);
                    }
                    else
                    {
                        this.logger.LogWarning("Invalid level 1 EXEC sp_addextendedproperty: {0}", node);
                    }
                }
            }
        }
예제 #3
0
        public static EngineResult Evaluate(ExecuteSpecification exec, Scope scope)
        {
            // TODO: exec.ExecuteContext for permissions
            // TODO: exec.LinkedServer for DB
            var execRef  = (ExecutableProcedureReference)exec.ExecutableEntity;
            var procName = execRef.ProcedureReference.ProcedureReference.Name.Identifiers.Last().Value;
            var proc     = scope.Env.Procedures[procName];

            return(Evaluate(
                       proc,
                       execRef.Parameters
                       .Select(p => (
                                   p.Variable.Name,
                                   !p.IsOutput,
                                   p.IsOutput,
                                   Evaluate(p.ParameterValue, NullArgument.It, scope)))
                       .ToList(),
                       scope));
        }
        public override void ExplicitVisit(ExecuteSpecification node)
        {
            if (node.ExecuteContext != null)
            {
                throw new NotSupportedException();
            }
            if (node.LinkedServer != null)
            {
                throw new NotSupportedException();
            }
            if (node.Variable != null)
            {
                throw new NotSupportedException();
            }

            if (node.ExecutableEntity is ExecutableProcedureReference procedureReference)
            {
                PgExpressionVisitor expressionVisitor = new PgExpressionVisitor(_buffer);
                procedureReference.ProcedureReference.Accept(expressionVisitor);
                _buffer.Append("(");
                for (int index = 0, count = procedureReference.Parameters.Count - 1; index <= count; ++index)
                {
                    ExecuteParameter parameter = procedureReference.Parameters[index];
                    parameter.Accept(expressionVisitor);
                    if (index < count)
                    {
                        _buffer.Append(", ");
                    }
                }
                _buffer.Append(")");
            }
            else
            {
                throw new NotSupportedException();
            }
        }
예제 #5
0
 public override void Visit(ExecuteSpecification node) { this.action(node); }
 public override void ExplicitVisit(ExecuteSpecification fragment)
 {
     _fragments.Add(fragment);
 }
예제 #7
0
        public static IList <FieldPairReference> GetFieldPairReferences(
            this ExecuteSpecification executeSpecification,
            ILogger logger,
            SchemaFile file
            )
        {
            var isSystemObject = executeSpecification
                                 .ExecutableEntity
                                 .GetSchema(logger, file)
                                 .Schema
                                 .Equals(SchemaObject.SystemSchema, StringComparison.InvariantCultureIgnoreCase);

            if (isSystemObject) // ignore system procs for now, we don't store their representation
            {
                return(new List <FieldPairReference>());
            }

            var inputParameters = executeSpecification
                                  .ExecutableEntity
                                  .GetParameters(logger, file)
                                  .ToList();

            if (!inputParameters.Any()) // missing schema object reference
            {
                return(new List <FieldPairReference>());
            }

            // TODO : this needs to be able to handle DEFAULT keyword

            var sourceFieldReferences = executeSpecification
                                        .ExecutableEntity
                                        .Parameters
                                        .Select(p => new
            {
                Fragment  = p,
                Reference = new FieldReference()
                {
                    Alias      = string.Empty,
                    Identifier = p.Variable?.Name ?? string.Empty,
                    Value      = p.ParameterValue.GetField(p.Variable?.Name, logger, file)
                }
            })
                                        .ToList();

            var pairs = sourceFieldReferences
                        .Where(x => string.IsNullOrWhiteSpace(x.Reference.Identifier))
                        .Select((fieldReference, index) =>
            {
                Field parameterValue = null;

                if (index < inputParameters.Count)
                {
                    parameterValue = inputParameters[index].Value;
                }
                else
                {
                    logger.Log(LogLevel.Warning,
                               LogType.TooManyParameters,
                               file.Path,
                               $"Executable entity specifies more than \"{inputParameters.Count}\" parameter(s).");
                    parameterValue = fieldReference.Reference.Value;
                }

                return(new FieldPairReference()
                {
                    Left = parameterValue,
                    Right = fieldReference.Reference.Value,
                    Fragment = fieldReference.Fragment
                });
            })
                        .ToList();

            var parametersMap = inputParameters.ToDictionary(k => k.Value.Name, v => v.Value, StringComparer.InvariantCultureIgnoreCase);
            var mappedPairs   = sourceFieldReferences
                                .Where(x => !string.IsNullOrWhiteSpace(x.Reference.Identifier))
                                .Select(unorderedReference => {
                Field parameter = null;

                if (parametersMap.ContainsKey(unorderedReference.Reference.Identifier))
                {
                    parameter = parametersMap[unorderedReference.Reference.Identifier];
                }
                else
                {
                    logger.Log(LogLevel.Warning,
                               LogType.InvalidParameterIndetifier,
                               file.Path,
                               $"Target procedure doesn't have \"{unorderedReference.Reference.Identifier}\" parameter.");
                    parameter = unorderedReference.Reference.Value;
                }

                return(new FieldPairReference()
                {
                    Left = parameter,
                    Right = unorderedReference.Reference.Value,
                    Fragment = unorderedReference.Fragment
                });
            })
                                .ToList();

            return(pairs
                   .Concat(mappedPairs)
                   .ToList());
        }