public void ProcessTableVariableStatement(DeclareTableVariableStatement Fragment)
 {
     if (Fragment.Body.VariableName.Value.Length <= 2)
     {
         _smells.SendFeedBack(33, Fragment);
     }
 }
예제 #2
0
        public void ProcessTopFilter(TopRowFilter TopFilter)
        {
            IntegerLiteral TopLiteral = null;

            if (FragmentTypeParser.GetFragmentType(TopFilter.Expression) != "ParenthesisExpression")
            {
                _smells.SendFeedBack(34, TopFilter);
                if (FragmentTypeParser.GetFragmentType(TopFilter.Expression) == "IntegerLiteral")
                {
                    TopLiteral = (IntegerLiteral)TopFilter.Expression;
                }
            }
            else
            {
                var ParenthesisExpression = (ParenthesisExpression)TopFilter.Expression;
                if (FragmentTypeParser.GetFragmentType(ParenthesisExpression.Expression) == "IntegerLiteral")
                {
                    TopLiteral = (IntegerLiteral)ParenthesisExpression.Expression;
                }
            }
            if (TopFilter.Percent && TopLiteral != null && TopLiteral.Value == "100")
            {
                _smells.SendFeedBack(35, TopLiteral);
            }
        }
예제 #3
0
 private void TestProcedureReference(ProcedureReference PrcRef)
 {
     if (PrcRef.Name.SchemaIdentifier == null)
     {
         _smells.SendFeedBack(24, PrcRef);
     }
 }
예제 #4
0
        private void ProcessWhereBooleanExpression(BooleanExpression BooleanExpression)
        {
            string ExpressionType = FragmentTypeParser.GetFragmentType(BooleanExpression);

            switch (ExpressionType)
            {
            case "BooleanComparisonExpression":
                var BoolComp = (BooleanComparisonExpression)BooleanExpression;
                ProcessWhereScalarExpression(BoolComp.FirstExpression);
                ProcessWhereScalarExpression(BoolComp.SecondExpression);
                if ((BoolComp.ComparisonType == BooleanComparisonType.Equals) &&
                    (FragmentTypeParser.GetFragmentType(BoolComp.FirstExpression) == "NullLiteral" ||
                     FragmentTypeParser.GetFragmentType(BoolComp.SecondExpression) == "NullLiteral")
                    )
                {
                    _smells.SendFeedBack(46, BoolComp);
                }

                break;

            case "BooleanBinaryExpression":
                var BoolExpression = (BooleanBinaryExpression)BooleanExpression;
                ProcessWhereBooleanExpression(BoolExpression.FirstExpression);
                ProcessWhereBooleanExpression(BoolExpression.SecondExpression);
                break;

            default:
                break;
            }
        }
예제 #5
0
        public void ProcessFunctionCall(FunctionCall FunctionCall)
        {
            if (FunctionCall.OverClause != null)
            {
                if (FunctionCall.OverClause.WindowFrameClause != null)
                {
                    if (FunctionCall.OverClause.WindowFrameClause.WindowFrameType == WindowFrameType.Range)
                    {
                        _smells.SendFeedBack(25, FunctionCall.OverClause.WindowFrameClause);
                    }
                }
                else
                {
                    if (FunctionCall.OverClause.OrderByClause != null)
                    {
                        switch (FunctionCall.FunctionName.Value.ToLower())
                        {
                        case "row_number":
                        case "rank":
                        case "dense_rank":
                        case "ntile":
                        case "lag":
                        case "lead":
                            break;

                        default:
                            _smells.SendFeedBack(26, FunctionCall.OverClause);
                            break;
                        }
                    }
                }
            }
        }
예제 #6
0
        private void ProcessGeneralSetCommand(GeneralSetCommand SetCommand)
        {
            switch (SetCommand.CommandType)
            {
            case GeneralSetCommandType.DateFirst:
                _smells.SendFeedBack(9, SetCommand);
                break;

            case GeneralSetCommandType.DateFormat:
                _smells.SendFeedBack(8, SetCommand);
                break;
            }
        }
예제 #7
0
        public void Process(InsertStatement Fragment)
        {
            if (Fragment.InsertSpecification.Columns.Count == 0)
            {
                _smells.SendFeedBack(12, Fragment);
            }

            switch (FragmentTypeParser.GetFragmentType(Fragment.InsertSpecification.InsertSource))
            {
            case "SelectInsertSource":
                var InsSource = (SelectInsertSource)Fragment.InsertSpecification.InsertSource;
                WithCtesAndXmlNamespaces Cte = Fragment.WithCtesAndXmlNamespaces;
                _smells.ProcessQueryExpression(InsSource.Select, "RG", false, Cte);
                if (Cte != null)
                {
                    ProcessWithCtesAndXmlNamespaces(Cte);
                }
                break;

            case "ExecuteInsertSource":
                var ExecSource = (ExecuteInsertSource)Fragment.InsertSpecification.InsertSource;
                //ProcessExecuteSpecification(ExecSource.Execute);
                ExecutableEntity ExecutableEntity = ExecSource.Execute.ExecutableEntity;
                _smells.ExecutableEntityProcessor.ProcessExecutableEntity(ExecutableEntity);
                break;
            }
        }
