Пример #1
0
        static bool CheckUpdate()
        {
            //update the rootpage of a table
            SchemaRecord table_before = icatalog.GetTableSchemaRecord("Student");

            Console.WriteLine(table_before.RootPage);
            icatalog.TryUpdateSchemaRecord("Student", 2);
            SchemaRecord table_after = icatalog.GetTableSchemaRecord("Student");

            Console.WriteLine(table_after.RootPage);
            Debug.Assert(table_after.RootPage == 2);

            //update the rootpage of an index
            SchemaRecord index_before = icatalog.GetIndexSchemaRecord("index_for_student_id");

            Console.WriteLine(index_before.RootPage);
            icatalog.TryUpdateSchemaRecord("index_for_student_id", 3);
            SchemaRecord index_after = icatalog.GetIndexSchemaRecord("index_for_student_id");

            Console.WriteLine(index_after.RootPage);
            Debug.Assert(index_after.RootPage == 3);

            //try to update the table or index that does not exist
            //will print false
            bool test1 = icatalog.TryUpdateSchemaRecord("HHH", 5);
            bool test2 = icatalog.TryUpdateSchemaRecord("hhh", 6);

            Console.WriteLine(test1);
            Console.WriteLine(test2);
            Debug.Assert(test1 == false);
            Debug.Assert(test2 == false);

            return(true);
        }
Пример #2
0
        // delete statement
        // NOTICE: relative index trees will NOT change accordingly
        private void HandleStatement(DeleteStatement statement)
        {
            // get table and indices
            _catalogManager.CheckValidation(statement);
            SchemaRecord        tableSchema  = _catalogManager.GetTableSchemaRecord(statement.TableName);
            List <SchemaRecord> indexSchemas = _catalogManager.GetIndicesSchemaRecord(statement.TableName);

            // TODO
            // delete index records from index trees
            // __problem__:
            // attribute names := (priKey, a, b, c)
            // condition := b < 3 and c > 5
            // fun facts: b and c both have index trees
            // issue: to delete the records satisfying the condition above

            // delete record from table tree
            int newTableRootPage = _recordManager.DeleteRecords(statement.Condition, tableSchema.SQL.PrimaryKey, tableSchema.SQL.AttributeDeclarations, tableSchema.RootPage);

            _catalogManager.TryUpdateSchemaRecord(statement.TableName, newTableRootPage);
        }