commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7787 - trunk/gnue-common/src/datasources/drivers/DBSIG2


From: reinhard
Subject: [gnue] r7787 - trunk/gnue-common/src/datasources/drivers/DBSIG2
Date: Fri, 5 Aug 2005 06:01:51 -0500 (CDT)

Author: reinhard
Date: 2005-08-05 06:01:50 -0500 (Fri, 05 Aug 2005)
New Revision: 7787

Modified:
   trunk/gnue-common/src/datasources/drivers/DBSIG2/Behavior.py
Log:
Cleanup, docstrings, comments.


Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/Behavior.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/Behavior.py        
2005-08-05 10:16:07 UTC (rev 7786)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/Behavior.py        
2005-08-05 11:01:50 UTC (rev 7787)
@@ -21,6 +21,12 @@
 #
 # $Id$
 
+"""
+Generic Behavior class for DBSIG2 based database driver plugins.
+"""
+
+all = ['Behavior']
+
 from gnue.common.datasources import GSchema
 from gnue.common.datasources.drivers import Base
 
@@ -34,13 +40,18 @@
   Generic Behavior class for SQL based backends using a DBSIG2 compatible
   Python module.
 
-  @cvar _alterMultiple: boolean flag indicating wether an 'alter table'
+  As schema creation is pretty well standardized among SQL based backends and
+  schema introspection works differently for each database, this class
+  implements pretty much of the dirty work for _writeSchema_ but leaves
+  _readSchema_ completely unimplemented.
+
+  @cvar _writeableTypes_: list of GSTables-types to be handled by
+    writeSchema ().  GSTables instances of other types (ie. views) are ignored.
+  @cvar _alterMultiple_: boolean flag indicating wether an 'alter table'
     statement can contain multiple fields or not.
-  @cvar _extraPrimaryKey: boolean flag indicating wether primary keys must be
+  @cvar _extraPrimaryKey_: boolean flag indicating wether primary keys must be
     added with an extra command (ie. alter table) or not.
-  @cvar _writableTypes: list of GSTables-types to be handled by writeSchema ().
-    GSTables instances of other types (ie. views) are ignored.
-  @cvar _numbers: triple specifying rules for datatype transformation of
+  @cvar _numbers_: triple specifying rules for datatype transformation of
     numeric types. The first element is a sequence of tuples (maxlen, type). If
     the numeric field has no precision (it's a whole number) this sequence will
     be iterated in an ascending order using the first suitable (length <=
@@ -53,15 +64,14 @@
     "numeric (%(length)s,%(scale)s)".
   """
 
-  _writeableTypes  = ['table']
-  _alterMultiple   = True        # multiple fields in an alter table statement
-  _extraPrimaryKey = False
+  _writeableTypes_  = ['table']
+  _alterMultiple_   = True
+  _extraPrimaryKey_ = False
+  _numbers_         = ([], None, None)
+  _type2native_     = {'datetime': 'datetime',
+                       'time'    : 'time',
+                       'date'    : 'date'}
 
-  _numbers      = ([], None, None)
-  _type2native_ = {'datetime': 'datetime',
-                   'time'    : 'time',
-                   'date'    : 'date'}
-
   # ---------------------------------------------------------------------------
   # Generate a code sequence to match the requested schema
   # ---------------------------------------------------------------------------
@@ -88,7 +98,7 @@
     result = (prolog, main, epilog) = ([], [], [])
 
     for block in diff.findChildrenOfType ('GSTables', False, True):
-      if not block.type in self._writeableTypes:
+      if not block.type in self._writeableTypes_:
         continue
 
       for table in block.findChildrenOfType ('GSTable', False, True):
@@ -156,7 +166,7 @@
                   if f._action in ['add', 'change']]
 
       if len (fields):
-        if self._alterMultiple:
+        if self._alterMultiple_:
           fcode = self._createFields_ (table)
           code = u"ALTER TABLE %s ADD (%s)" % (table.name, ", ".join 
(fcode[1]))
           self._mergeTriple (result, (fcode [0], [code], fcode [2]))
@@ -175,7 +185,7 @@
 
       pkey = table.findChildOfType ('GSPrimaryKey')
       if pkey is not None:
-        triple = self._extraPrimaryKey and result or fcode
+        triple = self._extraPrimaryKey_ and result or fcode
         self._mergeTriple (triple, self._createPrimaryKey_ (pkey))
 
       code = u"CREATE TABLE %s (%s)" % (table.name, ", ".join (fcode [1]))
@@ -323,7 +333,7 @@
 
   def _createPrimaryKey_ (self, pkey):
     """
-    Create a code triple for the given primary key. If _extraPrimaryKey is set
+    Create a code triple for the given primary key. If _extraPrimaryKey_ is set
     to True the result's epilogue will contain an 'ALTER TABLE' statement,
     otherwise the result's body sequence will contain the constraint code.
 
@@ -338,7 +348,7 @@
 
     code = u"CONSTRAINT %s PRIMARY KEY (%s)" % (keyName, fields)
 
-    if self._extraPrimaryKey:
+    if self._extraPrimaryKey_:
       table = pkey.findParentOfType ('GSTable')
       post.append (u"ALTER TABLE %s ADD %s" % (table.name, code))
     else:
@@ -499,17 +509,17 @@
     scale  = hasattr (field, 'precision') and field.precision or 0
 
     if not scale:
-      self._numbers [0].sort ()
+      self._numbers_ [0].sort ()
 
-      for (maxlen, ftype) in self._numbers [0]:
+      for (maxlen, ftype) in self._numbers_ [0]:
         if maxlen is None:
           return ftype
 
         elif length <= maxlen:
           return ftype
 
-      if self._numbers [1]:
-        return self._numbers [1] % length
+      if self._numbers_ [1]:
+        return self._numbers_ [1] % length
 
     else:
-      return self._numbers [2] % {'length': length, 'scale': scale}
+      return self._numbers_ [2] % {'length': length, 'scale': scale}





reply via email to

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