Beispiel #1
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);
            }
        }
Beispiel #2
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;
            }
        }
Beispiel #3
0
        public override void TearDown()
        {
            _dbStructure.Shutdown();

            string[] files = System.IO.Directory.GetFiles(".", "*.dbUtil");
            foreach (string fileName in files)
            {
                System.IO.File.Delete(fileName);
            }
        }
Beispiel #4
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();
        }
Beispiel #5
0
        public static void CreateDB()
        {
            DBStructure database = new DBStructure("", "MyPal", DatabaseMode.Create);

            database.Build = "Build";
            TableStructure tblPeople = database.CreateTable("People");

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

            colName = colName;
            ColumnStructure colAge =
                tblPeople.CreateColumn("Age", ColumnType.Integer, false);

            colAge = colAge;
            tblPeople.CreateColumn("Birthday", ColumnType.DateTime, false);
            tblPeople.SetCompoundIndex("Name", "Age");

            TableStructure tblBooks = database.CreateTable("Books");

            tblBooks.CreateColumn("Id", ColumnType.Integer, true);
            ColumnStructure colBookName =
                tblBooks.CreateColumn("Name", ColumnType.String, true);

            colBookName = colBookName;
            ColumnStructure colPrice =
                tblBooks.CreateColumn("Price", ColumnType.Integer, false);

            colPrice = colPrice;

            TableStructure tblDate = database.CreateTable("Date");

            tblDate.CreateColumn("Id", ColumnType.Integer, true);
            tblDate.CreateColumn("Age", ColumnType.Integer, false);
            tblDate.CreateColumn("Birthday", ColumnType.DateTime, true);
            tblDate.SetCompoundIndexWithValue("Age", "Birthday", "Id");

            TableStructure tblEndMarker = database.CreateTable("EndMarker");

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

            database.SaveStructure();
            database.Shutdown();
        }
Beispiel #6
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;
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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");
        }
Beispiel #9
0
        public void CheckTryCreateSameCompoundIndex( )
        {
            DBStructure dbStructure = null;

            try
            {
                dbStructure = new DBStructure("", "AnotherDB");
                TableStructure tblPeople = dbStructure.CreateTable("People");
                tblPeople.CreateColumn("Id", ColumnType.Integer, true);
                tblPeople.CreateColumn("Name", ColumnType.String, true);
                tblPeople.CreateColumn("Age", ColumnType.Integer, true);
                tblPeople.SetCompoundIndex("Name", "Age");
                tblPeople.SetCompoundIndex("Name", "Age");
            }
            finally
            {
                if (dbStructure != null)
                {
                    dbStructure.Shutdown();
                }
            }
        }
Beispiel #10
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();
            }
        }
Beispiel #11
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);
        }
Beispiel #12
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();
        }
Beispiel #13
0
 public void Dispose()
 {
     _dbStructure.Shutdown();
 }