示例#1
0
        public string GetUpdateQuery(QueryInformation predicateQueryInfo, QueryInformation modificationQueryInfo)
        {
            var msql       = modificationQueryInfo.WhereSql.Replace("WHERE ", "");
            var indexOfAnd = msql.IndexOf("AND", StringComparison.Ordinal);
            var update     = indexOfAnd == -1 ? msql : msql.Substring(0, indexOfAnd).Trim();

            var    match = UpdateRegex.Match(update);
            string updateSql;

            if (match.Success)
            {
                var col  = match.Groups[1];
                var rest = match.Groups[2].Value;

                rest = SqlStringHelper.FixParantheses(rest);

                updateSql = col.Value + " = " + rest;
            }
            else
            {
                updateSql = string.Join(" = ", update.Split(new[] { " = " }, StringSplitOptions.RemoveEmptyEntries).Reverse());
            }

            return
                ($"UPDATE [{predicateQueryInfo.Schema}].[{predicateQueryInfo.Table}] SET {updateSql} {predicateQueryInfo.WhereSql}");
        }
        public string GetUpdateQuery(QueryInformation predicateQueryInfo, QueryInformation modificationQueryInfo)
        {
            var msql       = modificationQueryInfo.WhereSql.Replace("WHERE ", "");
            var indexOfAnd = msql.IndexOf("AND");
            var update     = indexOfAnd == -1 ? msql : msql.Substring(0, indexOfAnd).Trim();

            var    updateRegex = new Regex(@"(\[[^\]]+\])[^=]+=(.+)", RegexOptions.IgnoreCase);
            var    match       = updateRegex.Match(update);
            string updateSql;

            if (match.Success)
            {
                var col  = match.Groups[1];
                var rest = match.Groups[2].Value;

                rest = SqlStringHelper.FixParantheses(rest);

                updateSql = col.Value + " = " + rest;
            }
            else
            {
                updateSql = string.Join(" = ", update.Split(new string[] { " = " }, StringSplitOptions.RemoveEmptyEntries).Reverse());
            }


            return(string.Format("UPDATE [{0}].[{1}] SET {2} {3}", predicateQueryInfo.Schema, predicateQueryInfo.Table, updateSql, predicateQueryInfo.WhereSql));
        }
        public QueryInformation GetQueryInformation<T>(System.Data.Entity.Core.Objects.ObjectQuery<T> query)
        {
            var fromRegex = new Regex(@"FROM \[([^\]]+)\]\.\[([^\]]+)\] AS (\[[^\]]+\])", RegexOptions.IgnoreCase);

            var queryInfo = new QueryInformation();

            var str = query.ToTraceString();
            var match = fromRegex.Match(str);
            queryInfo.Schema = match.Groups[1].Value;
            queryInfo.Table = match.Groups[2].Value;
            queryInfo.Alias = match.Groups[3].Value;

            var i = str.IndexOf("WHERE");
            if (i > 0)
            {
                var whereClause = str.Substring(i);
                queryInfo.WhereSql = whereClause.Replace(queryInfo.Alias + ".", "");
            }
            return queryInfo;
        }
示例#4
0
        public QueryInformation GetQueryInformation <T>(System.Data.Entity.Core.Objects.ObjectQuery <T> query)
        {
            var queryInfo = new QueryInformation();

            var str   = query.ToTraceString();
            var match = FromRegex.Match(str);

            queryInfo.Schema = match.Groups[1].Value;
            queryInfo.Table  = match.Groups[2].Value;
            queryInfo.Alias  = match.Groups[3].Value;

            var i = str.IndexOf("WHERE", StringComparison.Ordinal);

            if (i > 0)
            {
                var whereClause = str.Substring(i);
                queryInfo.WhereSql = whereClause.Replace(queryInfo.Alias + ".", "");
            }

            return(queryInfo);
        }
 public string GetDeleteQuery(QueryInformation queryInfo)
 {
     return(string.Format("DELETE FROM [{0}].[{1}] {2}", queryInfo.Schema, queryInfo.Table, queryInfo.WhereSql));
 }
示例#6
0
 public string GetDeleteQuery(QueryInformation queryInfo)
 {
     return($"DELETE {queryInfo.TopExpression} FROM [{queryInfo.Schema}].[{queryInfo.Table}] {queryInfo.WhereSql}");
 }
示例#7
0
 public string GetTruncateQuery(QueryInformation queryInfo)
 {
     return(string.Format("TRUNCATE TABLE [{0}].[{1}]", queryInfo.Schema, queryInfo.Table));
 }