public static Where ToWhere(this IEnumerable <Compare> cos, IDbAdapter adapter) { StringBuilder where = new StringBuilder(); List <Object> pms = new List <Object>(); foreach (Compare _co in cos) { Compare co = _co.Clone() as Compare; switch (co.Type) { default: case CompareType.Custom: where.AppendFormat("{0} and ", co.CustomCondition); pms.AddRange(co.CompareValues); break; case CompareType.Equals: if (_compareGetSingleValue(co)) { where.AppendFormat("{0}=@{1} and ", adapter.EnsureIdentifier(co.Field), pms.Count); pms.Add(co.CompareValues[0]); } break; case CompareType.Unequals: if (_compareGetSingleValue(co)) { where.AppendFormat("{0}<>@{1} and ", adapter.EnsureIdentifier(co.Field), pms.Count); pms.Add(co.CompareValues[0]); } break; case CompareType.GreaterThan: if (_compareGetSingleValue(co)) { where.AppendFormat("{0}>@{1} and ", adapter.EnsureIdentifier(co.Field), pms.Count); pms.Add(co.CompareValues[0]); } break; case CompareType.LessThan: if (_compareGetSingleValue(co)) { where.AppendFormat("{0}<@{1} and ", adapter.EnsureIdentifier(co.Field), pms.Count); pms.Add(co.CompareValues[0]); } break; case CompareType.Like: if (_compareGetSingleValue(co)) { where.AppendFormat("{0} like {1} and ", adapter.EnsureIdentifier(co.Field), adapter.Concat("'%'", "@" + pms.Count, "'%'")); pms.Add(adapter.LikePattern(co.CompareValues[0].ToString())); } break; case CompareType.Between: if (_compareGetBetweenValue(co)) { where.AppendFormat("{0} between @{1} and @{2} and ", adapter.EnsureIdentifier(co.Field), pms.Count, pms.Count + 1); pms.Add(co.CompareValues[0]); pms.Add(co.CompareValues[1]); } break; case CompareType.In: if (_compareGetInValue(co)) { where.AppendFormat("{0} in (", adapter.EnsureIdentifier(co.Field)); foreach (var o in co.CompareValues) { where.AppendFormat("@{0},", pms.Count); pms.Add(o); } where.Remove(where.Length - 1, 1); where.Append(") and "); } break; } } if (where.Length == 0) { return(null); } where.Remove(where.Length - 5, 5); return(new Where(where.ToString(), pms.ToArray())); }
public static Where ToWhere(this IEnumerable<Compare> cos, IDbAdapter adapter) { StringBuilder where = new StringBuilder(); List<Object> pms = new List<Object>(); foreach (Compare _co in cos) { Compare co = _co.Clone() as Compare; switch (co.Type) { default: case CompareType.Custom: where.AppendFormat("{0} and ", co.CustomCondition); pms.AddRange(co.CompareValues); break; case CompareType.Equals: if (_compareGetSingleValue(co)) { where.AppendFormat("{0}=@{1} and ", adapter.EnsureIdentifier(co.Field), pms.Count); pms.Add(co.CompareValues[0]); } break; case CompareType.Unequals: if (_compareGetSingleValue(co)) { where.AppendFormat("{0}<>@{1} and ", adapter.EnsureIdentifier(co.Field), pms.Count); pms.Add(co.CompareValues[0]); } break; case CompareType.GreaterThan: if (_compareGetSingleValue(co)) { where.AppendFormat("{0}>@{1} and ", adapter.EnsureIdentifier(co.Field), pms.Count); pms.Add(co.CompareValues[0]); } break; case CompareType.LessThan: if (_compareGetSingleValue(co)) { where.AppendFormat("{0}<@{1} and ", adapter.EnsureIdentifier(co.Field), pms.Count); pms.Add(co.CompareValues[0]); } break; case CompareType.Like: if (_compareGetSingleValue(co)) { where.AppendFormat("{0} like {1} and ", adapter.EnsureIdentifier(co.Field), adapter.Concat("'%'", "@" + pms.Count, "'%'")); pms.Add(adapter.LikePattern(co.CompareValues[0].ToString())); } break; case CompareType.Between: if (_compareGetBetweenValue(co)) { where.AppendFormat("{0} between @{1} and @{2} and ", adapter.EnsureIdentifier(co.Field), pms.Count, pms.Count + 1); pms.Add(co.CompareValues[0]); pms.Add(co.CompareValues[1]); } break; case CompareType.In: if (_compareGetInValue(co)) { where.AppendFormat("{0} in (", adapter.EnsureIdentifier(co.Field)); foreach (var o in co.CompareValues) { where.AppendFormat("@{0},", pms.Count); pms.Add(o); } where.Remove(where.Length - 1, 1); where.Append(") and "); } break; } } if (where.Length == 0) return null; where.Remove(where.Length - 5, 5); return new Where(where.ToString(), pms.ToArray()); }
public static Where ToWhere(this Compare _co, IDbAdapter adapter) { Compare co = _co.Clone() as Compare; switch (co.Type) { default: case CompareType.Custom: return(new Where(co.CustomCondition, co.CompareValues)); case CompareType.Equals: if (_compareGetSingleValue(co)) { return(new Where(string.Format("{0}=@0", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0])); } return(null); case CompareType.Unequals: if (_compareGetSingleValue(co)) { return(new Where(string.Format("{0}<>@0", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0])); } return(null); case CompareType.GreaterThan: if (_compareGetSingleValue(co)) { return(new Where(string.Format("{0}>@0", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0])); } return(null); case CompareType.LessThan: if (_compareGetSingleValue(co)) { return(new Where(string.Format("{0}<@0", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0])); } return(null); case CompareType.Like: if (_compareGetSingleValue(co)) { return(new Where(string.Format("{0} like {1}", adapter.EnsureIdentifier(co.Field), adapter.Concat("'%'", "@0", "'%'")), adapter.LikePattern(co.CompareValues[0].ToString()))); } return(null); case CompareType.Between: if (_compareGetBetweenValue(co)) { return(new Where(string.Format("{0} between @0 and @1", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0], co.CompareValues[1])); } return(null); case CompareType.In: if (_compareGetInValue(co)) { List <object> in_pms = new List <object>(); StringBuilder in_query = new StringBuilder(); foreach (var o in co.CompareValues) { in_query.AppendFormat("@{0},", in_pms.Count); in_pms.Add(o); } in_query.Remove(in_query.Length - 1, 1); return(new Where(string.Format("{0} in ({1})", adapter.EnsureIdentifier(co.Field), in_query), in_pms.ToArray())); } return(null); } }
public static Where ToWhere(this Compare _co, IDbAdapter adapter) { Compare co = _co.Clone() as Compare; switch (co.Type) { default: case CompareType.Custom: return new Where(co.CustomCondition, co.CompareValues); case CompareType.Equals: if (_compareGetSingleValue(co)) return new Where(string.Format("{0}=@0", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0]); return null; case CompareType.Unequals: if (_compareGetSingleValue(co)) return new Where(string.Format("{0}<>@0", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0]); return null; case CompareType.GreaterThan: if (_compareGetSingleValue(co)) return new Where(string.Format("{0}>@0", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0]); return null; case CompareType.LessThan: if (_compareGetSingleValue(co)) return new Where(string.Format("{0}<@0", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0]); return null; case CompareType.Like: if (_compareGetSingleValue(co)) return new Where(string.Format("{0} like {1}", adapter.EnsureIdentifier(co.Field), adapter.Concat("'%'", "@0", "'%'")), adapter.LikePattern(co.CompareValues[0].ToString())); return null; case CompareType.Between: if (_compareGetBetweenValue(co)) return new Where(string.Format("{0} between @0 and @1", adapter.EnsureIdentifier(co.Field)), co.CompareValues[0], co.CompareValues[1]); return null; case CompareType.In: if (_compareGetInValue(co)) { List<object> in_pms = new List<object>(); StringBuilder in_query = new StringBuilder(); foreach (var o in co.CompareValues) { in_query.AppendFormat("@{0},", in_pms.Count); in_pms.Add(o); } in_query.Remove(in_query.Length - 1, 1); return new Where(string.Format("{0} in ({1})", adapter.EnsureIdentifier(co.Field), in_query), in_pms.ToArray()); } return null; } }