commit-gnue
[Top][All Lists]
Advanced

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

r5614 - in trunk/gnue-common/src/schema: . scripter scripter/processors


From: johannes
Subject: r5614 - in trunk/gnue-common/src/schema: . scripter scripter/processors
Date: Fri, 2 Apr 2004 04:53:55 -0600 (CST)

Author: johannes
Date: 2004-04-02 04:53:54 -0600 (Fri, 02 Apr 2004)
New Revision: 5614

Modified:
   trunk/gnue-common/src/schema/GSParser.py
   trunk/gnue-common/src/schema/scripter/Definition.py
   trunk/gnue-common/src/schema/scripter/Scripter.py
   trunk/gnue-common/src/schema/scripter/processors/Base.py
   trunk/gnue-common/src/schema/scripter/processors/HTML.py
   trunk/gnue-common/src/schema/scripter/processors/SQL.py
   trunk/gnue-common/src/schema/scripter/processors/interbase.py
   trunk/gnue-common/src/schema/scripter/processors/mssql.py
   trunk/gnue-common/src/schema/scripter/processors/mysql.py
   trunk/gnue-common/src/schema/scripter/processors/oracle.py
   trunk/gnue-common/src/schema/scripter/processors/postgresql.py
Log:
Added 'action' attribute to <table>-tags, which could be 'create' or 'extend'.
Constraints are now created using ALTER TABLE statements, so order of table
definitions no longer matter.


