Exemplo n.º 1
0
    def test_creation(self):
        """Tests record creation and low level
        scanning to retrieve records from the database."""

        rec = wgdb.create_record(self.d, 3)
        self.assertTrue(wgdb.is_record(rec))
        l = wgdb.get_record_len(self.d, rec)
        self.assertEqual(l, 3)
        rec2 = wgdb.create_raw_record(self.d, 678)
        self.assertTrue(wgdb.is_record(rec2))
        l = wgdb.get_record_len(self.d, rec2)
        self.assertEqual(l, 678)
        
        # wgdb module only allows comparing records by contents
        # so we need to use recognizable data for this test.
        wgdb.set_field(self.d, rec, 0, 99531179)
        wgdb.set_field(self.d, rec2, 0, 55498756)

        # XXX: the following relies on certain assumptions on memory
        # management of WhiteDB. By the API description, the records
        # are not necessarily fetched in order of creation, it is just
        # useful for the current test case that it happens to be the case.
        #
        cand = wgdb.get_first_record(self.d)
        self.assertEqual(wgdb.get_field(self.d, cand, 0), 99531179)
        cand = wgdb.get_next_record(self.d, cand)
        self.assertEqual(wgdb.get_field(self.d, cand, 0), 55498756)

        # This, however, should always work correctly
        wgdb.delete_record(self.d, rec)
        cand = wgdb.get_first_record(self.d)
        self.assertEqual(wgdb.get_field(self.d, cand, 0), 55498756)
Exemplo n.º 2
0
 def _new_record(self, rec):
     """Create a Record instance from wgdb record object (internal)"""
     r = Record(self, rec)
     if self.locking:
         self.start_read()
     try:
         r.size = wgdb.get_record_len(self._db, rec)
     finally:
         if self.locking:
             self.end_read()
     return r