Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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);
        }