Beispiel #1
0
 def create_catalog():
     table_name1 = '/home/latin/code/latin/python/latin_database/version3/data/test1'
     table_name2 = '/home/latin/code/latin/python/latin_database/version3/data/test2'
     td1 = TestUtil.gen_tuple_desc1()
     td2 = TestUtil.gen_tuple_desc1()
     Catalog.add_table(table_name1, td1)
     Catalog.add_table(table_name2, td2)
Beispiel #2
0
 def clear():
     catalog_file = '/home/latin/code/latin/python/latin_database/version3/data/catalog'
     data_file1 = '/home/latin/code/latin/python/latin_database/version3/data/test1'
     data_file2 = '/home/latin/code/latin/python/latin_database/version3/data/test2'
     open(catalog_file, 'wb+').close()
     open(data_file1, 'wb+').close()
     open(data_file2, 'wb+').close()
     os.remove(catalog_file)
     os.remove(data_file1)
     os.remove(data_file2)
     Catalog.clear()
     Database.clear()
 def read_page(cls, page_id):
     tid = page_id.get_table_id()
     table_name = Catalog.id_to_name(tid)
     with open(table_name, 'rb+') as f:
         index = page_id.get_page_index()
         cls.seek_page(f, index)
         desc = Catalog.id_to_tuple_desc(tid)
         n = cls.read_tuple_num(f)
         tuples = []
         for i in range(n):
             t = cls.read_tuple(f, desc, page_id)
             tuples.append(t)
         return tuples
Beispiel #4
0
 def get_capacity(self):
     PGSIZE = 4096
     tid = self.id.get_table_id()
     tuple_size = Catalog.get_tuple_desc_size(tid)
     size = PGSIZE - IntType.get_size()
     tuple_num = int(size / tuple_size)
     return tuple_num
Beispiel #5
0
 def execute(self):
     hf = Catalog.name_to_file(self.table_name)
     tuples = hf.get_all_tuples()
     if self.has_filter():
         match_tuples = []
         for t in tuples:
             if t.is_match(self.filt_fields):
                 match_tuples.append(t)
         tuples = match_tuples
     return tuples
 def flush_page(cls, page):
     tid = page.get_table_id()
     index = page.get_index()
     table_name = Catalog.id_to_name(tid)
     with open(table_name, 'rb+') as f:
         tuples = page.tuples
         cls.seek_page(f, index)
         n = len(tuples)
         cls.write_tuple_num(f, n)
         for t in tuples:
             cls.write_tuple(f, t)
Beispiel #7
0
 def gen_tuples_for_page1(table_name, page_index, tuple_num=None):
     tuple_desc = TestUtil.get_tuple_desc(table_name)
     field_descs = tuple_desc.get_field_descs()
     if tuple_num == None:
         tuple_num = Catalog.get_page_capacity(table_name)
     tuples = []
     for i in range(tuple_num):
         id_ = i + page_index * 4096
         value1 = id_
         value2 = 'a' + str(id_)
         values = [value1, value2]
         fields = []
         for i in range(len(field_descs)):
             d = field_descs[i]
             v = values[i]
             f = Field(d, v)
             fields.append(f)
         t = Tuple(fields)
         tuples.append(t)
     return tuples
 def flush_page_num(cls, table_id, page_num):
     table_name = Catalog.id_to_name(table_id)
     with open(table_name, 'rb+') as f:
         cls.write_integer(f, page_num)
Beispiel #9
0
 def execute(self):
     hf = Catalog.name_to_file(self.table_name)
     hf.insert_tuple(self.tuple, self.tran_id, 'X')
Beispiel #10
0
 def get_page_id(table_name, page_index):
     table_id = Catalog.name_to_id(table_name)
     pid = PageId(table_id, page_index)
     return pid
Beispiel #11
0
 def gen_page_id2(page_index):
     table_name = '/home/latin/code/latin/python/latin_database/version3/data/test2'
     table_id = Catalog.name_to_id(table_name)
     page_id = PageId(table_id, page_index)
     return page_id
Beispiel #12
0
 def get_tuple_desc(table_name):
     return Catalog.get_tuple_desc(table_name)
Beispiel #13
0
 def gen_page(table_name, page_index, tuple_num=None):
     tid = Catalog.name_to_id(table_name)
     pid = PageId(tid, page_index)
     tuples = TestUtil.gen_tuples_for_page1(table_name, page_index, tuple_num)
     p = HeapPage(pid, tuples)
     return p
Beispiel #14
0
 def execute(self):
     # match_tuples = self.filt()
     hf = Catalog.name_to_file(self.table_name)
     # tuples = hf.get_all_tuples()
     # for t in match_tuples:
     hf.delete_tuple(self.filt_fields)