示例#1
0
文件: DBUtilsTest.cs 项目: mo5h/omeo
        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();
        }
示例#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, false);
         tblPeople.CreateColumn("Type", ColumnType.Integer, false);
         tblPeople.CreateColumn("Number", ColumnType.Integer, false);
         tblPeople.SetCompoundIndexWithValue("Type", "Id", "Number");
         tblPeople.SetCompoundIndex("Id", "Type");
         database.SaveStructure();
         database.Shutdown();
         database = new DBStructure("", "MyPal");
         database.LoadStructure(  );
         m_database = database.Database;
     }
     catch (Exception exc)
     {
         Assert.Fail(exc.Message);
     }
 }
示例#3
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));
        }