Modified: trunk/gnue-common/src/schema/GSParser.py
===================================================================
--- trunk/gnue-common/src/schema/GSParser.py    2004-04-02 09:45:55 UTC (rev 
5613)
+++ trunk/gnue-common/src/schema/GSParser.py    2004-04-02 10:53:54 UTC (rev 
5614)
@@ -100,7 +100,13 @@
                'Unique': 1,
                'Typecast': GTypecast.name },
             'description': {
-               'Typecast': GTypecast.text } },
+               'Typecast': GTypecast.text },
+            'action': {
+               'Typecast': GTypecast.text,
+               'ValueSet': {
+                  'create': {},
+                  'extend': {} },
+               'Default': 'create' }},
          'ParentTags':  ('tables',) },
 
       'fields':  {

Modified: trunk/gnue-common/src/schema/scripter/Definition.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/Definition.py 2004-04-02 09:45:55 UTC 
(rev 5613)
+++ trunk/gnue-common/src/schema/scripter/Definition.py 2004-04-02 10:53:54 UTC 
(rev 5614)
@@ -21,11 +21,10 @@
 # $Id$
 #
 
-from types import StringType
-
 # =============================================================================
 # The basic definition class
 # =============================================================================
+
 class Definition:
   """
   This class implements a basic definition. Each definition has a name, and a
@@ -37,6 +36,7 @@
   # ---------------------------------------------------------------------------
   # Constructor
   # ---------------------------------------------------------------------------
+
   def __init__ (self, name = None):
     self.name     = name
 
@@ -50,6 +50,7 @@
   # ---------------------------------------------------------------------------
   # Return all sequences as one single list 
   # ---------------------------------------------------------------------------
+
   def merge (self):
     """
     This function merges all sequences into a single list
@@ -60,6 +61,7 @@
   # ---------------------------------------------------------------------------
   # Dump a definition to a given destination
   # ---------------------------------------------------------------------------
+
   def writeDefinition (self, destination, encoding = "UTF-8"):
     """
     This method writes all sequences to the given destination using 'encoding',
@@ -74,15 +76,16 @@
 # =============================================================================
 # Basic class for schema definitions
 # =============================================================================
+
 class SchemaDefinition (Definition):
   """
   This class introduces another sequence "fields" to the definition. This list
   holds GSField/GSIndexField instances.
   """
-
   # ---------------------------------------------------------------------------
   # Constructor
   # ---------------------------------------------------------------------------
+
   def __init__ (self, name = None):
     Definition.__init__ (self, name)
     self.fields = []
@@ -90,44 +93,72 @@
 
 
 # =============================================================================
-# IndexDefinition is just basic at the moment
+# IndexDefinition introduces unique-flag
 # =============================================================================
+
 class IndexDefinition (SchemaDefinition):
   """
   This class has another public property 'unique', which describes wether a
   given index has the unique-flag set or not.
   """
-
   # ---------------------------------------------------------------------------
   # Constructor
   # ---------------------------------------------------------------------------
+
   def __init__ (self, name = None, unique = False):
     SchemaDefinition.__init__ (self, name)
     self.unique = unique
 
 
+# =============================================================================
+# Constraint definition
+# =============================================================================
 
+class ConstraintDefinition (SchemaDefinition):
+  """
+  This class implements reference-constraints
+  """
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+  def __init__ (self, name = None, kind = None):
+    SchemaDefinition.__init__ (self, name)
+
+    self.kind      = kind
+    self.reftable  = None
+    self.reffields = []
+
+
 # =============================================================================
-# TableDefinition adds postfield- and index- sequences
+# PhaseDefinition
 # =============================================================================
-class TableDefinition (SchemaDefinition):
+
+class PhaseDefinition (Definition):
+
+  def __init__ (self, name = None, phase = 0):
+    Definition.__init__ (self, name)
+    self.phase = phase
+
+
+# =============================================================================
+# TableDefinition 
+# =============================================================================
+class TableDefinition:
   """
-  A TableDefinition introduces another property primaryKey which is an
-  IndexDefinition, and two dictionaries indices and constraints. The first one 
-  'indices' holds all IndexDefinitions for the table (except the primary key), 
-  and 'constraints' is allways empty, since constraints are NOT implemented by
-  now.
   """
 
   # ---------------------------------------------------------------------------
   # Constructor
   # ---------------------------------------------------------------------------
-  def __init__ (self, name = None):
-    SchemaDefinition.__init__ (self, name)
+  def __init__ (self, name = None, action = 'create'):
+    self.name        = name
+    self.action      = action
+    self.fields      = []
+    self.primaryKey  = None
+    self.indices     = {}
+    self.constraints = {}
 
-    self.primaryKey = None
-    self.indices    = {}
-    self.constraints= {}
+    self.phases      = {}
 
 
   # ---------------------------------------------------------------------------
@@ -184,19 +215,20 @@
 
     return None
 
-# =============================================================================
-# Constraint definition
-# =============================================================================
 
-class ConstraintDefinition (SchemaDefinition):
-  """
-  """
-  def __init__ (self, name = None, kind = None):
-    SchemaDefinition.__init__ (self, name)
-    self.kind      = kind
-    self.reftable  = None
-    self.reffields = []
+  # ---------------------------------------------------------------------------
+  # Add a given phasedefinition and return it
+  # ---------------------------------------------------------------------------
 
+  def getPhase (self, phase):
+    """
+    This function returns the PhaseDefinition instance of @phase; if it's not
+    defined it will be created
+    """
+    if not self.phases.has_key (phase):
+      self.phases [phase] = PhaseDefinition (self.name, phase)
+      
+    return self.phases [phase]
 
 
 # =============================================================================
@@ -215,7 +247,8 @@
   def __init__ (self, name = None):
     Definition.__init__ (self, name)
 
-    self.rows  = []
+    self.rows     = []
+    self.tableDef = None
 
   # ---------------------------------------------------------------------------
   # Add a new row to the collection

Modified: trunk/gnue-common/src/schema/scripter/Scripter.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/Scripter.py   2004-04-02 09:45:55 UTC 
(rev 5613)
+++ trunk/gnue-common/src/schema/scripter/Scripter.py   2004-04-02 10:53:54 UTC 
(rev 5614)
@@ -232,12 +232,24 @@
 
     try:
       self.tables = {}
+      self.data   = {}
 
       self.processor.startDump ()
       self.processor.client_encoding (self.OPTIONS ['encoding'])
 
       self.schema.walk (self.__iterate_objects)
 
+      maxPhase = 0
+      for table in self.tables.values ():
+        maxPhase = max (maxPhase, max (table.phases.keys ()))
+
+      for phase in range (0, maxPhase + 1):
+        for table in self.tables.values ():
+          self.processor.writePhase (table, phase)
+
+      for table in self.data.values ():
+        self.processor.writeData (table, table.tableDef)
+
       self.processor.finishDump ()
 
       # and finally close the output file
@@ -278,11 +290,11 @@
   # Process the schema definition of a GSTable object
   # ---------------------------------------------------------------------------
   def __schema_table (self, sObject):
-    aTable = TableDefinition (sObject.name)
+    aTable = TableDefinition (sObject.name, sObject.action)
     self.tables [aTable.name] = aTable
     sObject.walk (self.__schema_fields, tableDef = aTable)
 
-    self.processor.writeTable (aTable)
+    self.processor.translateTableDefinition (aTable)
 
 
   # ---------------------------------------------------------------------------
@@ -355,17 +367,16 @@
   def __data_table (self, sObject):
     data = DataDefinition (sObject.tablename)
 
+    self.data [data.name] = data
+    if self.tables.has_key (data.name):
+      data.tableDef = self.tables [data.name]
+
     sObject.walk (self.__data_rows, dataDef = data)
 
-    if self.tables.has_key (data.name):
-      tableDef = self.tables [data.name]
-    else:
-      tableDef = None
+    # self.processor.writeData (data, data.tableDef)
 
-    self.processor.writeData (data, tableDef)
 
 
-
   # ---------------------------------------------------------------------------
   # Iterate over all rows of a tabledata definition
   # ---------------------------------------------------------------------------

Modified: trunk/gnue-common/src/schema/scripter/processors/Base.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/Base.py    2004-04-02 
09:45:55 UTC (rev 5613)
+++ trunk/gnue-common/src/schema/scripter/processors/Base.py    2004-04-02 
10:53:54 UTC (rev 5614)
@@ -20,36 +20,22 @@
 #
 # $Id$
 
-from string import join
-from types import ListType, StringType
+import string
+import types
 from mx.DateTime import now
 
 # =============================================================================
 # Exceptions
 # =============================================================================
 
-class EProcessorError (Exception):
+class ProcessorError (gException):
   """
   This is the base exception class for all processor related exceptions.
   """
+  pass
 
-  # ---------------------------------------------------------------------------
-  # Constructor
-  # ---------------------------------------------------------------------------
 
-  def __init__ (self, text):
-    self._text = text
-    Exception.__init__ (self, self._text)
 
-
-  # ---------------------------------------------------------------------------
-  # Instance representation
-  # ---------------------------------------------------------------------------
-
-  def __repr__ (self):
-    return self._text
-
-
 # =============================================================================
 # Base class for GNUe Schema Definition processors
 # =============================================================================
@@ -73,6 +59,7 @@
   END_BATCH          = ""       # Symbol used to terminate a command-sequence
 
   QUOTE_CHAR         = ""
+  ALTER_MULTIPLE     = True     # ALTER TABLE can handle multiple fields
 
 
   # ---------------------------------------------------------------------------
@@ -134,8 +121,8 @@
     encoding. If text is a sequence it will be joined with newlines first.
     """
 
-    if isinstance (text, ListType):
-      astr = join (text, "\n") + u"\n"
+    if isinstance (text, types.ListType):
+      astr = string.join (text, "\n") + u"\n"
     else:
       astr = text
 
@@ -264,10 +251,10 @@
 
 
   # ---------------------------------------------------------------------------
-  # Write a table definition to the destination
+  # Translate a table-definition into it's phase instances
   # ---------------------------------------------------------------------------
 
-  def writeTable (self, tableDef):
+  def translateTableDefinition (self, tableDef):
     """
     This function calls all _process*-functions on the given table definition
     and finally writes the definition to the destination.
@@ -275,7 +262,7 @@
     # Process all parts of the table definition
     self._processFields (tableDef)
 
-    if tableDef.primaryKey is not None:
+    if tableDef.action == 'create' and tableDef.primaryKey is not None:
       self._processPrimaryKey (tableDef)
 
     if len (tableDef.indices.keys ()):
@@ -285,11 +272,18 @@
       self._processConstraints (tableDef)
 
     if len (self.END_BATCH):
-      tableDef.epilogue.append (self.END_BATCH)
+      for phase in tableDef.phases.values ():
+        phase.epilogue.append (self.END_BATCH)
 
-    # and finally write the definition to the destination
-    tableDef.writeDefinition (self.destination, self.encoding)
 
+  # ---------------------------------------------------------------------------
+  # write a phase definition to the destination if it exists
+  # ---------------------------------------------------------------------------
+  def writePhase (self, tableDef, phase):
+    """
+    """
+    if tableDef.phases.has_key (phase):
+      tableDef.phases [phase].writeDefinition (self.destination, self.encoding)
 
 
   # ===========================================================================
@@ -387,7 +381,7 @@
     ruler = u"=" * (self.MAX_LINE_LENGTH - len (self.COMMENT_BEGIN) - \
                                            len (self.COMMENT_END))
     body.append (ruler)
-    if isinstance (text, ListType):
+    if isinstance (text, types.ListType):
       body.extend (text)
     else:
       body.extend (text.split ("\n"))

Modified: trunk/gnue-common/src/schema/scripter/processors/HTML.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/HTML.py    2004-04-02 
09:45:55 UTC (rev 5613)
+++ trunk/gnue-common/src/schema/scripter/processors/HTML.py    2004-04-02 
10:53:54 UTC (rev 5614)
@@ -58,8 +58,8 @@
   # ---------------------------------------------------------------------------
 
   def _processFields (self, tableDef):
-    pro = tableDef.prologue
-    hdr = tableDef.header
+    pro = tableDef.getPhase (0).prologue
+    hdr = tableDef.getPhase (0).header
 
     pro.append ("")
     pro.extend (self.comment ("Table definition '%s'" % tableDef.name))
@@ -72,7 +72,7 @@
                 'cellpadding="3" cellspacing="1">')
     hdr.extend (self._tableHeader ())
 
-    tableDef.footer.append ('</TABLE>')
+    tableDef.getPhase (0).footer.append ('</TABLE>')
 
     BaseProcessor._processFields (self, tableDef)
 
@@ -82,7 +82,7 @@
   # ---------------------------------------------------------------------------
 
   def _processField (self, tableDef, gsField, isLast):
-    tableDef.body.extend (self._fieldRow (gsField))
+    tableDef.getPhase (0).body.extend (self._fieldRow (gsField))
 
 
   # ---------------------------------------------------------------------------
@@ -93,7 +93,7 @@
     pkDef = tableDef.primaryKey
     flist = join ([pkf.name for pkf in pkDef.fields], ", ")
 
-    epi = tableDef.epilogue
+    epi = tableDef.getPhase (0).epilogue
 
     epi.append ("")
     epi.extend (self.comment ("Primary key '%s'" % pkDef.name))
@@ -117,7 +117,7 @@
     else:
       uniq = _("Index")
 
-    epi = tableDef.epilogue
+    epi = tableDef.getPhase (0).epilogue
 
     epi.append ("")
     epi.extend (self.comment ("Index '%s'" % indexDef.name))
@@ -133,7 +133,7 @@
   # ---------------------------------------------------------------------------
 
   def _processConstraint (self, tableDef, constraint):
-    epi = tableDef.epilogue
+    epi = tableDef.getPhase (0).epilogue
 
     epi.append ("")
     epi.extend (self.comment ("Constraint '%s'" % constraint.name))
@@ -265,6 +265,9 @@
     self._writeText (['</HEAD>', '<BODY>'])
 
 
+  def writePhase (self, tableDef, phase):
+    pass
+
   # ---------------------------------------------------------------------------
   # stop the dump
   # ---------------------------------------------------------------------------
@@ -287,7 +290,8 @@
     self._writeText ('</UL>\n')
 
     for table in self.__tables:
-      table.writeDefinition (self.destination, self.encoding)
+      # table.writeDefinition (self.destination, self.encoding)
+      BaseProcessor.writePhase (self, table, 0)
       self._writeText ('<HR>')
 
     self._writeText (['<P>%s %s UTC</P>' % (_("Generated on"), now ())])
@@ -298,7 +302,7 @@
   # write a table definition
   # ---------------------------------------------------------------------------
 
-  def writeTable (self, tableDef):
+  def translateTableDefinition (self, tableDef):
     """
     This function call all _process* () functions on the table definition given
     and adds the processed definition to the internal list of tables.
@@ -314,9 +318,6 @@
     if len (tableDef.constraints.keys ()):
       self._processConstraints (tableDef)
 
-    if len (self.END_BATCH):
-      tableDef.epilogue.append (self.END_BATCH)
-
     # Note: we won't write the table definition right now, but append it to the
     # list of tables. We would let stopDump () do the write out instead.
     self.__tables.append (tableDef)

Modified: trunk/gnue-common/src/schema/scripter/processors/SQL.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/SQL.py     2004-04-02 
09:45:55 UTC (rev 5613)
+++ trunk/gnue-common/src/schema/scripter/processors/SQL.py     2004-04-02 
10:53:54 UTC (rev 5614)
@@ -49,18 +49,49 @@
     """
     Populate a table definitions sequences.
     """
-    tableDef.prologue.append (u"")
-    tableDef.prologue.extend (self.comment ("Create table '%s'" % \
+    phase = tableDef.getPhase (0)
+
+    if tableDef.action == 'create':
+      phase.prologue.append (u"")
+      phase.prologue.extend (self.comment ("Create table '%s'" % \
                                             tableDef.name))
+      phase.body.append (u"CREATE TABLE %s (" % tableDef.name)
+      phase.footer.append (u")%s" % self.END_COMMAND)
 
-    tableDef.body.append (u"CREATE TABLE %s (" % tableDef.name)
-    tableDef.footer.append (u")%s" % self.END_COMMAND)
+      BaseProcessor._processFields (self, tableDef)
+    else:
+      phase.prologue.append (u"")
+      phase.prologue.extend (self.comment ("Alter table '%s'" % \
+                                            tableDef.name))
+      
+      if self.ALTER_MULTIPLE:
+        self._alterMultiple (tableDef)
+      else:
+        self._alterSingle (tableDef)
 
+
+  # ---------------------------------------------------------------------------
+  #
+  # ---------------------------------------------------------------------------
+
+  def _alterMultiple (self, tableDef):
+    phase = tableDef.getPhase (0)
+    phase.body.append (u"ALTER TABLE %s ADD (" % tableDef.name)
+    phase.footer.append (u")%s" % self.END_COMMAND)
+
     BaseProcessor._processFields (self, tableDef)
 
 
+  def _alterSingle (self, tableDef):
+    phase = tableDef.getPhase (0)
 
+    for field in tableDef.fields:
+      phase.body.append (u"ALTER TABLE %s ADD " % tableDef.name)
+      self._processField (tableDef, field, True)
+      phase.body.append ("%s" % self.END_COMMAND)
+    
 
+
   # ---------------------------------------------------------------------------
   # A single field is usually added to the definitions body
   # ---------------------------------------------------------------------------
@@ -75,7 +106,7 @@
     if not isLast:
       field += ", "
 
-    tableDef.body.append (field)
+    tableDef.getPhase (0).body.append (field)
 
 
   # ---------------------------------------------------------------------------
@@ -90,11 +121,12 @@
     pkDef = tableDef.primaryKey
     flist = join ([pkf.name for pkf in pkDef.fields], ", ")
 
-    if len (tableDef.body):
-      tableDef.body [-1] += u","
+    phase = tableDef.getPhase (0)
+    if len (phase.body):
+      phase.body [-1] += u","
 
-    tableDef.body.append (u"  CONSTRAINT %s PRIMARY KEY (%s)" % \
-                              (pkDef.name, flist))
+    phase.body.append (u"  CONSTRAINT %s PRIMARY KEY (%s)" % \
+                        (pkDef.name, flist))
 
 
   # ---------------------------------------------------------------------------
@@ -109,7 +141,7 @@
     BaseProcessor._processIndices (self, tableDef)
 
     for index in tableDef.indices.values ():
-      tableDef.epilogue.extend (index.merge ())
+      tableDef.getPhase (0).epilogue.extend (index.merge ())
 
 
   # ---------------------------------------------------------------------------
@@ -145,17 +177,22 @@
 
   def _processConstraint (self, tableDef, constraint):
     """
-    This function processes a foreign key constraint.
+    This function processes a foreign key constraint; these type of constraints
+    are put into the second phase.
     """
     if constraint.kind == "foreignkey":
-      if len (tableDef.body) and tableDef.body [-1].strip () [-1] != ",":
-        tableDef.body [-1] += u","
+      phase = tableDef.getPhase (1)
 
-      tableDef.body.append ("  CONSTRAINT %s FOREIGN KEY (%s)" % \
+      phase.body.append (u"")
+      phase.body.extend (self.comment ("CONSTRAINT '%s'" % constraint.name))
+      phase.body.append ("ALTER TABLE %s ADD" % tableDef.name)
+
+      phase.body.append ("  CONSTRAINT %s FOREIGN KEY (%s)" % \
         (constraint.name, join ([cf.name for cf in constraint.fields], ", ")))
-      tableDef.body.append ("    REFERENCES %s (%s)" % \
-        (constraint.reftable, join ([rf.name for rf in constraint.reffields],
-                                    ", ")))
+      phase.body.append ("    REFERENCES %s (%s)%s" % \
+        (constraint.reftable, 
+         join ([rf.name for rf in constraint.reffields], ", "), 
+         self.END_COMMAND))
 
 
 

Modified: trunk/gnue-common/src/schema/scripter/processors/interbase.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/interbase.py       
2004-04-02 09:45:55 UTC (rev 5613)
+++ trunk/gnue-common/src/schema/scripter/processors/interbase.py       
2004-04-02 10:53:54 UTC (rev 5614)
@@ -43,10 +43,11 @@
   # ---------------------------------------------------------------------------
   def _processField (self, tableDef, gsField, isLast):
     field = "  %s" % self._qualify (gsField)
+    phase = tableDef.getPhase (0)
 
     if gsField.defaultwith == "serial":
       gen = self._getSequenceName (tableDef.name, gsField)
-      tableDef.header.append ("CREATE GENERATOR %s%s" % (gen, 
self.END_COMMAND))
+      phase.header.append ("CREATE GENERATOR %s%s" % (gen, self.END_COMMAND))
 
       self.__addTrigger (tableDef, gsField, gen)
 
@@ -62,14 +63,14 @@
     if not isLast:
       field += ", "
 
-    tableDef.body.append (field)
+    phase.body.append (field)
 
 
   # ---------------------------------------------------------------------------
   # Add a generator trigger to the table definition
   # ---------------------------------------------------------------------------
   def __addTrigger (self, tableDef, gsField, gen):
-    epi = tableDef.epilogue
+    epi = tableDef.getPhase (0).epilogue
     epi.append ("")
     epi.append ("SET TERM ^ ;")
     epi.append ("CREATE TRIGGER trg_%s FOR %s" % (gsField.name, tableDef.name))

Modified: trunk/gnue-common/src/schema/scripter/processors/mssql.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/mssql.py   2004-04-02 
09:45:55 UTC (rev 5613)
+++ trunk/gnue-common/src/schema/scripter/processors/mssql.py   2004-04-02 
10:53:54 UTC (rev 5614)
@@ -58,7 +58,7 @@
     if not isLast:
       field += ","
 
-    tableDef.body.append (field)
+    tableDef.getPhase (0).body.append (field)
 
 
   # ===========================================================================

Modified: trunk/gnue-common/src/schema/scripter/processors/mysql.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/mysql.py   2004-04-02 
09:45:55 UTC (rev 5613)
+++ trunk/gnue-common/src/schema/scripter/processors/mysql.py   2004-04-02 
10:53:54 UTC (rev 5614)
@@ -22,7 +22,6 @@
 #
 
 from gnue.common.schema.scripter.processors.SQL import SQLProcessor
-from gnue.common.schema.scripter.processors.Base import EProcessorError
 
 name        = "MySQL"
 description = "MySQL (3.x/4.x)"
@@ -64,7 +63,7 @@
     if not isLast:
       field += ","
 
-    tableDef.body.append (field)
+    tableDef.getPhase (0).body.append (field)
 
 
 

Modified: trunk/gnue-common/src/schema/scripter/processors/oracle.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/oracle.py  2004-04-02 
09:45:55 UTC (rev 5613)
+++ trunk/gnue-common/src/schema/scripter/processors/oracle.py  2004-04-02 
10:53:54 UTC (rev 5614)
@@ -42,13 +42,14 @@
   # ---------------------------------------------------------------------------
   def _processField (self, tableDef, gsField, isLast):
     field = "  %s" % self._qualify (gsField)
+    phase = tableDef.getPhase (0)
 
     # Add a 'serial' as default value
     if gsField.defaultwith == "serial":
       seq = self._getSequenceName (tableDef.name, gsField)
 
-      tableDef.prologue.append ("CREATE SEQUENCE %s MAXVALUE %s NOCYCLE%s" % \
-                         (seq, "9" * self._PK_PRECISION, self.END_COMMAND))
+      phase.prologue.append ("CREATE SEQUENCE %s MAXVALUE %s NOCYCLE%s" % \
+                            (seq, "9" * self._PK_PRECISION, self.END_COMMAND))
       trig = []
       trig.append ("   IF :new.%s IS NULL THEN" % gsField.name)
       trig.append ("      SELECT %s.nextval INTO :new.%s FROM dual;" % \
@@ -81,14 +82,14 @@
     if not isLast:
       field += ","
 
-    tableDef.body.append (field)
+    phase.body.append (field)
 
 
   # ---------------------------------------------------------------------------
   # Add a trigger for defaults to the table definition
   # ---------------------------------------------------------------------------
   def __addTrigger (self, tableDef, gsField, body):
-    epi = tableDef.epilogue
+    epi = tableDef.getPhase (0).epilogue
 
     epi.append ("")
     epi.append ("CREATE OR REPLACE TRIGGER t__%s_%s_pre" % (tableDef.name,

Modified: trunk/gnue-common/src/schema/scripter/processors/postgresql.py
===================================================================
--- trunk/gnue-common/src/schema/scripter/processors/postgresql.py      
2004-04-02 09:45:55 UTC (rev 5613)
+++ trunk/gnue-common/src/schema/scripter/processors/postgresql.py      
2004-04-02 10:53:54 UTC (rev 5614)
@@ -36,6 +36,7 @@
 
   MAX_NAME_LENGTH = 31
   ESCAPECHAR      = '\\'
+  ALTER_MULTIPLE  = False
 
 
   # ---------------------------------------------------------------------------
@@ -49,7 +50,7 @@
     if gsField.defaultwith == "serial":
       seq = self._getSequenceName (tableDef.name, gsField)
 
-      tableDef.header.append ("CREATE SEQUENCE %s;" % seq)
+      tableDef.getPhase (0).header.append ("CREATE SEQUENCE %s;" % seq)
       field += " DEFAULT nextval ('%s')" % seq
 
     elif gsField.defaultwith == "timestamp":
@@ -64,7 +65,7 @@
     if not isLast:
       field += ", "
 
-    tableDef.body.append (field)
+    tableDef.getPhase (0).body.append (field)
 
 
   # ===========================================================================





reply via email to

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