/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/table.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/table.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 285 by bh, Tue Aug 27 14:08:32 2002 UTC revision 286 by bh, Thu Aug 29 11:21:52 2002 UTC
# Line 32  class Table: Line 32  class Table:
32      Currently this is basically just a wrapper around dbflib.      Currently this is basically just a wrapper around dbflib.
33      """      """
34    
35        # Implementation strategy regarding writing to a DBF file:
36        #
37        # Most of the time Thuban only needs to read from a table and it is
38        # important that Thuban can work with read-only files. Therefore the
39        # DBF file is opened only for reading initially. Only when
40        # write_record is called we try to open the DBF file for writing as
41        # well. If that succeeds the dbf read/write DBF file will be used
42        # for all IO afterwards.
43        #
44        # It's important to use the same DBF file object for both reading
45        # and writing to make sure that reading a records after writing
46        # returns the new values. With two separate objects this wouldn't
47        # work because a DBF file object buffers some data
48    
49      def __init__(self, filename):      def __init__(self, filename):
50          self.filename = filename          self.filename = filename
51          self.dbf = dbflib.DBFFile(filename)          self.dbf = dbflib.DBFFile(filename)
52    
53            # If true, self.dbf is open for writing.
54            self._writable = 0
55    
56      def Destroy(self):      def Destroy(self):
57          self.dbf.close()          self.dbf.close()
58          self.dbf = None          self.dbf = None
# Line 76  class Table: Line 93  class Table:
93          If it's a sequence, all fields must be present in the right          If it's a sequence, all fields must be present in the right
94          order.          order.
95          """          """
96          writable_dbf = dbflib.DBFFile(self.filename, "r+b")          if not self._writable:
97          writable_dbf.write_record(record, values)              new_dbf = dbflib.DBFFile(self.filename, "r+b")
98          writable_dbf.close()              self.dbf.close()
99                self.dbf = new_dbf
100                self._writable = 1
101            self.dbf.write_record(record, values)
102            self.dbf.commit()

Legend:
Removed from v.285  
changed lines
  Added in v.286

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26