コード例 #1
0
        public override void Analyze(SqlFileContext context)
        {
            ColumnDefinition node = (ColumnDefinition)context.Fragment;

            SqlDataTypeReference sdtr = node.DataType as SqlDataTypeReference;

            if (sdtr == null)
            {
                return;
            }

            if (sdtr.SqlDataTypeOption != SqlDataTypeOption.VarBinary &&
                sdtr.SqlDataTypeOption != SqlDataTypeOption.VarChar &&
                sdtr.SqlDataTypeOption != SqlDataTypeOption.NVarChar)
            {
                return;
            }

            if (sdtr.Parameters.Count > 0)
            {
                Region region = sdtr.CreateRegion();

                int size = Int32.Parse(sdtr.Parameters[0].Value);

                if (size <= context.Policy.GetProperty(SmallSizeThreshold))
                {
                    // The data type for column '{0}' was defined as {1} of a
                    // small size ({2}) which may incur additional storage and
                    // performance costs. Declare this data type as a fixed size
                    // or ignore the warning in cases performance is not a concern.
                    context.Logger.Log(this,
                                       RuleUtilities.BuildResult(ResultKind.Warning, context, region,
                                                                 nameof(RuleResources.SQL2009_Default),
                                                                 node.ColumnIdentifier.Value,
                                                                 sdtr.SqlDataTypeOption.ToString(),
                                                                 size.ToString()));
                }
            }
            return;
        }