commit-gnue
[Top][All Lists]
Advanced

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

gnue/gnue-common/gnue/common GClientApp.py GDat...


From: Jason Cater
Subject: gnue/gnue-common/gnue/common GClientApp.py GDat...
Date: Fri, 11 May 2001 14:59:04 -0700

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/05/11 14:59:04

Modified files:
        gnue-common/gnue/common: GClientApp.py GDataObjects.py 
        gnue-common/gnue/common/dbdrivers/_dbsig: DBdriver.py 
        gnue-common/gnue/common/dbdrivers/pg: DBdriver.py 

Log message:
        Modified gfclient to use the new GClientApp class.  Note the new help 
system :)  Developers should now try to start using 
gnue.common.GDebug.printMesg instead of GFDebug.printMesg. Note that 
GFDebug.printMesg now simply calls GDebug.printMesg, so code will not be 
broken.  However, GFDebug *should* be phased out.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GClientApp.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/GDataObjects.py.diff?cvsroot=OldCVS&tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/gnue/common/dbdrivers/pg/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue/gnue-common/gnue/common/GClientApp.py
diff -u gnue/gnue-common/gnue/common/GClientApp.py:1.1 
gnue/gnue-common/gnue/common/GClientApp.py:1.2
--- gnue/gnue-common/gnue/common/GClientApp.py:1.1      Fri May 11 14:09:39 2001
+++ gnue/gnue-common/gnue/common/GClientApp.py  Fri May 11 14:59:04 2001
@@ -49,6 +49,7 @@
   ARGUMENTS = []    # Will contain an array of command line arguments
 
   def __init__(self): 
+
     # format of COMMAND_OPTIONS and _base_options: 
     #  [option, option] where option is: 
     #       [dictionary key name, short option, long option, 
@@ -122,9 +123,13 @@
 #          'Unable to load the connections definition file.\n' \
 #          + '\n   Please set the environmental variable GNUE_CONNECTIONS or ' 
\
 #          + '\n   use the "-f" command option.')
