Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);

                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);
            }
        }
Ejemplo n.º 5
0
        public void TableNameMustBeUnique( )
        {
            DBStructure database = new DBStructure(".", "Test");

            database.CreateTable("People");
            try
            {
                database.CreateTable("People");
            }
            catch (TableAlreadyExistsException)
            {
                //it's normal
                return;
            }
            Assert.Fail("'People' table already exists but 'TableAlreadyExists' was not thrown");
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        public void CheckTryCreateCompoundIndexForNotExistedColumn( )
        {
            DBStructure    dbStructure = new DBStructure("", "CheckTryCreateCompoundIndexForNotExistedColumn");
            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", "Age1");
        }
Ejemplo n.º 8
0
        public void CheckDropIndexIfColumnDoesNotExist( )
        {
            DBStructure    dbStructure = new DBStructure("", "CheckDropIndexIfColumnDoesNotExist");
            TableStructure tblPeople   = dbStructure.CreateTable("People");

            tblPeople.CreateColumn("Id", ColumnType.Integer, true);
            tblPeople.CreateColumn("Name", ColumnType.String, false);
            tblPeople.CreateColumn("Age", ColumnType.Integer, false);
            tblPeople.DropIndex("Name1");
        }
Ejemplo n.º 9
0
        public void CheckCreateIndexIfIndexAlreadyExists( )
        {
            DBStructure    dbStructure = new DBStructure("", "CheckCreateIndexIfIndexAlreadyExists");
            TableStructure tblPeople   = dbStructure.CreateTable("People");

            tblPeople.CreateColumn("Id", ColumnType.Integer, true);
            tblPeople.CreateColumn("Name", ColumnType.String, true);
            tblPeople.CreateColumn("Age", ColumnType.Integer, false);
            tblPeople.CreateIndex("Name");
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
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");
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
0
        public void ColumnNameMustBeUnique( )
        {
            DBStructure    database = new DBStructure(".", "Test");
            TableStructure table    = database.CreateTable("People");

            table.CreateColumn("Name", ColumnType.String, true);
            try
            {
                table.CreateColumn("Name", ColumnType.String, true);
            }
            catch (ColumnAlreadyExistsException)
            {
                //it's normal
                return;
            }
            Assert.Fail("'Name' column already exists but 'ColumnAlreadyExists' was not thrown");
        }
Ejemplo n.º 15
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();
        }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
0
        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();
        }
Ejemplo n.º 18
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();
                }
            }
        }
Ejemplo n.º 19
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();
            }
        }