예제 #1
0
파일: CheckIndexTest.cs 프로젝트: mo5h/omeo
        public void CheckSaveLoadIndex( )
        {
            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.IsTrue(testTable.Count == (i + 1));
            }
            m_database.Shutdown();
            DBStructure database = new DBStructure("", "MyPal");

            database.LoadStructure();

            m_database = database.OpenDatabase( );
            testTable  = m_database.GetTable("People");
            Assert.IsTrue(testTable.Count == 1000);

            for (int i = 1000; i < 2000; i++)
            {
                IRecord record = testTable.NewRecord();
                record.SetValue(1, i.ToString());
                record.Commit();
                Assert.IsTrue(testTable.Count == (i + 1));
            }
        }
예제 #2
0
파일: DBUtilsTest.cs 프로젝트: mo5h/omeo
        public void SetUp()
        {
            try
            {
                DBTest.RemoveDBFiles();
                DBStructure    database  = new DBStructure("", "MyPal");
                TableStructure tblPeople = database.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                tblPeople.CreateColumn("Name", ColumnType.String, true);

                database.SaveStructure();
                m_database = database.OpenDatabase( );

                m_testTable = m_database.GetTable("People");
                for (int i = 0; i < 10; i++)
                {
                    IRecord record = m_testTable.NewRecord();
                    record.SetValue(Name, (500 - i).ToString());
                    record.Commit();
                    Assert.AreEqual((i + 1), m_testTable.Count);
                }
            }
            catch (Exception exc)
            {
                Assert.Fail(exc.Message);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        public void CheckFlushIndexes( )
        {
            ITable  testTable = m_database.GetTable("People");
            IRecord record    = testTable.NewRecord();

            record.SetValue(Name, "ZHU1");
            record.Commit();
            record = testTable.NewRecord();
            record.SetValue(Name, "zhu2");
            record.Commit();
            m_database.Flush();
            record = testTable.NewRecord();
            record.SetValue(Name, "ZHU3");
            record.Commit();
            record = testTable.NewRecord();
            record.SetValue(Name, "zhu4");
            record.Commit();
            m_database.Shutdown();
            DBStructure dbStruct = new DBStructure("", "MyPal");

            dbStruct.LoadStructure();
            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("People");
            Assert.AreEqual(4, testTable.Count);
        }
예제 #5
0
        public void SetUp()
        {
            try
            {
                Stream       stream = File.Open("resume.txt", FileMode.OpenOrCreate, FileAccess.Write);
                BinaryWriter text   = new BinaryWriter(stream);
                text.Write("Resume of developer");
                text.Close();
                stream.Close();

                stream = File.Open("resumeTester.txt", FileMode.OpenOrCreate, FileAccess.Write);
                text   = new BinaryWriter(stream);
                text.Write("Resume of tester");
                text.Close();
                stream.Close();

                DBTest.RemoveDBFiles();
                DBStructure    database  = new DBStructure("", "MyPal");
                TableStructure tblPeople = database.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                tblPeople.CreateColumn("Name", ColumnType.String, true);
                tblPeople.CreateColumn("Resume", ColumnType.BLOB, false);

                database.SaveStructure();
                m_database = database.OpenDatabase( );

                m_testTable = m_database.GetTable("People");
            }
            catch (Exception exc)
            {
                Assert.Fail(exc.Message);
            }
        }
예제 #6
0
        public void TestDateTimeAutoRecovery( )
        {
            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();
            m_database.Shutdown();
            FileStream file = File.Open("MyPal.Date.table.dbUtil", FileMode.Open, FileAccess.Write);

            file.Seek(9, SeekOrigin.Begin);
            byte[] bytes = new byte[8];
            for (int i = 0; i < 8; ++i)
            {
                bytes[i] = 255;
            }
            file.Write(bytes, 0, 8);
            file.Flush();
            file.Close();

            DBStructure dbStruct = new DBStructure("", "MyPal");

            dbStruct.LoadStructure();
            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("Date");
            IResultSet resultSet = testTable.CreateResultSet(1, 32);

            testTable.Defragment();
            m_database.Shutdown();
            dbStruct = new DBStructure("", "MyPal");
            dbStruct.LoadStructure();
            dbStruct.RebuildIndexes(true);

            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("Date");
            Assert.AreEqual(1, testTable.Count);
            resultSet = testTable.CreateResultSet(1, 32, 2, DateTime.MinValue, true);
            int count = 0;

            foreach (IRecord rec in resultSet)
            {
                ++count;
                Assert.AreEqual(DateTime.MinValue, rec.GetDateTimeValue(2));
            }
            Assert.AreEqual(1, count);
        }
예제 #7
0
        public void TestCorruptedRecordMarker( )
        {
            ITable  testTable = m_database.GetTable("People");
            IRecord record    = testTable.NewRecord();

            record.SetValue(1, "zhu");
            record.Commit();
            record = testTable.NewRecord();
            record.SetValue(1, "zhu");
            record.Commit();
            Assert.AreEqual(2, testTable.Count);
            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");
            bool       wasException = false;

            try
            {
                foreach (IRecord rec in resultSet)
                {
                    rec.Equals(null);
                }
            }
            catch (BadIndexesException)
            {
                wasException = true;
            }
            Assert.AreEqual(true, wasException);
            m_database.Shutdown();
            dbStruct = new DBStructure("", "MyPal");
            dbStruct.LoadStructure();
            dbStruct.RebuildIndexes(true);
            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("People");
            Assert.AreEqual(1, testTable.Count);
        }
예제 #8
0
 public void SetUp()
 {
     try
     {
         DBTest.RemoveDBFiles();
         DBTest.CreateDB();
         DBStructure dbStruct = new DBStructure("", "MyPal");
         dbStruct.LoadStructure();
         m_database = dbStruct.OpenDatabase( );
     }
     catch (Exception exc)
     {
         Assert.Fail(exc.Message);
     }
 }
예제 #9
0
파일: DBUtilsTest.cs 프로젝트: mo5h/omeo
        public void SmokeTestForSetCacheSize( )
        {
            DBStructure    database  = new DBStructure("", "MyPal");
            TableStructure tblPeople = database.CreateTable("People");

            tblPeople.CreateColumn("Id", ColumnType.Integer, true);
            tblPeople.CreateColumn("Name", ColumnType.String, true);

            database.SaveStructure();
            IDatabase m_database = database.OpenDatabase( );

            ITable testTable = m_database.GetTable("People");

            testTable = testTable;
            m_database.Shutdown();
        }
예제 #10
0
        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();
        }
예제 #11
0
        public void CheckUnlockDatabaseWhenSaveStructureTest( )
        {
            DBStructure dbStruct = new DBStructure("", "Test");

            TableStructure tableStruct = dbStruct.CreateTable("SomeTable");

            tableStruct.CreateColumn("SomeString", ColumnType.String, false);
            tableStruct.CreateColumn("SomeInt", ColumnType.Integer, false);
            tableStruct.CreateColumn("SomeDate", ColumnType.DateTime, false);
            dbStruct.SaveStructure();

            dbStruct = new DBStructure("", "Test");
            dbStruct.LoadStructure();

            IDatabase database = dbStruct.OpenDatabase( );

            database.Shutdown();
        }
예제 #12
0
        public void CheckCompoundIndexKeyFactory( )
        {
            for (int i = 0; i < 13000; i++)
            {
                IRecord record = _testTable.NewRecord();
                record.SetValue(1, DateTime.Today.AddDays(i));
                record.Commit();
            }
            _database.Shutdown();
            DBStructure dbStructure = new DBStructure("", "MyPal");

            _database = dbStructure.OpenDatabase();
            int i1 = ("1308554180").GetHashCode();

            i1 = i1;
            int i2 = ("2117097963").GetHashCode();

            i2 = i2;
        }
예제 #13
0
        public void TestBackwardIncompatabilityCheckVersionAndEndMark( )
        {
            ITable  testTable = m_database.GetTable("People");
            IRecord record    = testTable.NewRecord();

            record.SetValue(1, "zhu");
            record.Commit();
            m_database.Shutdown();

            FileStream file = File.Open("MyPal.database.struct.dbUtil", FileMode.Open, FileAccess.Write);

            file.Seek(3, SeekOrigin.Begin);
            byte[] bytes = new byte[1];
            bytes[0] = 21;
            file.Write(bytes, 0, 1);
            file.Flush();
            file.Close();


            DBStructure dbStruct = new DBStructure("", "MyPal");

            dbStruct.LoadStructure();
            Assert.AreEqual(false, dbStruct.IsDatabaseCorrect());

            if (!dbStruct.IsDatabaseCorrect())
            {
                dbStruct.RebuildIndexes();
            }
            m_database = dbStruct.OpenDatabase();
            testTable  = m_database.GetTable("People");
            IResultSet resultSet = testTable.CreateResultSet(0, 0);

            Assert.AreEqual(1, testTable.Count);
            int count = 0;

            foreach (IRecord rec in resultSet)
            {
                ++count;
                Assert.AreEqual("zhu", rec.GetStringValue(1));
            }
            Assert.AreEqual(1, count);
        }
예제 #14
0
파일: DBUtilsTest.cs 프로젝트: mo5h/omeo
        public void SmokeTestLoadDatabase( )
        {
            DBTest.CreateDB();
            DBStructure dbStruct = new DBStructure("", "MyPal");

            dbStruct.LoadStructure();

            IDatabase database = dbStruct.OpenDatabase( );
            ITable    people   = database.GetTable("People");
            IRecord   record   = people.NewRecord();

            record.SetValue(Name, "zhu");
            record.SetValue(Age, 30);
            ITable books = database.GetTable("Books");

            record = books.NewRecord();
            record.SetValue(Name, "Algorithm");
            record.SetValue(Price, 1000);
            database.Shutdown();
        }
예제 #15
0
        public void SetUp()
        {
            try
            {
                DBTest.RemoveDBFiles();
                DBStructure    database  = new DBStructure("", "MyPal");
                TableStructure tblPeople = database.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                tblPeople.CreateColumn("Name", ColumnType.String, true);
                tblPeople.CreateColumn("Cash", ColumnType.Double, true);

                database.SaveStructure();
                m_database = database.OpenDatabase( );

                m_testTable = m_database.GetTable("People");
            }
            catch (Exception exc)
            {
                Assert.Fail(exc.Message);
            }
        }
예제 #16
0
파일: CheckIndexTest.cs 프로젝트: mo5h/omeo
        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);
            }
        }
