private U DoAggregate <T, U>(Aggregate aggregate, Where where) { bool useMultiPartIdentifier = where.Any(w => w.Item1.Contains(".")); Type type = typeof(T); BuildMap(type); string sql = BuildAggregateSql(type, aggregate, where, useMultiPartIdentifier); Parameters parameters = BuildWhereParameters(where, useMultiPartIdentifier); return(DoExecuteScalar <U>(sql, parameters)); }
public void Where_Any() { //arrange SqlConnect sql = new CSharpedSql.MySql.MySqlConnect(); var expected = "SELECT * FROM `test` WHERE `id` = ANY (SELECT * FROM `table`);"; //act sql.Query(Select.From("test") + Where.Any("id", Select.From("table"))); var actual = sql.ToString().TrimEnd(); //assert Assert.AreEqual(expected, actual); }
protected void FillWhere(params NameValueCollection[] collections) { foreach (var collection in collections) { foreach (var item in collection) { var key = item.ToString(); if (Where.Any(p => p.Key.ToLower() == key.ToLower()) || string.IsNullOrEmpty(collection[key]) || key.ToLower() == "page" || key.ToLower() == "rows" || key.ToLower() == "order" || key.ToLower() == "sort") { continue; } Where.Add(key, collection[key].Trim()); } } }
/// <summary> /// Returns a <see cref="System.String" /> that represents this instance. /// </summary> /// <returns>A <see cref="System.String" /> that represents this instance.</returns> /// <exception cref="ArgumentException">Resource</exception> public override string ToString() { if (string.IsNullOrEmpty(ObjectStructureName)) { throw new ArgumentException($"Required paramater '{nameof(ObjectStructureName)}' was not given."); } var sb = new StringBuilder(); sb.Append($"{ObjectStructureName}?"); if (Select != null && Select.Any()) { var selectSb = new StringBuilder("oslc.select="); foreach (var att in Select) { selectSb.Append($"{att}{SELECT_SEPERATOR}"); } var selectStr = selectSb.ToString(); if (selectStr.EndsWith(SELECT_SEPERATOR)) { selectStr = selectStr.Remove(selectStr.Length - SELECT_SEPERATOR.Length); } sb.Append(selectStr); } else if (!IsCreate) { sb.Append("oslc.select=*"); } if (!string.IsNullOrEmpty(SavedQuery)) { sb.Append($"&savedQuery={SavedQuery}"); } if (Where.Any() || WhereIn.Any()) { var whereSb = new StringBuilder("&oslc.where="); foreach (var what in Where) { whereSb.Append($"{what}{WHERE_SEPERATOR}"); } foreach (var whatIn in WhereIn) { var valueList = whatIn.Value.Select(v => $"\"{v}\"").ToList(); whereSb.Append($"{whatIn.Key} in [{string.Join(",", valueList)}]{WHERE_SEPERATOR}"); } var whereStr = whereSb.ToString(); if (whereStr.EndsWith(WHERE_SEPERATOR)) { whereStr = whereStr.Remove(whereStr.Length - WHERE_SEPERATOR.Length); } sb.Append(whereStr); } if (OrderBy != null) { sb.Append("&oslc.orderBy="); sb.Append(OrderByDescending ? "-" : "%2B"); sb.Append(OrderBy); } if (PageSize != null && PageSize > 0) { sb.Append($"&oslc.pageSize={PageSize}"); if (PageNumber != null && PageNumber > 1) { sb.Append($"&pageno={PageNumber}"); } } if (UseLean) { sb.Append("&lean=1"); } if (UseOr) { sb.Append("&opmodeor=1"); } return(sb.ToString()); }