zoukankan      html  css  js  c++  java
  • 数据库IN查询参数化改造的方法

                    // 批量查询的 2019-05-14 
                    if (!string.IsNullOrWhiteSpace(Request["userCodes"]))
                    {
                        string userCodes = Request["userCodes"].Replace("
    ", "").Replace("", ",").Replace(" ", "").Trim('
    ').Trim();
                        userCodes = Regex.Replace(userCodes, "
    +", ",");
                        string[] userCodeArry = userCodes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        // 需要去重
                        userCodeArry = userCodeArry.Distinct().ToArray();
    
                   // In内容没有参数化 
                  // List<string> listCode = new List<string>();
                        //foreach (var item in userCodeArry)
                        //{
                        //    listCode.Add(SecretUtilitiesBase.SqlSafeOrderBy(item));
                        //}
                        //listCondition.Add(" CODE IN (" + BaseBusinessLogic.ObjectsToList(listCode.ToArray(), "'") + ")");
    
                        // 2019-06-21  参数化改造,避免硬解析
                        List<string> codeParameters = new List<string>();
                        Dictionary<string, object> codeConditions = new Dictionary<string, object>();
                        foreach (var code in userCodeArry)
                        {
                            codeParameters.Add(dbHelper.GetParameter("P_" + code));
                            codeConditions.Add("P_" + code, code);
                        }
                        listCondition.Add(" CODE IN (" + codeParameters.Join(",").TrimStart(",").TrimEnd(",") + ")");
                        dbParameters = dbParameters.Concat(codeConditions).ToDictionary(k => k.Key, v => v.Value);
                    }
  • 相关阅读:
    140704
    140703
    140702
    堆排序
    并查集
    140701
    这年暑假集训-140630
    vim for python
    hihocode 第九十二周 数论一·Miller-Rabin质数测试
    hdu 3157 Crazy Circuits 有源汇和下界的最小费用流
  • 原文地址:https://www.cnblogs.com/hnsongbiao/p/11063912.html
Copyright © 2011-2022 走看看