예제 #17
0
파일: DBUtilsTest.cs 프로젝트: mo5h/omeo
        public void CheckSaveLoadIndex( )
        {
            DBStructure    database  = new DBStructure("", "MyPal");
            TableStructure tblPeople = database.CreateTable("People");

            tblPeople.CreateColumn("Id", ColumnType.Integer, true);
            tblPeople.CreateColumn("Name", ColumnType.String, true);

            database.SaveStructure();
            IDatabase m_database = database.OpenDatabase( );

            ITable testTable = m_database.GetTable("People");

            for (int i = 0; i < 1000; i++)
            {
                IRecord record = testTable.NewRecord();
                record.SetValue(Name, (500 - i).ToString());
                record.Commit();
                Assert.IsTrue(testTable.Count == (i + 1));
            }
            m_database.Shutdown();
        }
예제 #18
0
        public override void SetUp()
        {
            IBTree._bUseOldKeys = true;

            DBStructure dbStructure =
                new DBStructure("", "OmniaMeaPerformanceTest", DatabaseMode.Create);

            TableStructure table = dbStructure.CreateTable("IntProps");

            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.Integer, false);
            table.CreateIndex("Id");

            table = dbStructure.CreateTable("StringProps");
            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.String, false);
            table.SetCompoundIndex("PropValue", "PropType");

            table = dbStructure.CreateTable("DateProps");
            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.DateTime, false);
            table.SetCompoundIndex("Id", "PropType");
            table.CreateIndex("PropValue");

            dbStructure.SaveStructure();
            dbStructure.Shutdown();

            _dbStructure = new DBStructure("", "OmniaMeaPerformanceTest");
            _dbStructure.LoadStructure();

            IDatabase db = _dbStructure.OpenDatabase();

            _intPropsTable    = db.GetTable("IntProps");
            _stringPropsTable = db.GetTable("StringProps");
            _datePropsTable   = db.GetTable("DateProps");
        }
