Exemplo n.º 1
0
        private void ProcessFunctionCall(FunctionCall functionCall)
        {
            var func = functionCall.FunctionName.Value;

            if (!SqlUtils.IsBuiltInFunction(func))
            {
                SelectTables.Add(func);
            }
        }
Exemplo n.º 2
0
        private IList <TableIdentifier> ProcessTableReferences(IList <TableReference> tRefs, SqlAction action, HashSet <string> tablesParam = null)
        {
            var identifiers = new List <TableIdentifier>();

            if (tRefs != null)
            {
                foreach (var tref in tRefs)
                {
                    var namedRef = tref as NamedTableReference;
                    if (namedRef != null)
                    {
                        var tables     = tablesParam ?? GetTables(action);
                        var identifier = new TableIdentifier(string.Empty, string.Empty);
                        if (!string.IsNullOrWhiteSpace(namedRef?.Alias?.Value))
                        {
                            identifier.Alias = namedRef?.Alias?.Value;
                        }
                        var table = GetVal(namedRef);
                        identifier.Name = table;
                        identifiers.Add(identifier);
                        if (table != null)
                        {
                            tables.Add(table);
                        }
                    }

                    var joinRef = tref as QualifiedJoin;
                    if (joinRef != null)
                    {
                        var joinIds = ProcessJoin(joinRef, action);
                        identifiers.AddRange(joinIds);
                    }

                    var uqJoinRef = tref as UnqualifiedJoin;
                    if (uqJoinRef != null)
                    {
                        var joinIds = ProcessJoin(uqJoinRef, action);
                        identifiers.AddRange(joinIds);
                    }

                    var pivotedRef = tref as PivotedTableReference;
                    if (pivotedRef != null)
                    {
                        ProcessTableReference(pivotedRef.TableReference, SqlAction.Select);
                    }

                    if (tref is QueryDerivedTable)
                    {
                        var queryExpr =
                            (tref as QueryDerivedTable).QueryExpression;
                        if (queryExpr != null)
                        {
                            ProcessSelect(queryExpr);
                        }
                    }
                    else
                    if (tref is SchemaObjectFunctionTableReference)
                    {
                        var schemaObject = tref as SchemaObjectFunctionTableReference;
                        var function     = GetVal(schemaObject.SchemaObject);
                        var id           = new TableIdentifier(schemaObject.Alias?.Value, function);
                        identifiers.Add(id);
                        if (!string.IsNullOrWhiteSpace(function))
                        {
                            SelectTables.Add(function);
                        }
                    }
                }
            }
            return(identifiers);
        }