public void GenericUpdate <T, TKey>(Expression <Func <T, TKey> > keySelector, Dictionary <int, object> values, LinqdbTransactionInternal trans, LinqDbTypes type) { CheckTableInfo <T>(); var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); var table_info = GetTableInfo(typeof(T).Name); if (table_info.Columns[name] != type) { throw new LinqDbException("Linqdb: wrong data type for given column."); } var info = new UpdateInfo() { TableNumber = table_info.TableNumber, ColumnNumber = table_info.ColumnNumbers[name], ColumnType = table_info.Columns[name], TableInfo = table_info, ColumnName = name }; var data = new Dictionary <int, object>(); foreach (var v in values) { data[v.Key] = v.Value; } Update <T>(info, data, table_info, trans); }
public IDbOrderedQueryable <T> OrderByDescending <T, TKey>(IDbQueryable <T> source, Expression <Func <T, TKey> > keySelector) { CheckTableInfo <T>(); var res = new IDbOrderedQueryable <T>() { _db = this }; res.LDBTree = source.LDBTree; var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); var table_info = GetTableInfo(typeof(T).Name); res.LDBTree.OrderingInfo = new OrderingInfo(); res.LDBTree.OrderingInfo.Orderings = new List <OrderByInfo>(); res.LDBTree.OrderingInfo.Orderings.Add(new OrderByInfo() { TableNumber = table_info.TableNumber, ColumnNumber = table_info.ColumnNumbers[name], ColumnType = table_info.Columns[name], IsDescending = true, ColumnName = name }); return(res); }
public void RemoveIndex <T, TKey>(Expression <Func <T, TKey> > valuePropertySelector) { CheckTableInfo <T>(); var value_par = valuePropertySelector.Parameters.First(); var value_name = SharedUtils.GetPropertyName(valuePropertySelector.Body.ToString()); RemoveIndexFromFile(typeof(T).Name, null, value_name); RemoveIndex(typeof(T).Name, null, value_name); }
public void CreateGroupByIndex <T, TKey1, TKey2>(Expression <Func <T, TKey1> > groupPropertySelector, Expression <Func <T, TKey2> > valuePropertySelector) { CheckTableInfo <T>(); var group_par = groupPropertySelector.Parameters.First(); var group_name = SharedUtils.GetPropertyName(groupPropertySelector.Body.ToString()); var value_par = valuePropertySelector.Parameters.First(); var value_name = SharedUtils.GetPropertyName(valuePropertySelector.Body.ToString()); CreateGroupByIndexString(typeof(T).Name, group_name, value_name); AddIndexToFile(typeof(T).Name, group_name, value_name); }
public ClientResult RemovePropertyIndex <T, TKey>(Expression <Func <T, TKey> > valuePropertySelector) { var res = new ClientResult(); res.Type = "removepropertyindex"; var par = valuePropertySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(valuePropertySelector.Body.ToString()); res.Selector = name; return(res); }
public ClientResult OrderByDescending <T, TKey>(Expression <Func <T, TKey> > keySelector) { var res = new ClientResult(); res.Type = "orderdesc"; var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); res.Selector = name; return(res); }
public ClientResult GenericUpdate <T, TKey>(Expression <Func <T, TKey> > keySelector, Dictionary <int, byte[]> UpdateData) { var res = new ClientResult(); StringBuilder up_sb = new StringBuilder(); var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); res.Selector = name; res.Type = "update"; res.UpdateData = UpdateData; return(res); }
public ClientResult Between <T, TKey>(Expression <Func <T, TKey> > keySelector, double from, double to, BetweenBoundariesInternal boundaries = BetweenBoundariesInternal.BothInclusive) { var res = new ClientResult(); res.Type = "between"; res.Boundaries = (short)boundaries; res.From = from; res.To = to; var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); res.Selector = name; return(res); }
public int?AtomicIncrement <T, TKey>(IDbQueryable <T> source, Expression <Func <T, TKey> > keySelector, int value, T item, int?old_val_equals) where T : new() { if (item == null) { throw new LinqDbException("Linqdb: new_item_if_doesnt_exist can't be null"); } var table_info = CheckTableInfo <T>(); var _write_lock = GetTableWriteLock(typeof(T).Name); lock (_write_lock) { var statistics = new LinqdbSelectStatisticsInternal(); var res = this.SelectEntity <T>(source.LDBTree, statistics); if (res != null && res.Count() > 1) { throw new LinqDbException("Linqdb: more than one item identified"); } if (res == null || !res.Any()) { this.SaveIncrement <T>(item, null); return(null); } else { var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); if (name == "Id") { throw new LinqDbException("Linqdb: can't modify Id property"); } object ov = typeof(T).GetProperty(name).GetValue(res[0], null); if (ov == null || !(ov is int)) { throw new LinqDbException("Linqdb: property to increment must be of type int"); } int old_val = (int)ov; if (old_val_equals == null || old_val_equals == old_val) { int id = (int)typeof(T).GetProperty("Id").GetValue(res[0], null); var dic = new Dictionary <int, int?>() { { id, old_val + value } }; UpdateIncrement(keySelector, dic, null); } return(old_val); } } }
public ClientResult RemoveGroupByMemoryIndex <T, TKey1, TKey2>(Expression <Func <T, TKey1> > groupPropertySelector, Expression <Func <T, TKey2> > valuePropertySelector) { var res = new ClientResult(); res.Type = "removegroupindex"; var par = groupPropertySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(groupPropertySelector.Body.ToString()); res.Selector = name; par = valuePropertySelector.Parameters.First(); name = SharedUtils.GetPropertyName(valuePropertySelector.Body.ToString()); res.Query = name; return(res); }
public ClientResult Intersect <T, TKey>(Expression <Func <T, TKey> > keySelector, HashSet <double> set) { var res = new ClientResult(); res.Double_set = new HashSet <double>(); foreach (var s in set) { res.Double_set.Add(s); } var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); res.Selector = name; res.Type = "intersect"; return(res); }
public ClientResult Intersect <T, TKey>(Expression <Func <T, TKey> > keySelector, HashSet <DateTime> set) { var res = new ClientResult(); res.Date_set = new HashSet <double>(); foreach (var s in set) { var val = (s - new DateTime(0001, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds; res.Date_set.Add(val); } var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); res.Selector = name; res.Type = "intersect"; return(res); }
//public ClientResult AtomicIncrement<T, TKey>(Expression<Func<T, TKey>> keySelector, int value, T item, Dictionary<string, string> def, Dictionary<string, short> order) //{ // var res = new ClientResult(); // res.Type = "increment1"; // res.Data = GetData<T>(new List<T>() { item }, def, order); // var par = keySelector.Parameters.First(); // var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); // res.Selector = name; // res.Inc_val = value; // res.Inc_old_val = null; // return res; //} public ClientResult AtomicIncrement2Props <T, TKey1, TKey2>(Expression <Func <T, TKey1> > keySelector1, Expression <Func <T, TKey2> > keySelector2, int value1, int value2, T item, Dictionary <string, string> def, Dictionary <string, short> order) { var res = new ClientResult(); res.Type = "increment2"; res.Data = GetData <T>(new List <T>() { item }, def, order); var par1 = keySelector1.Parameters.First(); var name1 = SharedUtils.GetPropertyName(keySelector1.Body.ToString()); var par2 = keySelector2.Parameters.First(); var name2 = SharedUtils.GetPropertyName(keySelector2.Body.ToString()); res.Selector = name1 + "|" + name2 + "|" + value1 + "|" + value2; return(res); }
public ClientResult AtomicIncrement <T, TKey>(Expression <Func <T, TKey> > keySelector, int value, T item, Dictionary <string, string> def, Dictionary <string, short> order, int?only_if_old_equal) { var res = new ClientResult(); res.Type = "increment"; res.Data = GetData <T>(new List <T>() { item }, def, order); var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); res.Selector = name; res.Inc_val = value; res.Inc_old_val = only_if_old_equal; return(res); }
public IDbQueryable <T> Search <T, TKey>(IDbQueryable <T> source, Expression <Func <T, TKey> > keySelector, string search_query, bool partial, bool timeLimited, int timeLimitInMs, int?start_step, int?steps) { if (start_step != null && steps == null || start_step == null && steps != null) { throw new LinqDbException("Linqdb: start_step and steps parameters must be used together."); } CheckTableInfo <T>(); if (string.IsNullOrEmpty(search_query)) { return(source); } if (source.LDBTree == null) { source.LDBTree = new QueryTree(); } var tree = source.LDBTree; if (tree.SearchInfo == null) { tree.SearchInfo = new List <SearchInfo>(); } var info = new SearchInfo(); tree.SearchInfo.Add(info); info.SearchQuery = search_query; info.Partial = partial; info.TimeLimited = timeLimited; info.SearchTimeInMs = timeLimitInMs; info.Start_step = start_step; info.Steps = steps; var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); var table_info = GetTableInfo(typeof(T).Name); info.TableInfo = table_info; info.Name = name; source.LDBTree.Prev = info; source.LDBTree.Prev.Id = source.LDBTree.Counter + 1; source.LDBTree.Counter++; return(source); }
public IDbGroupedQueryable <T, TKey> GroupBy <T, TKey>(IDbQueryable <T> source, Expression <Func <T, TKey> > keySelector) { CheckTableInfo <T>(); var res = new IDbGroupedQueryable <T, TKey>() { _db = this }; res.LDBTree = source.LDBTree; var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); var table_info = GetTableInfo(typeof(T).Name); res.LDBTree.GroupingInfo = new GroupByInfo(); res.LDBTree.GroupingInfo.TableNumber = table_info.TableNumber; res.LDBTree.GroupingInfo.ColumnNumber = table_info.ColumnNumbers[name]; res.LDBTree.GroupingInfo.ColumnType = table_info.Columns[name]; res.LDBTree.GroupingInfo.ColumnName = name; return(res); }
public ClientResult Search <T, TKey>(Expression <Func <T, TKey> > keySelector, string search_query, bool partial, bool timeLimited, int searchTimeLimitInMs, int?start_step, int?steps) { if (start_step != null && steps == null || start_step == null && steps != null) { throw new LinqDbException("Linqdb: start_step and steps parameters must be used together."); } var res = new ClientResult(); res.Type = "search"; var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); res.Selector = name; res.Query = search_query; res.Start_step = start_step; res.Steps = steps; res.Double_null = partial; res.Int_null = timeLimited; res.Take = searchTimeLimitInMs; return(res); }
public IDbQueryable <T> Between <T, TKey>(IDbQueryable <T> source, Expression <Func <T, TKey> > keySelector, double from, double to, BetweenBoundariesInternal boundaries = BetweenBoundariesInternal.BothInclusive) { CheckTableInfo <T>(); if (source.LDBTree == null) { source.LDBTree = new QueryTree(); } var tree = source.LDBTree; if (tree.BetweenInfo == null) { tree.BetweenInfo = new List <BetweenInfo>(); } var info = new BetweenInfo(); tree.BetweenInfo.Add(info); info.BetweenBoundaries = boundaries; info.From = from; info.To = to; var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); var table_info = GetTableInfo(typeof(T).Name); info.TableNumber = table_info.TableNumber; info.ColumnNumber = table_info.ColumnNumbers[name]; info.ColumnType = table_info.Columns[name]; info.ColumnName = name; info.TableName = table_info.Name; info.IdNumber = table_info.ColumnNumbers["Id"]; source.LDBTree.Prev = info; source.LDBTree.Prev.Id = source.LDBTree.Counter + 1; source.LDBTree.Counter++; return(source); }
Oper FillOpData(Expression expr, List <ParameterExpression> pars, Type table_type) { var pname = pars.First().Name; if (expr.NodeType == ExpressionType.Convert && !expr.ToString().StartsWith(pname)) { throw new LinqDbException("Linqdb: Error in Where statement, probably type mismatch, for example int and int? are different types and both side of an expression must be of same type. Cast the right hand side's value."); } //if (!expr.ToString().StartsWith(pname) && !expr.ToString().StartsWith("Convert("+pname)) //{ // throw new LinqDbException("Linqdb: Error in Where statement, probably type mismatch, for example int and int? are different types and both side of an expression must be of same type. Cast the right hand side's value."); //} var column_name = SharedUtils.GetPropertyName(expr.ToString()); var op = new Oper() { Type = expr.NodeType, ColumnName = column_name, IsOperator = false, IsDb = true }; return(op); }
public ClientResult Intersect <T, TKey>(Expression <Func <T, TKey> > keySelector, HashSet <int?> set) { var res = new ClientResult(); res.Int_set = new HashSet <int>(); foreach (var s in set) { if (s == null) { res.Int_null = true; } else { res.Int_set.Add((int)s); } } var par = keySelector.Parameters.First(); var name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); res.Selector = name; res.Type = "intersect"; return(res); }
IDbQueryable <T> Intersect <T, TKey>(IDbQueryable <T> source, Expression <Func <T, TKey> > keySelector, List <EncodedValue> set, Dictionary <long, byte[]> cache) { if (source.LDBTree == null) { source.LDBTree = new QueryTree(); } var tree = source.LDBTree; if (tree.IntersectInfo == null) { tree.IntersectInfo = new List <IntersectInfo>(); } var info = new IntersectInfo(); tree.IntersectInfo.Add(info); info.Set = set; string name = "Id"; if (keySelector != null) { var par = keySelector.Parameters.First(); name = SharedUtils.GetPropertyName(keySelector.Body.ToString()); } var table_info = GetTableInfo(typeof(T).Name); info.TableNumber = table_info.TableNumber; info.ColumnNumber = table_info.ColumnNumbers[name]; info.ColumnType = table_info.Columns[name]; source.LDBTree.Prev = info; source.LDBTree.Prev.Id = source.LDBTree.Counter + 1; source.LDBTree.Counter++; return(source); }