public void ProcessWithCtesAndXmlNamespaces(WithCtesAndXmlNamespaces Cte)
 {
     foreach (CommonTableExpression Expression in Cte.CommonTableExpressions)
     {
         _smells.ProcessQueryExpression(Expression.QueryExpression, "RG", false, Cte);
     }
 }
Beispiel #2
0
 public void Process(SelectStatement SelStatement, string ParentType, bool TestTop = false,
                     WithCtesAndXmlNamespaces Cte = null)
 {
     if (Cte == null && SelStatement.WithCtesAndXmlNamespaces != null)
     {
         Cte = SelStatement.WithCtesAndXmlNamespaces;
         if (Cte != null)
         {
             _smells.InsertProcessor.ProcessWithCtesAndXmlNamespaces(Cte);
         }
     }
     _smells.ProcessQueryExpression(SelStatement.QueryExpression, ParentType, false, Cte);
     ProcessOptimizerHints(SelStatement.OptimizerHints, SelStatement);
 }
Beispiel #3
0
        private void ProcessWhereScalarExpression(ScalarExpression WhereExpression)
        {
            string ExpressionType = FragmentTypeParser.GetFragmentType(WhereExpression);
            String ParameterType;

            switch (ExpressionType)
            {
            case "ConvertCall":
                var ConvertCall = (ConvertCall)WhereExpression;
                ParameterType = FragmentTypeParser.GetFragmentType(ConvertCall.Parameter);
                if (ParameterType == "ColumnReferenceExpression")
                {
                    _smells.SendFeedBack(6, ConvertCall);
                }
                break;

            case "CastCall":
                var CastCall = (CastCall)WhereExpression;
                ParameterType = FragmentTypeParser.GetFragmentType(CastCall.Parameter);
                if (ParameterType == "ColumnReferenceExpression")
                {
                    _smells.SendFeedBack(6, CastCall);
                }
                break;

            case "ScalarSubquery":
                var SubQuery = (ScalarSubquery)WhereExpression;
                _smells.ProcessQueryExpression(SubQuery.QueryExpression, "RG");
                break;
            }
        }
Beispiel #4
0
        private void ProcessTableReference(TableReference TableRef, WithCtesAndXmlNamespaces cte)
        {
            string Type = FragmentTypeParser.GetFragmentType(TableRef);

            switch (Type)
            {
            case "NamedTableReference":
                var NamedTableRef = (NamedTableReference)TableRef;
                if (NamedTableRef.SchemaObject.BaseIdentifier.Value[0] != '#' &&
                    NamedTableRef.SchemaObject.BaseIdentifier.Value[0] != '@')
                {
                    if (NamedTableRef.SchemaObject.ServerIdentifier != null)
                    {
                        _smells.SendFeedBack(1, NamedTableRef);
                    }
                    if (NamedTableRef.SchemaObject.SchemaIdentifier == null &&
                        !isCteName(NamedTableRef.SchemaObject, cte))
                    {
                        _smells.SendFeedBack(2, NamedTableRef);
                    }
                }
                if (NamedTableRef.TableHints != null)
                {
                    foreach (TableHint TableHint in NamedTableRef.TableHints)
                    {
                        switch (TableHint.HintKind)
                        {
                        case TableHintKind.NoLock:
                            _smells.SendFeedBack(3, TableHint);
                            break;

                        case TableHintKind.ReadPast:
                            break;

                        case TableHintKind.ForceScan:
                            _smells.SendFeedBack(44, TableHint);
                            break;

                        case TableHintKind.Index:
                            _smells.SendFeedBack(45, TableHint);
                            break;

                        default:
                            _smells.SendFeedBack(4, TableHint);
                            break;
                        }
                    }
                }
                break;

            case "QueryDerivedTable":

                var    QueryDerivedRef = (QueryDerivedTable)TableRef;
                String Alias           = QueryDerivedRef.Alias.Value;
                if (Alias.Length == 1)
                {
                    _smells.SendFeedBack(11, QueryDerivedRef);
                }
                if (FragmentTypeParser.GetFragmentType(QueryDerivedRef.QueryExpression) == "QuerySpecification")
                {
                    //    QuerySpecification QuerySpec = (QuerySpecification)QueryDerivedRef.QueryExpression;
                    //  Process(QuerySpec.FromClause, cte);
                    _smells.ProcessQueryExpression(QueryDerivedRef.QueryExpression, "RG", true, cte);
                }
                break;

            case "QualifiedJoin":
                var QualifiedJoin = (QualifiedJoin)TableRef;
                ProcessTableReference(QualifiedJoin.FirstTableReference, cte);
                ProcessTableReference(QualifiedJoin.SecondTableReference, cte);
                break;
            }
        }