public void IndexedSort(int propID) { lock (this) { if (_list == null) { Instantiate(); } IntHashSet hashSet = new IntHashSet(); for (int i = 0; i < _list.Count; i++) { hashSet.Add(_list [i]); } int destIndex = 0; IResultSet rs = MyPalStorage.Storage.SelectResourcesWithProp(propID); foreach (IRecord rec in rs) { int id = rec.GetIntValue(0); if (hashSet.Contains(id)) { _list [destIndex++] = id; } } } }
private void Execute() { if (_initialPlan.Criteria.SortResult) { rowResultSet = new SortedResultSet <long>(); } else { rowResultSet = new ListedResultSet <long>(); } var terminal = _initialPlan.Predicate as TerminalPredicate; if (terminal != null) { foreach (var kvp in terminal.Enumerate(_initialPlan.Criteria)) { rowResultSet.Add(kvp.Value); } } if (LoggerManager.Instance.QueryLogger != null) { LoggerManager.Instance.QueryLogger.Debug("ExecuteQuery", "ID:" + _initialPlan.Criteria.QueryId + ", Query Executed, Result Count: " + rowResultSet.Count); } }
/// <summary> /// TODO: add column disc_per2 into disc table /// </summary> /// <returns>The discount2.</returns> /// <param name="ctx">Context.</param> /// <param name="itemId">Item identifier.</param> /// <param name="cstId">Cst identifier.</param> public double GetDiscount2(Context ctx, long itemId, long cstId) { using (IConnection conn = Sync.GetConnection(ctx)) { const string query = @" select rdisc_per from rdisc where cst_kat_disc = (select cst_kat_disc from rcustomer where id = :cst_id) and item_ctg_disc = (select item_ctg_disc from ritems where id = :item_id) "; IPreparedStatement ps = conn.PrepareStatement(query); ps.Set("item_id", itemId); ps.Set("cst_id", cstId); double discount = 0; IResultSet rs = ps.ExecuteQuery(); if (rs.Next()) { discount = rs.GetDouble("rdisc_per"); } ps.Close(); conn.Commit(); conn.Release(); return(discount); } }
private void UpdatePropTypeRecord(string propName, IResource res) { IResultSet rs = _propTypeTable.CreateModifiableResultSet(1, propName); try { IEnumerator enumerator = rs.GetEnumerator(); using ((IDisposable)enumerator) { if (!enumerator.MoveNext()) { throw new StorageException("Cannot find the property type to be updated"); } IRecord rec = (IRecord)enumerator.Current; if (rec.GetIntValue(2) != res.GetIntProp("DataType")) { throw new StorageException("Invalid attempt to change data type of property " + propName + " from " + (PropDataType)rec.GetIntValue(2) + " to " + (PropDataType)res.GetIntProp("DataType")); } rec.SetValue(3, res.GetIntProp("Flags")); _storage.SafeCommitRecord(rec, "PropTypeCollection.UpdatePropTypeRecord"); } } finally { rs.Dispose(); } }
internal static TransHedList GetTransHedList(Context ctx) { TransHedList headers = new TransHedList(); using (IConnection conn = Sync.GetConnection(ctx)) { IPreparedStatement ps = conn.PrepareStatement(@" SELECT rtrans_hed.id, rtrans_hed.cust_id, trans_date, docnum, htrn_explanation, rcustomer.cst_desc FROM rtrans_hed LEFT OUTER JOIN rcustomer ON rcustomer.id = rtrans_hed.cust_id "); IResultSet result = ps.ExecuteQuery(); while (result.Next()) { TransHed header = new TransHed(); header.Fetch(result); headers.Add(header); } result.Close(); ps.Close(); foreach (TransHed h in headers) { TransHed.FetchDetails(h, conn); } conn.Release(); } return(headers); }
public static Category GetCategory(Context ctx, long categId, int categTbl) { Category info = new Category(); using (IConnection conn = Sync.GetConnection(ctx)) { string tableName = "ritem_categ"; if (categTbl == 2) { tableName += "2"; } IPreparedStatement ps = conn.PrepareStatement(@"SELECT id, item_categ_desc FROM " + tableName + " WHERE id = :CategId"); ps.Set("categId", categId); IResultSet result = ps.ExecuteQuery(); if (result.Next()) { info.Id = result.GetInt("id"); info.ItemCategDesc = result.GetString("item_categ_desc"); } result.Close(); ps.Close(); conn.Release(); } return(info); }
public DictionaryResultSetComposer() { this.createdResultSet = null; this.current = new Dictionary <string, object>(); this.resultSet = new List <IDictionary <string, object> >(); }
private void RepairResources() { int maxResID = -1; HashSet resIDs = new HashSet(); using (IResultSet rs = _resources.CreateResultSet(0)) { foreach (IRecord rec in rs) { _resCount++; int resID = rec.GetIntValue(0); int typeID = rec.GetIntValue(1); if (resID > maxResID) { maxResID = resID; } if (_dumpStructure) { string typeName = (string)_resTypeNames [typeID]; if (typeName == null) { typeName = Convert.ToString(typeID); } ShowProgress("Resource " + resID + " of type " + typeName); } if (!_resTypeIDs.Contains(typeID)) { ReportError("Found a resource of a non-existing type " + typeID); if (_fixErrors) { rec.Delete(); _fixCount++; } continue; } if (resIDs.Contains(resID)) { ReportError("Duplicate resource ID " + resID); if (_fixErrors) { rec.Delete(); _fixCount++; } continue; } resIDs.Add(resID); } } int nextID = _resources.NextID(); if (nextID <= maxResID) { ReportError("Next ID for table Resources " + nextID + " is smaller than maximum resource ID " + maxResID); } }
/// <summary> /// Called to Delete a record container. /// This call is deep (all records contained are deleted). /// </summary> /// <param name="name">The name of the container.</param> internal FlaimError.Error DeleteContainer(string name) { FlaimError.Error rc = FlaimError.Error.FERR_OK; try { Query query = new Query(name, BaseSchema.CollectionId, SearchOp.Exists, name, Syntax.String); IResultSet results = Search(query); char [] buffer = new char[4096]; int count; while ((count = results.GetNext(ref buffer)) != 0) { XmlDocument delDoc = new XmlDocument(); delDoc.LoadXml(new string(buffer, 0, count)); rc = CommitRecords(name, null, delDoc); } } catch { if (FlaimError.IsSuccess(rc)) { rc = FlaimError.Error.FERR_FAILURE; } } return(rc); }
public void TestThrowBadIndexesWhenCorruptedRecordMarker2( ) { ITable testTable = m_database.GetTable("People"); IRecord record = testTable.NewRecord(); record.SetValue(1, "zhu"); record.Commit(); m_database.Shutdown(); FileStream file = File.Open("MyPal.People.table.dbUtil", FileMode.Open, FileAccess.Write); file.Seek(0, SeekOrigin.Begin); byte[] bytes = new byte[1]; bytes[0] = 255; file.Write(bytes, 0, 1); file.Flush(); file.Close(); DBStructure dbStruct = new DBStructure("", "MyPal"); dbStruct.LoadStructure(); m_database = dbStruct.OpenDatabase( ); testTable = m_database.GetTable("People"); IResultSet resultSet = testTable.CreateResultSet(1, "zhu"); foreach (IRecord rec in resultSet) { rec.Equals(null); } }
public void TestDateTimeQuery( ) { ITable testTable = m_database.GetTable("Date"); IRecord record = testTable.NewRecord(); record.SetValue(1, 32); DateTime dt = new DateTime(1972, 7, 26); long ticks = dt.Ticks; ticks = ticks; record.SetValue(2, dt); record.Commit(); IResultSet resultSet = testTable.CreateResultSet(2, dt); try { foreach (IRecord rec in resultSet) { rec.Equals(null); } } catch (System.Exception) { return; } Assert.Fail("Index for DateTime is not supported. It is necessary to review autorecovery for DateTime"); }
public void Initialize(char symbol, int index, ArchitectureStyle style) { if (symbol == 'e') { return; } IResultSet resultSet = Repository.List("facade_item").Filter("style", style.name).Filter("symbol", symbol + "").Filter("index", index + ""); if (resultSet.Count() == 0) { throw new Exception("model not found (style: " + style.name + ", element: " + symbol + index + ")"); } _model = resultSet.Get(0); if (_model == null) { throw new Exception("invalid model (style: " + style.name + ", element: " + symbol + index + ")"); } CacheMetadata(); _invalid = false; }
private SmartMatchResult GetResultSmartMatch(IResultSet reader) { var index = 0; var result = new SmartMatchResult { Id = reader.GetGuid(0) }; index++; result.ItemName = reader.GetString(index); index++; result.DisplayName = reader.GetString(index); index++; result.OrganizerType = (FileOrganizerType)Enum.Parse(typeof(FileOrganizerType), reader.GetString(index), true); index++; if (!reader.IsDBNull(index)) { result.MatchStrings = _json.DeserializeFromString <List <string> >(reader.GetString(index)); } return(result); }
/* * public Set<Integer> getPatterns(String sentId, Integer tokenId) throws SQLException, IOException, ClassNotFoundException { * if(useDBForTokenPatterns){ * Connection conn = SQLConnection.getConnection(); * * String query = "Select patterns from " + tableName + " where sentid=\'" + sentId + "\' and tokenid = " + tokenId; * Statement stmt = conn.createStatement(); * ResultSet rs = stmt.executeQuery(query); * Set<Integer> pats = null; * if(rs.next()){ * byte[] st = (byte[]) rs.getObject(1); * ByteArrayInputStream baip = new ByteArrayInputStream(st); * ObjectInputStream ois = new ObjectInputStream(baip); * pats = (Set<Integer>) ois.readObject(); * * } * conn.close(); * return pats; * } * else * return patternsForEachToken.get(sentId).get(tokenId); * }*/ public override IDictionary <int, ICollection <E> > GetPatternsForAllTokens(string sentId) { try { IConnection conn = SQLConnection.GetConnection(); //Map<Integer, Set<Integer>> pats = new ConcurrentHashMap<Integer, Set<Integer>>(); string query = "Select patterns from " + tableName + " where sentid=\'" + sentId + "\'"; IStatement stmt = conn.CreateStatement(); IResultSet rs = stmt.ExecuteQuery(query); IDictionary <int, ICollection <E> > patsToken = new Dictionary <int, ICollection <E> >(); if (rs.Next()) { byte[] st = (byte[])rs.GetObject(1); ByteArrayInputStream baip = new ByteArrayInputStream(st); ObjectInputStream ois = new ObjectInputStream(baip); patsToken = (IDictionary <int, ICollection <E> >)ois.ReadObject(); } //pats.put(rs.getInt("tokenid"), patsToken); conn.Close(); return(patsToken); } catch (Exception e) { throw new Exception(e); } }
internal static void FetchDetails(TransHed transHed, IConnection conn) { IPreparedStatement ps = conn.PrepareStatement(@" SELECT rtrans_det.id, rtrans_det.htrn_id, rtrans_det.dtrn_num, rtrans_det.item_id, rtrans_det.qty1, rtrans_det.unit_price, rtrans_det.disc_line1, rtrans_det.net_value, rtrans_det.vat_value, ritems.item_cod, ritems.item_desc, ritems.item_vat FROM rtrans_det JOIN ritems ON ritems.id = rtrans_det.item_id WHERE htrn_id = :htrn_id ORDER BY rtrans_det.id"); ps.Set("htrn_id", transHed.HtrnId); IResultSet result = ps.ExecuteQuery(); if (transHed.TransDetList == null) { transHed.TransDetList = new TransDetList(); } while (result.Next()) { TransDet d = new TransDet(); d.Fetch(result); transHed.TransDetList.Add(d); } result.Close(); ps.Close(); }
public static User Login(Context ctx, string username, string password) { User user = null; using (IConnection conn = Sync.GetConnection(ctx)) { IPreparedStatement ps = conn.PrepareStatement(@"SELECT deal_id, user_id, login_name, user_pass, user_active FROM rusers WHERE user_active = 1 AND login_name = :login_name AND user_pass = :user_pass "); ps.Set("login_name", username); ps.Set("user_pass", password); IResultSet result = ps.ExecuteQuery(); if (result.Next()) { user = new User(); user.deal_id = result.GetInt("deal_id"); user.user_id = result.GetInt("user_id"); user.login_name = result.GetString("login_name"); user.user_pass = result.GetString("user_pass"); } result.Close(); ps.Close(); conn.Commit(); conn.Release(); } return(user); }
public static string Serialize(IResultSet resultSet) { IResultSetElement[] elements = resultSet.Elements.ToArray(); IDictionary <string, object>[] convertedElements = new IDictionary <string, object> [elements.Length]; for (int i = 0; i < elements.Length; i++) { IResultSetElement element = elements[i]; IDictionary <string, object> convertedElement = new Dictionary <string, object>(); foreach (string field in element.FieldNames) { convertedElement.Add(field, element.GetValue(field)); } convertedElements[i] = convertedElement; } using (TextWriter textWriter = new StringWriter()) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(textWriter, convertedElements); return(textWriter.ToString()); } }
public static Statistic GetStatistic(Context ctx, int cstId) { Statistic info = new Statistic(); using (IConnection conn = Sync.GetConnection(ctx)) { IPreparedStatement ps = conn.PrepareStatement(@" SELECT cst_id, item_kateg, month, amount_curr, amount_prev, ritem_categ.item_categ_desc FROM rstatistic JOIN ritem_categ ON ritem_categ.id = rstatistic.item_kateg WHERE cst_id = :cstId"); ps.Set("cstId", cstId); IResultSet result = ps.ExecuteQuery(); if (result.Next()) { info.Fetch(result); } ps.Close(); conn.Release(); } return(info); }
public void NavigationThroughRecords( ) { ITable testTable = m_database.GetTable("People"); Insert_100_NewRecordsAndCheck(testTable, 100); IResultSet people = testTable.CreateResultSet(Id); int count = 0; foreach (IRecord person in people) { person.GetValue(Id); count++; } Assert.AreEqual(100, count); people.Dispose(); people = testTable.CreateResultSet(Id); count = 0; foreach (IRecord person in people) { person.GetValue(Id); count++; } Assert.AreEqual(100, count); people.Dispose(); }
public static string Serialize(IResultSet resultSet) { IResultSetElement[] elements = resultSet.Elements.ToArray(); IDictionary<string, object>[] convertedElements = new IDictionary<string,object>[elements.Length]; for (int i = 0; i < elements.Length; i++) { IResultSetElement element = elements[i]; IDictionary<string, object> convertedElement = new Dictionary<string, object>(); foreach (string field in element.FieldNames) { convertedElement.Add(field, element.GetValue(field)); } convertedElements[i] = convertedElement; } using (TextWriter textWriter = new StringWriter()) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(textWriter, convertedElements); return textWriter.ToString(); } }
public static IEnumerable <IDocument> OrderBy(this IResultSet source, List <QuerySortParameter> sortings) { if (!sortings?.Any() ?? false) { return(source); } var sortedResults = default(IOrderedEnumerable <IDocument>); foreach (var sort in sortings) { if (sortedResults == default(IOrderedEnumerable <IDocument>)) { sortedResults = sort.OrderBy == SitefinityAccelerator.Models.OrderBy.DESCENDING ? source.OrderByDescending(s => s.GetValue(sort.FieldName)) : source.OrderBy(s => s.GetValue(sort.FieldName)); } else { sortedResults = sort.OrderBy == SitefinityAccelerator.Models.OrderBy.DESCENDING ? sortedResults.ThenByDescending(s => s.GetValue(sort.FieldName)) : sortedResults.ThenBy(s => s.GetValue(sort.FieldName)); } } return(sortedResults); }
public void SaveAndLoad( ) { ITable testTable = m_database.GetTable("People"); DateTime dateTime = DateTime.Now; for (int i = 0; i < 100; i++) { InsertRecord(testTable, i.ToString(), i, dateTime.Subtract(new TimeSpan(i, 0, 0, 0))); } IResultSet people = testTable.CreateResultSet(Id); int count = 0; foreach (IRecord person in people) { int id = person.GetIntValue(Id); Assert.IsTrue(id == count); string name = person.GetStringValue(Name); Assert.IsTrue(name == count.ToString()); int age = person.GetIntValue(Age); age = age; DateTime receivedTime = (DateTime)person.GetValue(Birthday); Assert.IsTrue(receivedTime == dateTime.Subtract(new TimeSpan(count, 0, 0, 0))); count++; } Assert.AreEqual(100, count); people.Dispose(); }
internal override IntArrayList GetMatchingResources(out bool sortedById) { bool reverseLink = (_propId < 0 && MyPalStorage.Storage.IsLinkDirected(-_propId)); IResultSet rs = MyPalStorage.Storage.SelectLinksOfType(reverseLink ? -_propId : _propId); try { IntArrayList list; if (reverseLink) { list = DoGetResourcesFromResultSet(rs, 1); list.Sort(); } else { list = DoGetResourcesFromResultSet(rs, 0); list.Sort(); if (!MyPalStorage.Storage.IsLinkDirected(_propId)) { IntArrayList list2 = DoGetResourcesFromResultSet(rs, 1); list2.Sort(); list = IntArrayList.MergeSorted(list, list2); } } list.RemoveDuplicatesSorted(); sortedById = true; return(list); } finally { rs.Dispose(); } }
public static void SetDbBindColumn(IDataBaseObject obj, IResultSet rs, IColumnInfo p, DbBindColumn dbc) { var sp = obj as IStoredProcedureInfo; if (sp != null) { obj = sp; dbc.SpResultIndex = sp.ResultSets.IndexOf(rs); } switch (rs.Type) { case ResultType.Table: dbc.ColumnOriginType = ColumnOriginType.Table; break; case ResultType.View: dbc.ColumnOriginType = ColumnOriginType.View; break; case ResultType.StoredProcedure: dbc.ColumnOriginType = ColumnOriginType.StoredProcedure; break; } //dbc.ColumnOriginType= dbc.CatalogName = obj.ObjectCatalog; dbc.SchemaName = obj.ObjectSchema; dbc.ObjectName = obj.ObjectName; dbc.ColumnName = p.ColumnName; dbc.LoadColumn(GeneratorController.Catalog); }
/// <summary> /// Searches the specified query. /// </summary> /// <param name="query">The query.</param> /// <param name="skip">The skip.</param> /// <param name="take">The take.</param> /// <param name="hitCount">The hit count.</param> /// <returns></returns> public IEnumerable <IDocument> Search(string query, string language, int skip, int take, out int hitCount) { var service = Telerik.Sitefinity.Services.ServiceBus.ResolveService <ISearchService>(); var queryBuilder = ObjectFactory.Resolve <IQueryBuilder>(); var config = Config.Get <SearchConfig>(); var enableExactMatch = config.EnableExactMatch; var searchQuery = queryBuilder.BuildQuery(query, this.SearchFields); searchQuery.IndexName = this.IndexCatalogue; searchQuery.Skip = skip; searchQuery.Take = take; searchQuery.OrderBy = this.GetOrderList(); searchQuery.EnableExactMatch = enableExactMatch; searchQuery.HighlightedFields = this.HighlightedFields; ISearchFilter filter; if (this.TryBuildLanguageFilter(language, out filter)) { searchQuery.Filter = filter; } var oldSkipValue = skip; IResultSet result = service.Search(searchQuery); hitCount = result.HitCount; return(result.SetContentLinks()); }
public static IResultSet <T> ToBaggedResultSet(IResultSet <T> source) { if (source is ListedResultSet <T> ) { return(source); } return(new ListedResultSet <T>(source.GetEnumerator())); }
public static IResultSet <T> ToSortedResultSet(IResultSet <T> source) { if (source is SortedResultSet <T> ) { return(source); } return(new SortedResultSet <T>(source.GetEnumerator())); }
private string RenderAsJoinMember(IResultSet resultSet) { resultSet.ConsiderAsJoinMember = true; string result = resultSet.RenderPlain(); resultSet.ConsiderAsJoinMember = false; return(result); }
public static Guid GetGuid(this IResultSet result, int index) { #if NETCOREAPP return(new Guid(result.GetBlob(index))); #else return(new Guid(result.GetBlob(index).ToArray())); #endif }
public static DateTimeOffset ReadDateTimeOffset(this IResultSet result, int index, bool enableMsPrecision) { if (enableMsPrecision) { return(DateTimeOffset.FromUnixTimeMilliseconds(result.GetInt64(index))); } return(DateTimeOffset.FromUnixTimeSeconds(result.GetInt64(index))); }
public DirectoryAnalyzerViewModel(IResultSet resultSet, IRegionManager regionManager) { _jpegFilesLocation = new List <string>(); InitializeWorker(); InitializeCommands(); _resultSet = resultSet; _regionManager = regionManager; }
public JsonResultSet(string json) { JsonSerializer serializer = new JsonSerializer(); TextReader textReader = new StringReader(json); JsonReader jsonReader = new JsonTextReader(textReader); IDictionary<string, object>[] deserialized = serializer.Deserialize<IDictionary<string, object>[]>(jsonReader); this.innerResultSet = new DictionaryResultSet(deserialized); }
public Correctness(IResultSet expected, IResultSet actual) : this(expected, actual, false) { }
public Correctness(IResultSet expected, IResultSet actual, bool ordered) { this.expected = expected; this.actual = actual; this.ordered = ordered; }