+
+    try: 
+      GDebug.setDebug(int("%s" % self.OPTIONS['debug_level']),
+          self.OPTIONS['debug_file'])
+    except ValueError: 
+      self.handleStartupError('The debug_level option ("-d") expects a 
numerical value.')
 
-    GDebug.setDebug(self.OPTIONS['debug_level'],
-        self.OPTIONS['debug_file'])
 
     GDebug.printMesg(1,"Run Options: %s" % opt)
     GDebug.printMesg(1,"Run Arguments: %s" % self.ARGUMENTS)
@@ -163,11 +168,11 @@
       else: 
         valMarker = " " * (maxArg+2)
       dispOptions = dispOptions + "\n" +\
-           ("  -%s, --%s %s  " % (allOptions[optionKey][1], 
+           ("  -%s, --%s %s " % (allOptions[optionKey][1], 
                                   allOptions[optionKey][2], valMarker)) +\
            " "*(maxLength-len(allOptions[optionKey][2]))
 
-      margin = maxLength + 13 + maxArg
+      margin = maxLength + 12 + maxArg
       width = 78 - margin
       pos = 0
 
@@ -201,4 +206,3 @@
       sys.exit()
 
 
-GClientApp()
Index: gnue/gnue-common/gnue/common/GDataObjects.py
diff -u gnue/gnue-common/gnue/common/GDataObjects.py:1.2 
gnue/gnue-common/gnue/common/GDataObjects.py:1.3
--- gnue/gnue-common/gnue/common/GDataObjects.py:1.2    Wed May  2 15:33:04 2001
+++ gnue/gnue-common/gnue/common/GDataObjects.py        Fri May 11 14:59:04 2001
@@ -31,7 +31,14 @@
 
 import GDebug
 from string import lower
+import exceptions
 
+class DataObjectError(StandardError): 
+  pass
+
+class ReadOnlyError(DataObjectError): 
+  pass
+
 ###########################################################
 #
 # 
@@ -44,20 +51,20 @@
     self._dataConnection = None
     self._resultSetClass = ResultSet
 
-  def createResultSet(self, conditions={}): 
-    return self._resultSetClass()
+  def createResultSet(self, conditions={}, readOnly=0): 
+    pass
 
   def addDetailDataSource(self, ds): 
     GDebug.printMesg (1,"DataSource: adding a master/detail relationship")
     self._detailSources.append (ds)
 
-  def connect(self, connectData={}): 
+  def connect(self, connectData={}):
     pass
 
-  def commit(self): 
+  def commit(self):
     pass
 
-  def rollback(self): 
+  def rollback(self):
     pass
 
 
@@ -75,13 +82,19 @@
      self._currentRecord = -1
      self._defaultValues = defaultValues
      self._masterRecordSet = masterRecordSet
+     self._readonly = 0
 
      self.current = None
 
-#     if parentRecordSet: 
-#       self._masterRecordSet.
+     if masterRecordSet: 
+       masterRecordSet.addDetailResultSet(self)
 
 
+  # Returns whether this result set is read only or not
+  def isReadOnly(self): 
+    return self._readonly
+  
+
   # Returns 1=At first record, 0=Not first record
   def isFirstRecord(self):
     return (_currentRecord == 1)
@@ -144,10 +157,14 @@
 
   # Insert a blank record after the current record
   def insertRecord(self):
-    self._currentRecord = self._currentRecord+1
-    self._cachedRecords.insert(_currentRecord, self._createEmptyRecord())
-    current = self._cachedRecords[self._currentRecord]
-    return 1
+    if self.isReadOnly(): 
+      # Provide better feedback?? 
+      raise ReadOnlyError, "Attempted to insert into a read only datasource"
+    else: 
+      self._currentRecord = self._currentRecord+1
+      self._cachedRecords.insert(_currentRecord, self._createEmptyRecord())
+      current = self._cachedRecords[self._currentRecord]
+      return 1
 
 
   # Returns 1=DataSource has uncommitted changes 
@@ -172,10 +189,9 @@
     pass
 
 
-  # Called when master in master/detail is updated
+  # 
   def notifyDetailSources(self):
     pass
-
   
 
   ###
@@ -200,14 +216,14 @@
 ###########################################################
 class RecordSet: 
 
-  def __init__(self, initialData={}, dbIdentifier=None, defaultData={}): 
+  def __init__(self, parent, initialData={}, dbIdentifier=None, 
defaultData={}): 
     self._detailSources = []
-    self.dbIdentifier = dbIdentifier
+    self._dbIdentifier = dbIdentifier
     self._deleteFlag = 0
     self._updateFlag = 0
+    self._parent = parent
     self._modifiedFlags = {}      # If field name is present as a key, 
                                   # then field has been modified
-
     if len(initialData): 
       self._insertFlag = 0
       self._emptyFlag = 0
@@ -217,6 +233,7 @@
       self._emptyFlag = 1
       self._fields = defaultData
 
+
   # Returns 1=Record has uncommitted changes
   def isPending(self):
     if self._emptyFlag or self._insertFlag and self._deleteFlag: 
@@ -264,17 +281,29 @@
 
   # Sets current value of "field"
   def setField(self, field, value):
-    self._emptyFlag = 0
-    self._updateFlag = 1
-    fn = lower(field)
-    self._fields[fn] = value
-    if self._modifiedFlags.has_key(fn): 
-      flag = self._modifiedFlags[fn] + 1
+    # If this field is bound to a datasource and the datasource is read only, 
+    # generate an error.
+    if self.isFieldBound(field) and self._parent.isReadOnly(): 
+      # Provide better feedback??
+      raise ReadOnlyError, "Attempted to modify read only field '%s'" % field
     else: 
-      flag = 1
-    self._modifiedFlags[fn] = flag
+      self._emptyFlag = 0
+      fn = lower(field)
+      self._fields[fn] = value
+      if self.isFieldBound(field): 
+        self._updateFlag = 1
+      if self._modifiedFlags.has_key(fn): 
+        flag = self._modifiedFlags[fn] + 1
+      else: 
+        flag = 1
+      self._modifiedFlags[fn] = flag
 
 
+  # Returns 1=Field is bound to a database field
+  def isFieldBound(self, fieldName): 
+    return self._boundFields.has_key(lower(fieldName))
+
+
   # Returns 1=Field has been modified
   def isFieldModified(self, fieldName):
     return self._modifiedFlags.has_key (lower(fieldName))   
@@ -282,11 +311,19 @@
 
   # Posts changes to database
   def delete(self): 
-    self._deleteFlag = 1
+    if self._parent.isReadOnly(): 
+      # Provide better feedback?? 
+      raise ReadOnlyError, "Attempted to delete from a read only datasource"
+    else: 
+      self._deleteFlag = 1
 
 
   # Posts changes to database
   def post(self):
+    # Should a post() to a read only datasource cause a ReadOnlyError?
+    # It does no harm to attempt to post since nothing will be posted,
+    # But does this allow sloppy programming?
+
     if self.isPending(): 
       self._postChanges()
 
@@ -296,7 +333,7 @@
 
 
   # Sets the ResultSet associated with this master record
-  def setDetailResultSet(self, ds):
+  def addDetailResultSet(self, ds):
     self._detailSources.append(ds)
 
 
Index: gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py
diff -u gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.1 
gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.2
--- gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py:1.1       Wed May 
 2 15:33:04 2001
+++ gnue/gnue-common/gnue/common/dbdrivers/_dbsig/DBdriver.py   Fri May 11 
14:59:04 2001
@@ -58,13 +58,14 @@
         self._fieldNames = []
         for t in (self._cursor.description): 
           self._fieldNames.append (t[0])
+          self._boundFields[lower[t[0]]] = ""
       if rs: 
         i = 0
         dict = {}
         for f in (rs): 
           dict[self._fieldNames[i]] = f
           i = i + 1
-        self._cachedRecords.append (self._recordSetClass(initialData=dict))
+        self._cachedRecords.append (self._recordSetClass(parent=self, 
initialData=dict))
         return 1
       else:
         return 0
@@ -81,13 +82,16 @@
     self._resultSetClass = DBSIG_ResultSet
     self._DatabaseError = None
 
-  def createResultSet(self, conditions={}): 
+  def createResultSet(self, conditions={}, readOnly=0): 
     try: 
       cursor = self._dataConnection.cursor()
       cursor.execute(self._buildQuery(conditions))
     except self._DatabaseError, err: 
       raise DBError, err
-    return self._resultSetClass(cursor=cursor)
+    rs = self._resultSetClass(cursor=cursor)
+    if readOnly: 
+      rs._readonly = readOnly
+    return rs
 
   def commit(self): 
     GDebug.printMesg (5,"DB-SIG database driver: commit()")
@@ -104,6 +108,7 @@
       connection.rollback()
     except: 
       pass     # I'm SURE this isn't right (jcater)
+                # But not all db's support transactions
 
   def _buildQuery(self, conditions={}): 
     return None
Index: gnue/gnue-common/gnue/common/dbdrivers/pg/DBdriver.py
diff -u gnue/gnue-common/gnue/common/dbdrivers/pg/DBdriver.py:1.1 
gnue/gnue-common/gnue/common/dbdrivers/pg/DBdriver.py:1.2
--- gnue/gnue-common/gnue/common/dbdrivers/pg/DBdriver.py:1.1   Wed May  2 
15:33:04 2001
+++ gnue/gnue-common/gnue/common/dbdrivers/pg/DBdriver.py       Fri May 11 
14:59:04 2001
@@ -35,10 +35,27 @@
 from gnue.common.dbdrivers._dbsig import DBdriver
 
 
-#### NOTE:  Once PyGreSQL's .fetchone() bug is fixed, this class 
-####   should be deleted!  Also note the line in PG_DataSource.__init__ .
-####   Right now, we are having to preload *ALL* rows from a datasource.
+class PG_RecordSet(DBdriver.DBSIG_RecordSet): 
+  def _postChanges(self): 
+    values = []
+    fields = []
+    fieldString = ""
+    for field in (self._modifiedFields.keys()): 
+      fields.append(field + " = %s")
+      values.append(self._fields[field])
+    
+    statement = 'UPDATE %s SET %s WHERE %s = %s'
+    
+
 class PG_ResultSet(DBdriver.DBSIG_ResultSet): 
+  def __init__(self, cursor=None, defaultValues={}, masterRecordSet=None): 
+    
DBDriver.DBSIG_ResultSet.__init__(self,cursor,defaultValues,masterRecordSet)
+    self._recordSetClass = PG_RecordSet
+
+
+  #### NOTE:  Once PyGreSQL's .fetchone() bug is fixed, this method 
+  ####   should be deleted!  Also note the line in PG_DataSource.__init__.
+  ####   Right now, we are having to preload *ALL* rows from a datasource.
   def _loadNextRecord(self): 
     if self._cursor: 
       try: 
@@ -53,6 +70,7 @@
             self._fieldNames = []
             for t in(self._cursor.description): 
               self._fieldNames.append(t[0])
+              self._boundFields[lower[t[0]]] = ""
             GDebug.printMesg(5, "Field names set to %s" % self._fieldNames)
           if rs: 
             i = 0
@@ -60,7 +78,7 @@
             for f in(rs): 
               dict[self._fieldNames[i]] = f
               i = i + 1
-            self._cachedRecords.append(self._recordSetClass(initialData=dict))
+            
self._cachedRecords.append(self._recordSetClass(parent=self,initialData=dict))
           else:
             return 0
         return 1



reply via email to

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