/// <summary> /// 创建查询命令 /// </summary> /// <param name="query">参数化查询</param> /// <returns>查询命令</returns> public TCommand Parse(ParameterizedQuery query) { var regex = ParameterizedQuery.DbPartialPlaceholdRegex; var text = regex.Replace(query.TextTemplate, (match) => { if (match.Groups["index"].Success) { var index = int.Parse(match.Groups["index"].Value); return(GetLiteralValue(DbValueConverter.ConvertTo(query.ParameterValues[index], null))); } else if (match.Groups["name"].Success) { var name = match.Groups["name"].Value.Replace("##", "#"); return(GetDbName(name)); } else { throw new InvalidOperationException(); } }); return(CreateCommand(text.Replace("##", "#"))); }
/// <summary> /// 创建查询命令 /// </summary> /// <param name="query">参数化查询</param> /// <returns>查询命令</returns> public TCommand Parse(ParameterizedQuery query) { var regex = ParameterizedQuery.ParameterPlaceholdRegex; var text = regex.Replace(query.TextTemplate, (match) => { var index = int.Parse(match.Groups["index"].Value); return(GetLiteralValue(DbValueConverter.ConvertTo(query.ParameterValues[index], null))); }); return(CreateCommand(text.Replace("##", "#"))); }
/// <summary> /// 创建查询命令 /// </summary> /// <param name="query">参数化查询</param> /// <returns>查询命令</returns> public TCommand Parse(ParameterizedQuery query) { var length = query.ParameterValues.Length; TParameter[] parameters = new TParameter[length]; string[] parameterPlaceholders = new string[length]; lock ( SyncRoot ) { var regex = ParameterizedQuery.ParameterPlaceholdRegex; var text = regex.Replace(query.TextTemplate, (match) => { var index = int.Parse(match.Groups["index"].Value); if (index >= length) { throw new IndexOutOfRangeException("分析参数化查询时遇到错误,参数索引超出边界"); } var placeholder = parameterPlaceholders[index]; if (placeholder == null) { placeholder = parameterPlaceholders[index] = GetParameterPlaceholder(DbValueConverter.ConvertTo(query.ParameterValues[index], null), index, out parameters[index]); } return(placeholder); }); return(CreateCommand(text.Replace("##", "#"), parameters.ToArray())); } }