예제 #8
0
 public void ProcessCursorStatement(DeclareCursorStatement CursorStatement)
 {
     if (CursorStatement.CursorDefinition == null || CursorStatement.CursorDefinition.Options.Count == 0)
     {
         _smells.SendFeedBack(29, CursorStatement);
     }
 }
 private void TestViewReference(SchemaObjectName ObjectName)
 {
     if (ObjectName.SchemaIdentifier == null)
     {
         _smells.SendFeedBack(24, ObjectName);
     }
 }
 public void ProcessSetTransactionIolationLevelStatement(SetTransactionIsolationLevelStatement Statement)
 {
     switch (Statement.Level)
     {
     case IsolationLevel.ReadUncommitted:
         _smells.SendFeedBack(10, Statement);
         break;
     }
 }
예제 #11
0
        private void ProcessOrderExpression(ExpressionWithSortOrder Expression)
        {
            string SubExpressionType = FragmentTypeParser.GetFragmentType(Expression.Expression);

            switch (SubExpressionType)
            {
            case "IntegerLiteral":
                _smells.SendFeedBack(7, Expression);
                break;

            case "CastCall":
                var CastCall = (CastCall)Expression.Expression;
                if (FragmentTypeParser.GetFragmentType(CastCall.Parameter) == "ColumnReferenceExpression")
                {
                    _smells.SendFeedBack(6, Expression);
                }
                break;
            }
        }
        public void ProcessExecutableEntity(ExecutableEntity ExecutableEntity)
        {
            switch (FragmentTypeParser.GetFragmentType(ExecutableEntity))
            {
            case "ExecutableProcedureReference":
                var ProcReference = (ExecutableProcedureReference)ExecutableEntity;
                if (ProcReference.ProcedureReference.ProcedureReference.Name.SchemaIdentifier == null &&
                    !ProcReference.ProcedureReference.ProcedureReference.Name.BaseIdentifier.Value.StartsWith(
                        "sp_", StringComparison.OrdinalIgnoreCase))
                {
                    _smells.SendFeedBack(21, ExecutableEntity);
                }
                if (
                    ProcReference.ProcedureReference.ProcedureReference.Name.BaseIdentifier.Value.Equals(
                        "sp_executesql", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (ExecuteParameter Param in ExecutableEntity.Parameters)
                    {
                        if (Param.Variable.Name.Equals("@stmt", StringComparison.OrdinalIgnoreCase))
                        {
                            if (FragmentTypeParser.GetFragmentType(Param.ParameterValue) == "VariableReference")
                            {
                                var var = (VariableReference)Param.ParameterValue;
                                if (TestVariableAssigmentChain(var.Name))
                                {
                                    _smells.SendFeedBack(43, ExecutableEntity);
                                }
                            }
                        }
                    }
                }
                break;

            case "ExecutableStringList":
                var StringList = (ExecutableStringList)ExecutableEntity;
                if (InjectionTesting(StringList))
                {
                    _smells.SendFeedBack(43, ExecutableEntity);
                }
                break;
            }
        }
예제 #13
0
        private void ProcessSelectElement(SelectElement SelectElement, string ParentType, WithCtesAndXmlNamespaces Cte)
        {
            string ElemType = FragmentTypeParser.GetFragmentType(SelectElement);

            switch (ElemType)
            {
            case "SelectStarExpression":
                _smells.SendFeedBack(5, SelectElement);
                break;

            case "SelectScalarExpression":

                var    ScalarExpression = (SelectScalarExpression)SelectElement;
                string ExpressionType   = FragmentTypeParser.GetFragmentType(ScalarExpression.Expression);
                switch (ExpressionType)
                {
                case "ScalarSubquery":
                    var SubQuery = (ScalarSubquery)ScalarExpression.Expression;
                    _smells.ProcessQueryExpression(SubQuery.QueryExpression, ParentType, false, Cte);
                    break;

                case "ColumnReferenceExpression":
                    var Expression = (ColumnReferenceExpression)ScalarExpression.Expression;
                    break;

                case "FunctionCall":
                    _smells.FunctionProcessor.ProcessFunctionCall((FunctionCall)ScalarExpression.Expression);
                    break;

                case "IntegerLiteral":
                    break;

                case "ConvertCall":
                    break;
                }
                break;

            case "SelectSetVariable":
                _smells.SelectSetProcessor.ProcessSelectSetVariable((SelectSetVariable)SelectElement);
                break;
            }
        }
예제 #14
0
 public void ProcessDeclareVariableElement(DeclareVariableElement Element)
 {
     if (Element.VariableName.Value.Length <= 2)
     {
         _smells.SendFeedBack(33, Element);
     }
     _smells.ProcessTsqlFragment(Element.DataType);
     if (Element.Value != null)
     {
         _smells.ProcessTsqlFragment(Element.Value);
     }
 }
        public void ProcessFunctionStatementBody(FunctionStatementBody Function)
        {
            if (Function.Name.SchemaIdentifier == null)
            {
                _smells.SendFeedBack(24, Function.Name);
            }

            _smells.ProcessTsqlFragment(Function.ReturnType);

            if (Function.StatementList != null)
            {
                foreach (TSqlFragment Statement in Function.StatementList.Statements)
                {
                    _smells.ProcessTsqlFragment(Statement);
                }
            }
        }
        public void ProcessSqlDataTypeReference(SqlDataTypeReference DataType)
        {
            if (DataType.SqlDataTypeOption == SqlDataTypeOption.Table)
            {
            }

            switch (DataType.SqlDataTypeOption)
            {
            case SqlDataTypeOption.Table:
                break;

            case SqlDataTypeOption.Text:
            case SqlDataTypeOption.NText:
            case SqlDataTypeOption.Image:
                _smells.SendFeedBack(47, DataType);
                break;
            }
        }
예제 #17
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;
            }
        }