예제 #19
0
        public void CheckSaveLoadIndex( )
        {
            ITable testTable = m_database.GetTable("People");

            for (int i = 0; i < 10; i++)
            {
                IRecord record = testTable.NewRecord();
                record.SetValue(Name, i.ToString());
                record.SetValue(Birthday, DateTime.Now.Date);
                record.Commit();
                Assert.IsTrue(testTable.Count == (i + 1));
            }
            m_database.Shutdown();
            DBStructure dbStruct = new DBStructure("", "MyPal");

            dbStruct.LoadStructure();
            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("People");
            Assert.AreEqual(10, testTable.Count);
            IResultSet people = testTable.CreateResultSet(Id);
            int        count  = 0;

            foreach (IRecord person in people)
            {
                int id = person.GetIntValue(Id);
                Assert.AreEqual(count, id);
                string name = person.GetStringValue(Name);
                Assert.AreEqual(count.ToString(), name);
                int age = person.GetIntValue(Age);
                age = age;
                DateTime dateTime = (DateTime)person.GetValue(Birthday);
                Assert.AreEqual(DateTime.Now.Date, dateTime);
                count++;
            }
            Assert.AreEqual(10, count);
            people.Dispose();
        }
예제 #20
0
        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));
        }
예제 #21
0
        public void TestPaddingForTableLength( )
        {
            ITable  testTable = m_database.GetTable("Date");
            IRecord record    = testTable.NewRecord();

            record.SetValue(1, 32);
            record.SetValue(2, new DateTime(1972, 7, 26));
            record.Commit();
            record = testTable.NewRecord();
            record.SetValue(1, 33);
            record.SetValue(2, new DateTime(1972, 7, 26));
            record.Commit();
            IResultSet resultSet = testTable.CreateResultSet(0, 1);

            foreach (IRecord rec in resultSet)
            {
                Assert.AreEqual(new DateTime(1972, 7, 26), rec.GetDateTimeValue(2));
            }
            m_database.Shutdown();
            FileStream file = File.Open("MyPal.Date.table.dbUtil", FileMode.Open, FileAccess.Write);

            file.SetLength(26);
            file.Flush();
            file.Close();

            DBStructure dbStruct = new DBStructure("", "MyPal");

            dbStruct.LoadStructure();
            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("Date");
            resultSet  = testTable.CreateResultSet(0, 1);
            foreach (IRecord rec in resultSet)
            {
                Assert.AreEqual(DateTime.MinValue, rec.GetDateTimeValue(2));
            }
        }
