예제 #1
0
        /// <summary>
        /// Sanitized comparison of the view sql
        /// </summary>
        /// <param name="view1">The view1.</param>
        /// <param name="view2">The view2.</param>
        /// <returns></returns>
        public bool CompareView(string view1, string view2)
        {
            //trim any extra whitespace around the sql
            var sql1 = (view1 == null) ? string.Empty : view1.Trim();
            var sql2 = view2.Trim();

            if (_sqlType != SqlType.SqlServerCe && _sqlType != SqlType.SqlServer)
            {
                return(sql1 == sql2);
            }

            //the create view could take many forms:
            //create view "Alphabetical list of products" AS ...
            //create view [dbo].[Alphabetical list of products] AS ...

            //let's strip that bit for the comparison...

            sql1 = SanitizeSql.StripComments(sql1);
            sql2 = SanitizeSql.StripComments(sql2);

            var reg   = new Regex(@"\bCREATE VIEW\b(.*?)(?=\bAS\b)", RegexOptions.IgnoreCase);
            var match = reg.Match(sql1);

            if (match.Success)
            {
                sql1 = sql1.Remove(match.Index, match.Length);
            }
            match = reg.Match(sql2);
            if (match.Success)
            {
                sql2 = sql2.Remove(match.Index, match.Length);
            }
            return(sql1 == sql2);
        }
예제 #2
0
        public bool CompareProcedure(string procedure1, string procedure2)
        {
            //trim any extra whitespace around the sql
            var sql1 = procedure1.Trim();
            var sql2 = procedure2.Trim();

            if (_sqlType != SqlType.SqlServerCe && _sqlType != SqlType.SqlServer)
            {
                return(sql1 == sql2);
            }

            sql1 = SanitizeSql.StripComments(sql1);
            sql2 = SanitizeSql.StripComments(sql2);

            return(sql1 == sql2);
        }