commit-gnue
[Top][All Lists]
Advanced

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

r6394 - in trunk/gnue-common/src/schema: . scripter


From: johannes
Subject: r6394 - in trunk/gnue-common/src/schema: . scripter
Date: Sat, 25 Sep 2004 11:28:09 -0500 (CDT)

Author: johannes
Date: 2004-09-25 11:28:08 -0500 (Sat, 25 Sep 2004)
New Revision: 6394

Modified:
   trunk/gnue-common/src/schema/GSParser.py
   trunk/gnue-common/src/schema/scripter/Scripter.py
Log:
*) gnue-schema now uses column-definitions for tabledata too
*) column-definitinos can be used for key-definitions now
*) datasource-fields are now complete (not taken from the first row)


Modified: trunk/gnue-common/src/schema/GSParser.py
===================================================================
--- trunk/gnue-common/src/schema/GSParser.py    2004-09-25 14:31:01 UTC (rev 
6393)
+++ trunk/gnue-common/src/schema/GSParser.py    2004-09-25 16:28:08 UTC (rev 
6394)
@@ -255,7 +255,10 @@
             'Typecast': GTypecast.name },
           'type': {
             'Required': True,
-            'Typecast': GTypecast.name }
+            'Typecast': GTypecast.name },
+          'key': {
+            'Typecast': GTypecast.boolean,
+            'Default' : False},
           },
         'ParentTags': ('definition',)},
 

Modified: trunk/gnue-common/src/schema/scripter/Scripter.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/Scripter.py   2004-09-25 14:31:01 UTC 
(rev 6393)
+++ trunk/gnue-common/src/schema/scripter/Scripter.py   2004-09-25 16:28:08 UTC 
(rev 6394)
@@ -248,7 +248,8 @@
       sObject.walk (self.__schemaFields, defs = self.tables [-1])
 
     elif sObject._type == "GSTableData":
-      self.tabledata.append ({'name': sObject.tablename, 'rows': []})
+      self.tabledata.append ({'name': sObject.tablename, 'rows': [],
+          'defi': {'fields': [], 'key': []}})
       sObject.walk (self.__dataRows, defs = self.tabledata [-1]['rows'])
 
     return
@@ -389,7 +390,14 @@
       defs.append ({'key': [], 'fields': []})
       sObject.walk (self.__dataValues, defs [-1])
 
+    elif sObject._type == "GSColumn":
+      defi = self.tabledata [-1]['defi']
+      defi ['fields'].append (sObject.field)
 
+      if hasattr (sObject, 'key') and sObject.key:
+        defi ['key'].append (sObject.field)
+
+
   # ---------------------------------------------------------------------------
   # Iterate over all values of a row definition
   # ---------------------------------------------------------------------------
@@ -428,6 +436,11 @@
       tableKey  = None
       missing   = False
 
+      # is there a definition with keys ?
+      if len (item ['defi']['key']):
+        tableKey = item ['defi']['key']
+        continue
+
       # is a key missing or does at least one row specify a key?
       for row in rows:
         if len (row ['key']):
@@ -493,7 +506,7 @@
     """
 
     print _("Updating data ...")
-      
+
     for table in self.tabledata:
       tablename = table ['name']
       rows      = table ['rows']
@@ -501,26 +514,16 @@
       if not len (rows):
         continue
 
-      attributes = {'name'    : "dts_%s" % tablename,
-                    'database': self.OPTIONS ['connection'],
-                    'table'   : tablename}
+      (datasource, keyFields) = self.__openSource (table)
 
-      fieldList = [field ['name'] for field in rows [0]['fields']]
-
-      datasource = GDataSource.DataSourceWrapper (
-          connections = self.connections,
-          attributes  = attributes,
-          fields      = fieldList,
-          unicodeMode = True)
-
       print o (u_("  updating table '%s' ...") % tablename)
       updCount = 0
       insCount = 0
 
-      for row in rows:
+      for row in table ['rows']:
         cList = ['and']
 
-        for keyField in row ['key']:
+        for keyField in keyFields:
           for field in row ['fields']:
             if field ['name'] == keyField:
               kvalue = field ['value']
@@ -544,9 +547,6 @@
         for field in row ['fields']:
           fieldName  = field ['name']
           fieldValue = field ['value']
-          gDebug (4, "Field %s: old %s" % (fieldName,
-                            resultSet.current.getField (fieldName)))
-          gDebug (4, "Field %s: new %s" % (fieldName, fieldValue))
 
           if resultSet.current.getField (fieldName) != fieldValue:
             resultSet.current.setField (fieldName, fieldValue)
@@ -560,7 +560,33 @@
                % (insCount, updCount))
 
 
+  # ---------------------------------------------------------------------------
+  # Prepare a datasource
+  # ---------------------------------------------------------------------------
 
+  def __openSource (self, table):
+    fieldList = table ['defi']['fields']
+    keyFields = table ['defi']['key']
+
+    for row in table ['rows']:
+      for field in [f ['name'] for f in row ['fields']]:
+        if not field in fieldList:
+          fieldList.append (field)
+
+      for field in row ['key']:
+        if not field in keyFields:
+          keyFields.append (field)
+
+    source = GDataSource.DataSourceWrapper (connections = self.connections,
+        attributes = {'name'    : "dts_%s" % table ['name'],
+                      'database': self.OPTIONS ['connection'],
+                      'table'   : table ['name']},
+        fields      = fieldList,
+        unicodeMode = True)
+
+    return (source, keyFields)
+
+
 # =============================================================================
 # If executed directly, start the scripter
 # =============================================================================





reply via email to

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