private void CreateQueryFieldWhereSql(ConditionValueGeneratorPara para, Dictionary <string, string> tableAliaNameDic, Dictionary <string, Dictionary <string, DBFieldInfo> > tableFieldInfoDic, ExpressionNodeCollection conditionExpressionNodes, DBFiledValueConverterCollection dbFiledValueConverterCollection) { if (conditionExpressionNodes == null || conditionExpressionNodes.Count == 0) { return; } ExpressionNodeCollection childrenConditionExpressionNodes; DBFieldInfo dbFieldInfo; CompareOperaterAttribute compareOperaterAttribute; int lastIndex = conditionExpressionNodes.Count - 1; for (int i = 0; i < conditionExpressionNodes.Count; i++) { var expressionNode = conditionExpressionNodes.ElementAt(i); childrenConditionExpressionNodes = expressionNode.Children; if (childrenConditionExpressionNodes == null || childrenConditionExpressionNodes.Count == 0) { //无子节点 dbFieldInfo = tableFieldInfoDic[expressionNode.TableName][expressionNode.FieldName]; para.DBFiledValueConverter = dbFiledValueConverterCollection.GetDBFiledValueConverter(dbFieldInfo); para.FieldInfo = dbFieldInfo; if (tableAliaNameDic.ContainsKey(expressionNode.TableName)) { para.TableAliaName = tableAliaNameDic[expressionNode.TableName]; } else { para.TableAliaName = expressionNode.TableName; } para.ValueList = expressionNode.ValueList; para.Operater = expressionNode.Operater; compareOperaterAttribute = CompareOperaterHelper.GetCompareOperaterAttributeByCompareOperater(expressionNode.Operater); compareOperaterAttribute.ConditionValueGenerator.Generate(para); if (i < lastIndex) { para.SqlStringBuilder.Append(DBConstant.BLACK_SPACE); para.SqlStringBuilder.Append(conditionExpressionNodes.LogicOperaters.ToString()); para.SqlStringBuilder.Append(DBConstant.BLACK_SPACE); } } else { //有子节点 para.SqlStringBuilder.Append('('); this.CreateQueryFieldWhereSql(para, tableAliaNameDic, tableFieldInfoDic, childrenConditionExpressionNodes, dbFiledValueConverterCollection); para.SqlStringBuilder.Append(')'); } } }
/// <summary> /// 转换为带参数where语句 /// </summary> /// <param name="tableFieldInfoDic">表字段字典集合[key:表名;value:[key:字段名;value:DBFieldInfo]]</param> /// <param name="tableAliaNameDic">表别名字典集合[key:列名;value:别名]</param> /// <param name="filedValueConverterCollection">数据库字段值转换对象集合</param> /// <param name="paraSign">SQL参数符号字符串</param> /// <param name="parameterIndex">参数索引</param> /// <param name="parameterNameValueDic">参数名名称及对应的值字典集合[key:参数名称,含参数符号;value:参数值]</param> /// <returns>where语句</returns> public string ToWhere(Dictionary <string, Dictionary <string, DBFieldInfo> > tableFieldInfoDic, Dictionary <string, string> tableAliaNameDic, DBFiledValueConverterCollection filedValueConverterCollection, string paraSign, ref int parameterIndex, out Dictionary <string, object> parameterNameValueDic) { var sbSql = new StringBuilder(); parameterNameValueDic = new Dictionary <string, object>(); var para = new ConditionValueGeneratorPara(sbSql, paraSign, parameterIndex, parameterNameValueDic); this.CreateQueryFieldWhereSql(para, tableAliaNameDic, tableFieldInfoDic, this, filedValueConverterCollection); parameterIndex = para.GetParameterIndex(); return(sbSql.ToString()); }