public void CheckNextIDAfterDeleting( ) { ITable testTable = m_database.GetTable("People"); IRecord record = testTable.NewRecord(); record.SetValue(Name, "SomeName"); record.SetValue(Birthday, DateTime.Now); record.Commit(); record = testTable.NewRecord(); record.SetValue(Name, "zhu"); record.SetValue(Birthday, DateTime.Now); record.Commit(); Assert.AreEqual(2, testTable.Count); ICountedResultSet resultSet = testTable.CreateModifiableResultSet(Name, "zhu"); Assert.AreEqual(1, resultSet.Count); record = resultSet[0]; Assert.AreEqual(1, record.GetIntValue(Id)); record.Delete(); record = testTable.NewRecord(); record.SetValue(Name, "zhu"); record.SetValue(Birthday, DateTime.Now); record.Commit(); Assert.AreEqual(2, testTable.Count); resultSet.Dispose(); resultSet = testTable.CreateModifiableResultSet(Name, "zhu"); Assert.AreEqual(1, resultSet.Count); record = resultSet[0]; Assert.AreEqual(2, record.GetIntValue(Id)); resultSet.Dispose(); }
public void SelectCompound( ) { DBStructure dbStructure = new DBStructure("", "Test", DatabaseMode.Create); TableStructure tblPeople = dbStructure.CreateTable("People"); tblPeople.CreateColumn("Id", ColumnType.Integer, false); tblPeople.CreateColumn("Name", ColumnType.String, false); tblPeople.CreateColumn("Age", ColumnType.Integer, false); tblPeople.SetCompoundIndex("Id", "Age"); tblPeople.SetCompoundIndex("Name", "Age"); dbStructure.SaveStructure(); dbStructure.Shutdown(); dbStructure = new DBStructure("", "Test", DatabaseMode.Create); dbStructure.LoadStructure( ); IDatabase database = dbStructure.Database; ITable people = database.GetTable("People"); IRecord record = people.NewRecord(); record.SetValue(2, 777); record.Commit(); ICountedResultSet rs = people.CreateModifiableResultSet(0, 0); Assert.AreEqual(1, rs.Count); IRecord rec = rs[0]; Assert.AreEqual(0, rec.GetIntValue(0)); Assert.AreEqual(777, rec.GetIntValue(2)); for (int i = 0; i < 100; i++) { record = people.NewRecord(); record.SetValue(1, "Serg"); record.SetValue(2, i); record.Commit(); } rs.Dispose(); rs = people.CreateResultSet(1, "Serg", 2, 31, false); Assert.AreEqual(1, rs.Count); rs.Dispose(); rs = people.CreateResultSet(1, "Serg", 2, 100, false); Assert.AreEqual(0, rs.Count); rs.Dispose(); rs = people.CreateResultSetForRange(1, "Serg", 2, 10, 50); Assert.AreEqual(41, rs.Count); rs.Dispose(); database.Shutdown(); }
internal void UpdateResourceType(string name, string displayNameTemplate, ResourceTypeFlags flags, string propDisplayName) { ICountedResultSet rs = _resourceTypeTable.CreateModifiableResultSet(1, name); try { if (rs.Count > 0) { IRecord rec = rs [0]; if (rec.GetStringValue(2) != displayNameTemplate) { rec.SetValue(2, displayNameTemplate); _storage.SafeCommitRecord(rec, "ResourceTypeCollection.UpdateResourceType"); } int resID = rec.GetIntValue(0); UpdateResourceTypeCache(resID, displayNameTemplate, flags); ResourceTypeItem item = (ResourceTypeItem)this [resID]; item.SetDisplayName(propDisplayName); } } finally { rs.Dispose(); } }
public void CheckSelectionByTwoColumnsWithNoRecords( ) { ICountedResultSet resultSet = _peopleTable.CreateResultSet(0, 1, 1, "498", false); Assert.AreEqual(0, resultSet.Count); resultSet.Dispose(); }
public void Delete(string name) { ResourceTypeItem item = (ResourceTypeItem)this [name]; IResourceList resList = _storage.GetAllResources(name); resList.DeleteAll(); _resourceTypeCache [item.Id] = null; _resourceTypeNameCache.Remove(name); ICountedResultSet rs = _resourceTypeTable.CreateModifiableResultSet(0, item.Id); try { _storage.SafeDeleteRecord(rs [0], "ResourceTypes.Delete"); } finally { rs.Dispose(); } IResource resourceTypeRes = _storage.FindUniqueResource("ResourceType", "Name", name); Debug.Assert(resourceTypeRes != null); resourceTypeRes.Delete(); }
public void CheckSelectByOneColumnWhenCompoundIndexexistsOnlyIndex( ) { ITable table = m_database.GetTable("People"); IRecord record = table.NewRecord(); record.SetValue(1, "Sergey"); record.SetValue(2, 31); record.Commit(); record = table.NewRecord(); record.SetValue(1, "Sergey"); record.SetValue(2, 15); record.Commit(); record = table.NewRecord(); record.SetValue(1, "Sergey"); record.SetValue(2, 25); record.Commit(); record = table.NewRecord(); record.SetValue(1, "Misha"); record.SetValue(2, 15); record.Commit(); record = table.NewRecord(); record.SetValue(1, "Null"); record.Commit(); ICountedResultSet resultSet = table.CreateModifiableResultSet(1, "Sergey"); Assert.AreEqual(3, resultSet.Count); resultSet.Dispose(); resultSet = table.CreateModifiableResultSet(1, "Misha"); Assert.AreEqual(1, resultSet.Count); resultSet.Dispose(); resultSet = table.CreateModifiableResultSet(1, ""); Assert.AreEqual(0, resultSet.Count); resultSet.Dispose(); resultSet = table.CreateModifiableResultSet(1, "Zorro"); Assert.AreEqual(0, resultSet.Count); resultSet.Dispose(); resultSet = table.CreateModifiableResultSet(1, "Null"); Assert.AreEqual(1, resultSet.Count); resultSet.Dispose(); }
public void CheckNotReusingIDs( ) { ITable testTable = m_database.GetTable("People"); IRecord record = testTable.NewRecord(); record.Commit(); int id = record.GetID(); Assert.AreEqual(0, id); record = testTable.NewRecord(); record.Commit(); id = record.GetID(); Assert.AreEqual(1, id); ICountedResultSet resultSet = testTable.CreateModifiableResultSet(Id, 1); Assert.AreEqual(1, resultSet.Count); record = resultSet[0]; record.Delete(); resultSet.Dispose(); resultSet = testTable.CreateModifiableResultSet(Id, 1); Assert.AreEqual(0, resultSet.Count); record = testTable.NewRecord(); record.Commit(); id = record.GetID(); Assert.AreEqual(2, id); m_database.Shutdown(); DBStructure dbStruct = new DBStructure("", "MyPal"); dbStruct.LoadStructure(); m_database = dbStruct.OpenDatabase( ); testTable = m_database.GetTable("People"); resultSet.Dispose(); resultSet = testTable.CreateModifiableResultSet(Id, 0); Assert.AreEqual(1, resultSet.Count); resultSet.Dispose(); resultSet = testTable.CreateModifiableResultSet(Id, 1); Assert.AreEqual(0, resultSet.Count); resultSet.Dispose(); resultSet = testTable.CreateModifiableResultSet(Id, 2); Assert.AreEqual(1, resultSet.Count); record = testTable.NewRecord(); record.Commit(); id = record.GetID(); Assert.AreEqual(3, id); resultSet.Dispose(); }
public void BLOBUpdateTest( ) { Stream stream = File.Open("resumeTester.txt", FileMode.Open, FileAccess.Read); IRecord record = m_testTable.NewRecord(); record.SetValue(1, "Sergey"); record.SetValue(2, m_testTable.CreateBLOB(stream)); record.Commit(); ICountedResultSet resultSet = m_testTable.CreateModifiableResultSet(1, "Sergey"); IRecord person = resultSet[0]; Stream resumeStream = person.GetBLOBValue(2).Stream; resumeStream.Seek(0, SeekOrigin.Begin); BinaryReader reader = new BinaryReader(resumeStream); string strResume = reader.ReadString(); resumeStream.Close(); Assert.AreEqual("Resume of tester", strResume); resultSet.Dispose(); resultSet = m_testTable.CreateModifiableResultSet(1, "Sergey"); person = resultSet[0]; stream = File.Open("resume.txt", FileMode.Open, FileAccess.Read); person.SetValue(2, m_testTable.CreateBLOB(stream)); person.Commit(); resultSet.Dispose(); resultSet = m_testTable.CreateModifiableResultSet(1, "Sergey"); person = resultSet[0]; resumeStream = person.GetBLOBValue(2).Stream; resumeStream.Seek(0, SeekOrigin.Begin); reader = new BinaryReader(resumeStream); strResume = reader.ReadString(); resumeStream.Close(); resultSet.Dispose(); Assert.AreEqual("Resume of developer", strResume); }
public void CheckSelectionByTwoColumns( ) { ICountedResultSet resultSet = _peopleTable.CreateResultSet(0, 1, 1, "499", false); Assert.AreEqual(1, resultSet.Count, "Count is wrong"); Assert.AreEqual(1, resultSet[0].GetIntValue(0), "Id is wrong"); Assert.AreEqual("499", resultSet[0].GetStringValue(1), "Name is wrong"); resultSet.Dispose(); }
public void CheckCaseInsensitivityInIndex( ) { ITable testTable = m_database.GetTable("People"); IRecord record = testTable.NewRecord(); record.SetValue(Name, "ZHU"); record.Commit(); record = testTable.NewRecord(); record.SetValue(Name, "zhu"); record.Commit(); Assert.AreEqual(2, testTable.Count); ICountedResultSet resultSet = testTable.CreateModifiableResultSet(Name, "zhu"); Assert.AreEqual(2, resultSet.Count); resultSet.Dispose(); resultSet = testTable.CreateModifiableResultSet(Name, "ZHU"); Assert.AreEqual(2, resultSet.Count); resultSet.Dispose(); resultSet = testTable.CreateModifiableResultSet(Name, "Zhu"); Assert.AreEqual(2, resultSet.Count); resultSet.Dispose(); }
public void CheckSelectionByStringWithSameHashCode( ) { IRecord record = _peopleTable.NewRecord(); record.SetValue(1, "1308554180"); record.Commit(); record = _peopleTable.NewRecord(); record.SetValue(1, "2117097963"); record.Commit(); ICountedResultSet resultSet = _peopleTable.CreateModifiableResultSet(1, "1308554180"); Assert.AreEqual(1, resultSet.Count); resultSet.Dispose(); }
public void CreateResultOnFirstPartOfCompoundIndex( ) { for (int i = 0; i < 20; i = i + 2) { IRecord record = _peopleTable.NewRecord(); record.SetValue(1, "Ivan"); record.SetValue(3, i); record.Commit(); } ICountedResultSet resultSet = _peopleTable.CreateResultSet(1); Assert.AreEqual(20, resultSet.Count); resultSet.Dispose(); }
public void CreateResultSetForRangeByTwoColumnsIndex9( ) { for (int i = 0; i < 20; i = i + 2) { IRecord record = _peopleTable.NewRecord(); record.SetValue(1, "Ivan"); record.SetValue(3, i); record.Commit(); } ICountedResultSet resultSet = _peopleTable.CreateResultSetForRange(1, "Ivan", 3, 13, 17); Assert.AreEqual(2, resultSet.Count); resultSet.Dispose(); }
public void CreateResultSetForRangeByTwoColumnsIndex1( ) { for (int i = 0; i < 100; i++) { IRecord record = _peopleTable.NewRecord(); record.SetValue(1, "Ivan"); record.SetValue(3, i); record.Commit(); } ICountedResultSet resultSet = _peopleTable.CreateResultSetForRange(1, "Sergey", 3, 0, 99); Assert.AreEqual(0, resultSet.Count); resultSet.Dispose(); }
public void FloatTypeTest( ) { for (int i = 0; i < 20; i++) { IRecord record = m_testTable.NewRecord(); record.SetValue(1, "Сергей"); record.SetValue(2, ((double)i) / 10.0); record.Commit(); } ICountedResultSet resultSet = m_testTable.CreateResultSet(2); Assert.AreEqual(20, resultSet.Count); for (int i = 0; i < 20; i++) { IRecord person = resultSet[i]; Assert.AreEqual("Сергей", person.GetStringValue(1)); Assert.AreEqual(((double)i) / 10.0, person.GetDoubleValue(2)); } resultSet.Dispose(); }
public void CheckNextID( ) { ITable testTable = m_database.GetTable("People"); for (int i = 0; i < 1000; i++) { IRecord record = testTable.NewRecord(); record.SetValue(1, i.ToString()); record.Commit(); Assert.AreEqual(i, record.GetID()); Assert.IsTrue(testTable.Count == (i + 1)); } for (int i = 1000; i < 2000; i++) { Assert.IsTrue(testTable.NextID() == i); } for (int i = 0; i < 1000; i++) { ICountedResultSet resultSet = testTable.CreateModifiableResultSet(1, i.ToString()); resultSet[0].Delete(); resultSet.Dispose(); } m_database.Shutdown(); DBStructure database = new DBStructure("", "MyPal"); database.LoadStructure(); m_database = database.OpenDatabase( ); testTable = m_database.GetTable("People"); Assert.AreEqual(0, testTable.Count); for (int i = 2000; i < 3000; i++) { IRecord record = testTable.NewRecord(); record.SetValue(1, i.ToString()); record.Commit(); Assert.AreEqual(i, record.GetID()); Assert.AreEqual((i - 1999), testTable.Count); } }
public void Search( ) { _testTable = m_database.GetTable("People"); IRecord record = null; for (int i = 0; i < 10; i++) { record = _testTable.NewRecord(); Assert.AreEqual(i, record.GetID()); record.SetValue(Id, i); record.SetValue(Type, i); record.SetValue(Number, i * 100); record.Commit(); Assert.AreEqual(i + 1, _testTable.Count); } record = _testTable.GetRecordByEqual(1, 2); Assert.AreEqual(2, record.GetIntValue(1)); Assert.AreEqual(200, record.GetIntValue(2)); ICountedResultSet resultSet = _testTable.CreateResultSet(1, 2, 0, 2, false); Assert.AreEqual(1, resultSet.Count); record = resultSet[0]; Assert.AreEqual(2, record.GetIntValue(1)); Assert.AreEqual(200, record.GetIntValue(2)); resultSet.Dispose(); m_database.Shutdown(); DBStructure database = new DBStructure("", "MyPal"); database.LoadStructure(); m_database = database.OpenDatabase(); _testTable = m_database.GetTable("People"); record = _testTable.GetRecordByEqual(1, 2); Assert.AreEqual(2, record.GetIntValue(1)); Assert.AreEqual(200, record.GetIntValue(2)); }
public void DropCompoundAndCreateWithValue( ) { _testTable = m_database.GetTable("People"); IRecord record = null; for (int i = 0; i < 10; i++) { record = _testTable.NewRecord(); Assert.AreEqual(i, record.GetID()); record.SetValue(Id, i); record.SetValue(Type, i); record.SetValue(Number, i * 100); record.Commit(); Assert.AreEqual(i + 1, _testTable.Count); } record = _testTable.GetRecordByEqual(0, 2); Assert.AreEqual(2, record.GetIntValue(1)); Assert.AreEqual(200, record.GetIntValue(2)); ICountedResultSet resultSet = _testTable.CreateResultSet(0, 2, 1, 2, false); Assert.AreEqual(1, resultSet.Count); record = resultSet[0]; Assert.AreEqual(2, record.GetIntValue(1)); Assert.AreEqual(200, record.GetIntValue(2)); resultSet.Dispose(); m_database.Shutdown(); DBStructure database = new DBStructure("", "MyPal"); database.LoadStructure(); m_database = database.Database; _testTable = m_database.GetTable("People"); record = _testTable.GetRecordByEqual(0, 2); Assert.AreEqual(2, record.GetIntValue(1)); Assert.AreEqual(200, record.GetIntValue(2)); m_database.Shutdown(); database = new DBStructure("", "MyPal"); database.LoadStructure(); m_database = database.Database; TableStructure tblStruct = database.GetTable("People"); tblStruct.DropCompoundIndex("Id", "Type"); tblStruct.SetCompoundIndexWithValue("Id", "Type", "Number"); _testTable = m_database.GetTable("People"); database.SaveStructure(); m_database.Shutdown(); database.RebuildIndexes(true); database = new DBStructure("", "MyPal"); database.LoadStructure(); m_database = database.Database; _testTable = m_database.GetTable("People"); Assert.AreEqual(10, _testTable.Count); record = _testTable.GetRecordByEqual(0, 2); Assert.AreEqual(2, record.GetIntValue(1)); Assert.AreEqual(200, record.GetIntValue(2)); }
public void ComputeWastedSpace( ) { ITable testTable = m_database.GetTable("People"); for (int i = 0; i < 1000; i++) { IRecord record = testTable.NewRecord(); record.SetValue(1, i.ToString()); record.Commit(); } RecordsCounts recCounts = testTable.ComputeWastedSpace(); Assert.AreEqual(1000, recCounts.NormalRecordCount); Assert.AreEqual(1000, recCounts.TotalRecordCount); ICountedResultSet resultSet = testTable.CreateModifiableResultSet(1, "5"); foreach (IRecord record in resultSet) { record.Delete(); } resultSet.Dispose(); recCounts = testTable.ComputeWastedSpace(); Assert.AreEqual(999, recCounts.NormalRecordCount); Assert.AreEqual(1000, recCounts.TotalRecordCount); m_database.Shutdown(); DBStructure database = new DBStructure("", "MyPal"); database.LoadStructure(); m_database = database.OpenDatabase( ); testTable = m_database.GetTable("People"); for (int i = 1000; i < 2000; i++) { IRecord record = testTable.NewRecord(); record.SetValue(1, i.ToString()); record.Commit(); } recCounts = testTable.ComputeWastedSpace(); Assert.AreEqual(1999, recCounts.NormalRecordCount); Assert.AreEqual(2000, recCounts.TotalRecordCount); for (int i = 500; i < 1500; i++) { ICountedResultSet resultSet1 = testTable.CreateModifiableResultSet(1, i.ToString()); foreach (IRecord record in resultSet1) { record.Delete(); } resultSet1.Dispose(); } recCounts = testTable.ComputeWastedSpace(); Assert.AreEqual(999, recCounts.NormalRecordCount); Assert.AreEqual(1001, recCounts.TotalRecordCount - recCounts.NormalRecordCount); testTable.SortedColumn = -1; testTable.Defragment(); testTable.SortedColumn = 1; testTable.Defragment(); testTable.SortedColumn = 0; testTable.Defragment(); recCounts = testTable.ComputeWastedSpace(); Assert.AreEqual(999, recCounts.NormalRecordCount); Assert.AreEqual(999, recCounts.TotalRecordCount); Assert.AreEqual(0, recCounts.TotalRecordCount - recCounts.NormalRecordCount); }