Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void TestBackwardIncompatability( )
        {
            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] = 24;
            file.Write(bytes, 0, 1);
            file.Flush();
            file.Close();

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

            try
            {
                dbStruct.LoadStructure();
            }
            finally
            {
                dbStruct.Shutdown();
                m_database = null;
            }
        }
Exemplo n.º 4
0
        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));
            }
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            try
            {
                DBTest.RemoveDBFiles();
                DBStructure    database  = new DBStructure("", "MyPal", DatabaseMode.Create);
                TableStructure tblPeople = database.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                ColumnStructure colName =
                    tblPeople.CreateColumn("Name", ColumnType.String, false);
                colName = colName;
                tblPeople.CreateColumn("Age", ColumnType.Integer, false);
                tblPeople.CreateColumn("Type", ColumnType.Integer, true);
                tblPeople.CreateColumn("DateTime", ColumnType.DateTime, true);
                tblPeople.SetCompoundIndex("Id", "Name");
                tblPeople.SetCompoundIndex("Name", "Type");

                database.SaveStructure();
                database.Shutdown();
                database = new DBStructure("", "MyPal");
                database.LoadStructure( );
                m_database = database.Database;
            }
            catch (Exception exc)
            {
                Assert.Fail(exc.Message);
            }
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
     }
 }
Exemplo n.º 10
0
        public void SetUp()
        {
            DBTest.RemoveDBFiles();
            DBStructure    database  = new DBStructure("", "MyPal", DatabaseMode.Create);
            TableStructure tblPeople = database.CreateTable("People");

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

            database.SaveStructure();
            database.Shutdown();
            database = new DBStructure("", "MyPal");
            database.LoadStructure( );
            m_database = database.Database;
        }
Exemplo n.º 11
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();
        }
Exemplo n.º 12
0
        public void SetUp()
        {
            try
            {
                DBTest.RemoveDBFiles();
                DBStructure    database  = new DBStructure("", "MyPal", DatabaseMode.Create);
                TableStructure tblPeople = database.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                ColumnStructure colName =
                    tblPeople.CreateColumn("Name", ColumnType.String, false);
                colName = colName;
                tblPeople.CreateColumn("Age", ColumnType.Integer, false);
                tblPeople.CreateColumn("Type", ColumnType.Integer, true);
                tblPeople.CreateColumn("DateTime", ColumnType.DateTime, true);
                tblPeople.SetCompoundIndex("Id", "Name");
                tblPeople.SetCompoundIndex("Name", "Type");

                TableStructure tblTest = database.CreateTable("Test");
                tblTest.CreateColumn("Id", ColumnType.Integer, false);
                tblTest.CreateColumn("Date", ColumnType.DateTime, false);
                tblTest.SetCompoundIndex("Id", "Date");

                database.SaveStructure();
                database.Shutdown();
                database = new DBStructure("", "MyPal", DatabaseMode.Create);
                database.LoadStructure( );
                _database = database.Database;

                _peopleTable = _database.GetTable("People");
                _testTable   = _database.GetTable("Test");
                //m_testTable.InputMode = InputMode.Batch;
                for (int i = 0; i < 10; i++)
                {
                    IRecord record = _peopleTable.NewRecord();
                    Assert.AreEqual(i, record.GetID(), "Id is wrong");
                    record.SetValue(1, (500 - i).ToString());
                    record.Commit();
                    Assert.AreEqual((i + 1), _peopleTable.Count, "Count is wrong");
                }
            }
            catch (Exception exc)
            {
                Assert.Fail(exc.Message);
            }
        }
Exemplo n.º 13
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();
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        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();
        }
Exemplo n.º 16
0
        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);
            }
        }
Exemplo n.º 17
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");
        }
Exemplo n.º 18
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();
        }
Exemplo n.º 19
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));
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 21
0
        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));
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
        private void ProcessDB()
        {
            if (!DBHelper.DatabaseExists(MyPalStorage.DBPath, "MyPal"))
            {
                Console.WriteLine("Omea database not found");
                return;
            }

            DBStructure dbStructure = new DBStructure(MyPalStorage.DBPath, "MyPal");

            dbStructure.ProgressListenerEvent += new DBStructure.ProgressEventHandler(dbStructure_ProgressListenerEvent);

            Console.WriteLine("Loading database...");

            bool structureCorrupted = false;

            try
            {
                dbStructure.LoadStructure(true);
            }
            catch (Exception)
            {
                structureCorrupted = true;
            }

            if (structureCorrupted || !AllTablesExist(dbStructure))
            {
                Console.WriteLine("Rebuilding database structure...");
                dbStructure.Shutdown();

                MyPalStorage.CreateDatabase();
                dbStructure = new DBStructure(MyPalStorage.DBPath, "MyPal");
                dbStructure.LoadStructure(true);
                _forceRebuild = true;
            }

            if (_defrag)
            {
                Console.WriteLine("Defragmenting database...");
                dbStructure.Defragment();
            }
            else if (!dbStructure.IsDatabaseCorrect())
            {
                Console.WriteLine("Database indexes are corrupt. Rebuilding...");
                dbStructure.RebuildIndexes();
            }
            else if (_forceRebuild)
            {
                Console.WriteLine("Performing forced rebuild of database indexes...");
                dbStructure.RebuildIndexes(true);
            }
            else if (_lowCheck)
            {
                dbStructure.LowLevelCheck( );
                return;
            }

            if (_dbdump)
            {
                Console.WriteLine("Dumping database...");
                dbStructure.Dump();
            }

            IDatabase db = dbStructure.OpenDatabase();

            if (_calcSpace)
            {
                CalcSpace(db, "ResourceTypes");
                CalcSpace(db, "PropTypes");
                CalcSpace(db, "IntProps");
                CalcSpace(db, "StringProps");
                CalcSpace(db, "LongStringProps");
                CalcSpace(db, "StringListProps");
                CalcSpace(db, "DateProps");
                CalcSpace(db, "BlobProps");
                CalcSpace(db, "DoubleProps");
                CalcSpace(db, "Resources");
                CalcSpace(db, "Links");
                return;
            }

            ResourceStoreRepair rsRepair = new ResourceStoreRepair(db);

            rsRepair.FixErrors       = _fixErrors;
            rsRepair.DumpStructure   = _dump;
            rsRepair.RepairProgress += new RepairProgressEventHandler(RsRepair_OnRepairProgress);
            rsRepair.Run();
        }
Exemplo n.º 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);
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
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();
            }
        }
Exemplo n.º 27
0
 public DatabaseProxy(string path)
 {
     _dbStructure = new DBStructure(path, "MyPal");
     _dbStructure.LoadStructure(true);
     _database = _dbStructure.OpenDatabase();
 }