예제 #22
0
파일: CheckIndexTest.cs 프로젝트: mo5h/omeo
        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);
        }
예제 #23
0
        public void TestStringAutorecovery_corruptedCount( )
        {
            ITable  testTable = m_database.GetTable("People");
            IRecord record    = testTable.NewRecord();

            record.SetValue(1, "zhu");
            record.Commit();
            record = testTable.NewRecord();
            record.SetValue(1, "zhu1");
            record.Commit();
            m_database.Shutdown();
            FileStream file = File.Open("MyPal.People.table.dbUtil", FileMode.Open, FileAccess.Write);

            file.Seek(5, 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");

            try
            {
                foreach (IRecord rec in resultSet)
                {
                    rec.Equals(null);
                }
            }
            catch (BadIndexesException)
            {}
            m_database.Shutdown();
            dbStruct = new DBStructure("", "MyPal");
            dbStruct.LoadStructure();
            dbStruct.RebuildIndexes(true);
            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("People");
            Assert.AreEqual(1, testTable.Count);
            resultSet = testTable.CreateResultSet(1, "zhu1");
            int count = 0;

            foreach (IRecord rec in resultSet)
            {
                ++count;
                Assert.AreEqual("zhu1", rec.GetStringValue(1));
            }
            Assert.AreEqual(1, count);
            resultSet = testTable.CreateResultSet(1, "zhu");
            count     = 0;
            foreach (IRecord rec in resultSet)
            {
                ++count;
                rec.Equals(null);
                //Assert.AreEqual( "zhu", rec.GetStringValue( 1 ) );
            }
            Assert.AreEqual(0, count);
        }
예제 #24
0
        public void TestStringAutorecovery_CountToEndMarker( )
        {
            ITable  testTable = m_database.GetTable("EndMarker");
            IRecord record    = testTable.NewRecord();

            record.SetValue(2, "zhu");
            record.Commit();
            record = testTable.NewRecord();
            record.SetValue(2, "zhu1");
            record.Commit();
            record = testTable.NewRecord();
            record.SetValue(2, "zhu2");
            record.Commit();
            m_database.Shutdown();

            FileStream file = File.Open("MyPal.EndMarker.table.dbUtil", FileMode.Open, FileAccess.Write);

            file.Seek(50, SeekOrigin.Begin);
            byte[] bytes = new byte[4];
            bytes[0] = 0xBA;
            bytes[1] = 0xB0;
            bytes[2] = 0xDA;
            bytes[3] = 0xDE;
            file.Write(bytes, 0, 4);
            file.Flush();
            file.Close();

            DBStructure dbStruct = new DBStructure("", "MyPal");

            dbStruct.LoadStructure();
            m_database = dbStruct.OpenDatabase( );
            testTable  = m_database.GetTable("EndMarker");
            IResultSet resultSet = testTable.CreateResultSet(2, "zhu");

            try
            {
                foreach (IRecord rec in resultSet)
                {
                    rec.Equals(null);
                }
            }
            catch (BadIndexesException)
            {}
            m_database.Shutdown();

            dbStruct = new DBStructure("", "MyPal");
            dbStruct.LoadStructure();
            dbStruct.RebuildIndexes(true);
            dbStruct.Shutdown();

            dbStruct = new DBStructure("", "MyPal");
            dbStruct.LoadStructure(  );
            m_database = dbStruct.Database;
            testTable  = m_database.GetTable("EndMarker");
            Assert.AreEqual(2, testTable.Count);
            resultSet = testTable.CreateResultSet(2, "zhu2");
            int count = 0;

            foreach (IRecord rec in resultSet)
            {
                ++count;
                Assert.AreEqual("zhu2", rec.GetStringValue(2));
            }
            Assert.AreEqual(0, count);
            resultSet = testTable.CreateResultSet(2, "zhu");
            count     = 0;
            foreach (IRecord rec in resultSet)
            {
                ++count;
                rec.Equals(null);
                //Assert.AreEqual( "zhu", rec.GetStringValue( 2 ) );
            }
            Assert.AreEqual(1, count);
            resultSet = testTable.CreateResultSet(2, "zhu1");
            count     = 0;
            foreach (IRecord rec in resultSet)
            {
                ++count;
                Assert.AreEqual("zhu1", rec.GetStringValue(2));
            }
            Assert.AreEqual(1, count);
        }
예제 #25
0
        public override void SetUp()
        {
            IBTree._bUseOldKeys = true;

            DBStructure dbStructure =
                new DBStructure("", "OmniaMeaPerformanceTest", DatabaseMode.Create);

            TableStructure table = dbStructure.CreateTable("IntProps");

            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.Integer, false);
            table.CreateIndex("Id");

            table = dbStructure.CreateTable("StringProps");
            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.String, false);
            table.SetCompoundIndex("PropValue", "PropType");

            table = dbStructure.CreateTable("DateProps");
            table.CreateColumn("Id", ColumnType.Integer, false);
            table.CreateColumn("PropType", ColumnType.Integer, false);
            table.CreateColumn("PropValue", ColumnType.DateTime, false);
            table.SetCompoundIndex("PropValue", "PropType");

            dbStructure.SaveStructure();
            dbStructure.Shutdown();

            _dbStructure = new DBStructure("", "OmniaMeaPerformanceTest");
            _dbStructure.LoadStructure();

            IDatabase db = _dbStructure.OpenDatabase();

            _intPropsTable    = db.GetTable("IntProps");
            _stringPropsTable = db.GetTable("StringProps");
            _datePropsTable   = db.GetTable("DateProps");

            Random rnd = new Random();

            for (int i = 0; i < 200000; i++)
            {
                IRecord rec = _intPropsTable.NewRecord();
                rec.SetValue(0, rnd.Next());
                rec.SetValue(1, i % 100);
                rec.SetValue(2, i);
                rec.Commit();
            }
            for (int i = 0; i < 200000; i++)
            {
                IRecord rec = _stringPropsTable.NewRecord();
                rec.SetValue(0, i);
                rec.SetValue(1, i % 100);
                rec.SetValue(2, rnd.NextDouble().ToString());
                rec.Commit();
            }
            for (int i = 0; i < 200000; i++)
            {
                IRecord rec = _datePropsTable.NewRecord();
                rec.SetValue(0, i % 1000);
                rec.SetValue(1, i);
                rec.SetValue(2, new DateTime(rnd.Next()));
                rec.Commit();
            }
        }
예제 #26
0
 public DatabaseProxy(string path)
 {
     _dbStructure = new DBStructure(path, "MyPal");
     _dbStructure.LoadStructure(true);
     _database = _dbStructure.OpenDatabase();
 }