Пример #1
0
        static bool CheckCreate()
        {
            //test create statement including index and table

            //make a create statement for table
            CreateStatement test_create_table = new CreateStatement();

            test_create_table.CreateType    = CreateType.Table;
            test_create_table.TableName     = "Student";
            test_create_table.IndexName     = "";
            test_create_table.AttributeName = "";

            List <AttributeDeclaration> temp         = new List <AttributeDeclaration>();
            AttributeDeclaration        student_name = new AttributeDeclaration();

            student_name.AttributeName = "Name";
            student_name.CharLimit     = 10;
            student_name.Type          = AttributeTypes.Char;
            student_name.IsUnique      = false;
            AttributeDeclaration student_score = new AttributeDeclaration();

            student_score.AttributeName = "Score";
            student_score.Type          = AttributeTypes.Float;
            student_score.IsUnique      = false;
            AttributeDeclaration student_class = new AttributeDeclaration();

            student_class.AttributeName = "Class";
            student_class.Type          = AttributeTypes.Int;
            student_class.IsUnique      = false;
            AttributeDeclaration student_ID = new AttributeDeclaration();

            student_ID.AttributeName = "ID";
            student_ID.Type          = AttributeTypes.Char;
            student_ID.CharLimit     = 10;
            student_ID.IsUnique      = true;
            temp.Add(student_ID);
            temp.Add(student_name);
            temp.Add(student_score);
            temp.Add(student_class);
            test_create_table.AttributeDeclarations = temp;
            test_create_table.PrimaryKey            = "ID";
            //return whether we have successfully created the statement
            bool test1 = icatalog.TryCreateStatement(test_create_table, 0);

            // Console.WriteLine("Create table, expecting true:");
            // Console.WriteLine(test1);
            Debug.Assert(test1 == true);

            //make a create statement for index
            CreateStatement test_create_index = new CreateStatement();

            test_create_index.CreateType            = CreateType.Index;
            test_create_index.TableName             = "Student";
            test_create_index.IsUnique              = true;
            test_create_index.IndexName             = "index_for_student_id";
            test_create_index.AttributeName         = "ID";
            test_create_index.AttributeDeclarations = new List <AttributeDeclaration>()
            {
                new AttributeDeclaration()
                {
                    AttributeName = "priKey", Type = AttributeTypes.Char, CharLimit = 20
                }
            };
            test_create_index.PrimaryKey = "priKey";
            bool test2 = icatalog.TryCreateStatement(test_create_index, 1);

            // Console.WriteLine("Create index1, expecting true:");
            // Console.WriteLine(test2);
            Debug.Assert(test2 == true);

            CreateStatement test_create_index2 = new CreateStatement();

            test_create_index2.CreateType            = CreateType.Index;
            test_create_index2.TableName             = "Student";
            test_create_index2.IsUnique              = true;
            test_create_index2.IndexName             = "index2";
            test_create_index2.AttributeName         = "ID";
            test_create_index2.AttributeDeclarations = new List <AttributeDeclaration>()
            {
                new AttributeDeclaration()
                {
                    AttributeName = "priKey2", Type = AttributeTypes.Char, CharLimit = 20
                }
            };
            test_create_index2.PrimaryKey = "priKey2";
            bool test3 = icatalog.TryCreateStatement(test_create_index2, 7);

            // Console.WriteLine("Create index2, expecting true:");
            // Console.WriteLine(test3);
            Debug.Assert(test3 == true);

            return(true);
        }