Example #1
0
        /// <summary>
        /// 获取匹配的列.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string GetMatchedOrderbyColumn(string str)
        {
            var col        = "\\[?[\\w_#@\\$]+\\]?";
            var aliasTable = "\\[?[\\w_#@\\$]+\\]?";

            //"UserNickName"
            var match1 = "^(" + col + ")$";
            //"UserNickName ASC"
            var match2 = "^(" + col + "\\s+ASC)$";
            //"UserNickName DESC"
            var match3 = "^(" + col + "\\s+DESC)$";
            //"dbc.UserNickName"
            var match4 = "^" + aliasTable + "\\.(" + col + ")$";
            //"us.UserNickName ASC"
            var match5 = "^" + aliasTable + "\\.(" + col + "\\s+ASC)$";
            //"us.UserNickName DESC"
            var match6 = "^" + aliasTable + "\\.(" + col + "\\s+DESC)$";


            var matches = new string[] { match1, match2, match3, match4, match5, match6 };
            var colName = string.Empty;
            var i       = 0;

            while (string.IsNullOrWhiteSpace(colName) && i < matches.Length)
            {
                colName = SqlMacher.GetMatchedValueIgnoreCase(str, matches[i]);
                i++;
            }
            return(colName);
        }
Example #2
0
        /// <summary>
        /// 获取匹配的列.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public string GetMatchedSelectColumn(string str)
        {
            var aliasCol   = "\\[?\\'?([\\w_#@\\$]+)\\'?\\]?";
            var col        = "\\[?[\\w_#@\\$]+\\]?";
            var aliasTable = "\\[?[\\w_#@\\$]+\\]?";
            //"UserNickName"
            var match1 = "^(" + col + ")$";
            //"us.UserNickName"
            var match2 = "^" + aliasTable + "\\.(" + col + ")$";
            //"us.UserNickName UserName"
            var match3 = "^" + col + "\\s+" + aliasCol + "$";
            //"UserNickName UserName"
            var match4 = "^" + aliasTable + "\\." + col + "\\s+" + aliasCol + "$";
            //"UserNickName as UserName"
            var match5 = "^" + col + "\\s+AS\\s+" + aliasCol + "$";
            //"us.UserNickName as UserName"
            var match6 = "^" + aliasTable + "\\." + col + "\\s+AS\\s+" + aliasCol + "$";
            //"UserName = us.UserNickName"
            var match8 = "^" + aliasCol + "\\s*=\\s*" + col + "$";
            //"UserName = us.UserNickName"
            var match7  = "^" + aliasCol + "\\s*=\\s*" + aliasTable + "\\." + col + "$";
            var match9  = "[\\w\\W]+" + "\\s+AS\\s+" + aliasCol + "$";
            var match10 = "^" + aliasCol + "\\s*=\\s*[\\w\\W]+";
            var match11 = "[\\w\\W]+" + "\\s+" + aliasCol + "$";
            var match12 = "^(\\*)$";

            var matches = new string[] { match1, match2, match3, match4, match7, match5, match6, match8, match9, match10, match11, match12 };
            var colName = string.Empty;
            var i       = 0;

            while (string.IsNullOrWhiteSpace(colName) && i < matches.Length)
            {
                colName = SqlMacher.GetMatchedValueIgnoreCase(str, matches[i]);
                i++;
            }
            return(colName);
        }