commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue-common/src/datasources GDataObjects.py


From: Jason Cater
Subject: gnue-common/src/datasources GDataObjects.py
Date: Thu, 17 Jul 2003 01:24:17 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue-common
Branch:         
Changes by:     Jason Cater <address@hidden>    03/07/17 01:24:17

Modified files:
        src/datasources: GDataObjects.py 

Log message:
        Added some convenience python-isms to resultset and recordset;
        * insertRecord, nextRecord, firstRecord,
        prevRecord, lastRecord, geRecord  --
        all return either None (false; no record loaded)
        or the actual RecordSet, instead of 0 or 1
        (this shouldn't break any old code as a boolean
        test will still return the same results)
        
        * RecordSet supports dictionary methods, so instead of
        val = resultset.getField('test')
        resultset.setField('test2', 12)
        you can do:
        val = resultset['test']
        resultset['test2'] = 12
        
        All old functions still work as expected, so no code breakage.
        
        In a nutshell, this means the following code fragment:
        
        if resultset.firstRecord():
        val = resultset.getField('foo')
        resultset2.insertRecord()
        resultset2.current.setField('foo2', val)
        
        could just as easily be written:
        
        rec = resultset.firstRecord()
        if rec:
        newRec = resultset2.insertRecord()
        newRec[foo2] = rec['foo']
        
        (not much shorter, but more Python-ish)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/GDataObjects.py.diff?tr1=1.68&tr2=1.69&r1=text&r2=text

Patches:
Index: gnue-common/src/datasources/GDataObjects.py
diff -c gnue-common/src/datasources/GDataObjects.py:1.68 
gnue-common/src/datasources/GDataObjects.py:1.69
*** gnue-common/src/datasources/GDataObjects.py:1.68    Tue Apr 29 15:25:16 2003
--- gnue-common/src/datasources/GDataObjects.py Thu Jul 17 01:24:17 2003
***************
*** 365,424 ****
        pass
  
      if record >= len(self._cachedRecords):
!       return 0
      else:
        self._currentRecord = record
        self.current = self._cachedRecords[self._currentRecord]
        self.notifyDetailObjects()
!       return 1
  
    # returns 1=New record loaded, 0=No more records
    def nextRecord(self):
      if self._currentRecord + 1 == len(self._cachedRecords):
        if not self._cacheNextRecord():
!         return 0
  
      self._currentRecord += 1
      self.current = self._cachedRecords[self._currentRecord]
      self.notifyDetailObjects()
!     return 1
  
  
    # returns 1=New record loaded, 0=At first record
    def prevRecord(self):
      if self._currentRecord < 1:
!       return 0
      else:
        self._currentRecord -= 1
        self.current = self._cachedRecords[self._currentRecord]
        self.notifyDetailObjects()
!       return 1
  
  
    # returns 1=at first record, 0=No records loaded
    def firstRecord(self):
      if self._currentRecord < 0:
        if not self._cacheNextRecord():
!         return 0
  
      self._currentRecord = 0
      self.current = self._cachedRecords[0]
      self.notifyDetailObjects()
!     return 1
  
  
  
    # returns 1=at last record, 0=No records loaded
    def lastRecord(self):
      if self._currentRecord == -1:
!       return 0
      else:
        while self._cacheNextRecord():
          pass
        self._currentRecord = len(self._cachedRecords) - 1
        self.current = self._cachedRecords[self._currentRecord]
        self.notifyDetailObjects()
!       return 1
  
  
  
--- 365,424 ----
        pass
  
      if record >= len(self._cachedRecords):
!       return None
      else:
        self._currentRecord = record
        self.current = self._cachedRecords[self._currentRecord]
        self.notifyDetailObjects()
!       return self.current
  
    # returns 1=New record loaded, 0=No more records
    def nextRecord(self):
      if self._currentRecord + 1 == len(self._cachedRecords):
        if not self._cacheNextRecord():
!         return None
  
      self._currentRecord += 1
      self.current = self._cachedRecords[self._currentRecord]
      self.notifyDetailObjects()
!     return self.current
  
  
    # returns 1=New record loaded, 0=At first record
    def prevRecord(self):
      if self._currentRecord < 1:
!       return None
      else:
        self._currentRecord -= 1
        self.current = self._cachedRecords[self._currentRecord]
        self.notifyDetailObjects()
!       return self.current
  
  
    # returns 1=at first record, 0=No records loaded
    def firstRecord(self):
      if self._currentRecord < 0:
        if not self._cacheNextRecord():
!         return None
  
      self._currentRecord = 0
      self.current = self._cachedRecords[0]
      self.notifyDetailObjects()
!     return self.current
  
  
  
    # returns 1=at last record, 0=No records loaded
    def lastRecord(self):
      if self._currentRecord == -1:
!       return None
      else:
        while self._cacheNextRecord():
          pass
        self._currentRecord = len(self._cachedRecords) - 1
        self.current = self._cachedRecords[self._currentRecord]
        self.notifyDetailObjects()
!       return self.current
  
  
  
***************
*** 451,457 ****
            i += 1
  
        self.notifyDetailObjects()
!       return 1
  
  
    # Returns 1=DataObject, or a detail resultset, has uncommitted changes
--- 451,457 ----
            i += 1
  
        self.notifyDetailObjects()
!       return self.current
  
  
    # Returns 1=DataObject, or a detail resultset, has uncommitted changes
***************
*** 595,600 ****
--- 595,606 ----
        self._fields = {}
        self._fields.update(defaultData)
  
+   def __setitem__(self, attr, val):
+     self.setField(attr, val)
+ 
+   def __getitem__(self, attr):
+     return self.getField(attr)
+ 
    # Returns 1=Record has uncommitted changes
    def isPending(self):
  
***************
*** 678,683 ****
--- 684,690 ----
              self._parent._dataObject._dataSource._onModification(self)
            except AttributeError:
              pass
+     return value
  
    # Batch mode of above setField method
    # If trackMod is set to 0 then the modification flag isn't raised




reply via email to

[Prev in Thread] Current Thread [Next in Thread]