예제 #18
0
        public void ProcessPredicateSetStatement(PredicateSetStatement Fragment)
        {
            switch (Fragment.Options)
            {
            case SetOptions.AnsiNulls:
                if (!Fragment.IsOn)
                {
                    _smells.SendFeedBack(14, Fragment);
                }
                return;

            case SetOptions.AnsiPadding:
                if (!Fragment.IsOn)
                {
                    _smells.SendFeedBack(15, Fragment);
                }
                return;

            case SetOptions.AnsiWarnings:
                if (!Fragment.IsOn)
                {
                    _smells.SendFeedBack(16, Fragment);
                }
                return;

            case SetOptions.ArithAbort:
                if (!Fragment.IsOn)
                {
                    _smells.SendFeedBack(17, Fragment);
                }
                return;

            case SetOptions.NumericRoundAbort:
                if (Fragment.IsOn)
                {
                    _smells.SendFeedBack(18, Fragment);
                }
                return;

            case SetOptions.QuotedIdentifier:
                if (!Fragment.IsOn)
                {
                    _smells.SendFeedBack(19, Fragment);
                }
                return;

            case SetOptions.ForcePlan:
                if (Fragment.IsOn)
                {
                    _smells.SendFeedBack(20, Fragment);
                }
                return;

            case SetOptions.ConcatNullYieldsNull:
                if (!Fragment.IsOn)
                {
                    _smells.SendFeedBack(13, Fragment);
                }
                return;

            case SetOptions.NoCount:
                if (Fragment.IsOn)
                {
                    _smells.ProcedureStatementBodyProcessor.NoCountSet = true;
                }
                return;
            }
        }
예제 #19
0
        public void ProcessCreateTable(CreateTableStatement TblStmt)
        {
            bool isTemp = TblStmt.SchemaObjectName.BaseIdentifier.Value.StartsWith("#") ||
                          TblStmt.SchemaObjectName.BaseIdentifier.Value.StartsWith("@");


            if (TblStmt.SchemaObjectName.SchemaIdentifier == null &&
                !isTemp
                )
            {
                _smells.SendFeedBack(27, TblStmt);
            }
            {
                foreach (ColumnDefinition colDef in TblStmt.Definition.ColumnDefinitions)
                {
                    _smells.ProcessTsqlFragment(colDef);
                }
            }

            if (isTemp)
            {
                foreach (ConstraintDefinition constDef in TblStmt.Definition.TableConstraints)
                {
                    if (constDef.ConstraintIdentifier != null)
                    {
                    }
                    switch (FragmentTypeParser.GetFragmentType(constDef))
                    {
                    case "UniqueConstraintDefinition":
                        UniqueConstraintDefinition unqConst = (UniqueConstraintDefinition)constDef;
                        if (unqConst.IsPrimaryKey)
                        {
                            _smells.SendFeedBack(38, constDef);
                        }
                        break;
                    }
                }
                foreach (ColumnDefinition colDef in TblStmt.Definition.ColumnDefinitions)
                {
                    if (colDef.DefaultConstraint != null && colDef.DefaultConstraint.ConstraintIdentifier != null)
                    {
                        _smells.SendFeedBack(39, colDef);
                    }
                    foreach (ConstraintDefinition constDef in colDef.Constraints)
                    {
                        if (constDef.ConstraintIdentifier != null)
                        {
                        }
                        switch (FragmentTypeParser.GetFragmentType(constDef))
                        {
                        case "CheckConstraintDefinition":
                            CheckConstraintDefinition chkConst = (CheckConstraintDefinition)constDef;
                            if (chkConst.ConstraintIdentifier != null)
                            {
                                _smells.SendFeedBack(40, chkConst);;
                            }
                            break;
                        }
                    }
                }
            }
        }