[CalendarServer-changes] [7132] CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 7 19:03:17 PST 2011


Revision: 7132
          http://trac.macosforge.org/projects/calendarserver/changeset/7132
Author:   glyph at apple.com
Date:     2011-03-07 19:03:17 -0800 (Mon, 07 Mar 2011)
Log Message:
-----------
parse multi-column primary keys properly.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/parseschema.py
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_parseschema.py

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/parseschema.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/parseschema.py	2011-03-08 03:03:06 UTC (rev 7131)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/parseschema.py	2011-03-08 03:03:17 UTC (rev 7132)
@@ -215,6 +215,20 @@
             return self.parseConstraint(maybeIdent)
 
 
+    def namesInParens(self, parens):
+        parens = iterSignificant(parens)
+        expect(parens, ttype=Punctuation, value="(")
+        idorids = parens.next()
+        if isinstance(idorids, Identifier):
+            idnames = [idorids.get_name()]
+        elif isinstance(idorids, IdentifierList):
+            idnames = [x.get_name() for x in idorids.get_identifiers()]
+        else:
+            raise ViolatedExpectation("identifier or list", repr(idorids))
+        expect(parens, ttype=Punctuation, value=")")
+        return idnames
+
+
     def parseConstraint(self, constraintType):
         """
         Parse a 'free' constraint, described explicitly in the table as opposed
@@ -223,20 +237,12 @@
         # only know about PRIMARY KEY and UNIQUE for now
         if constraintType.match(Keyword, 'PRIMARY'):
             expect(self, ttype=Keyword, value='KEY')
-            expect(self, cls=Parenthesis)
-            self.primaryKey = 'MULTI-VALUE-KEY'
+            names = self.namesInParens(expect(self, cls=Parenthesis))
+            self.table.primaryKey = tuple(self.table.columnNamed(n)
+                                          for n in names)
         elif constraintType.match(Keyword, 'UNIQUE'):
-            parens = iterSignificant(expect(self, cls=Parenthesis))
-            expect(parens, ttype=Punctuation, value="(")
-            idorids = parens.next()
-            if isinstance(idorids, Identifier):
-                idnames = [idorids.get_name()]
-            elif isinstance(idorids, IdentifierList):
-                idnames = [x.get_name() for x in idorids.get_identifiers()]
-            else:
-                raise ViolatedExpectation("identifier or list", repr(idorids))
-            expect(parens, ttype=Punctuation, value=")")
-            self.table.tableConstraint(Constraint.UNIQUE, idnames)
+            names = self.namesInParens(expect(self, cls=Parenthesis))
+            self.table.tableConstraint(Constraint.UNIQUE, names)
         else:
             raise ViolatedExpectation('PRIMARY or UNIQUE', constraintType)
         return self.checkEnd(self.next())

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_parseschema.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_parseschema.py	2011-03-08 03:03:06 UTC (rev 7131)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_parseschema.py	2011-03-08 03:03:17 UTC (rev 7132)
@@ -215,3 +215,16 @@
                           [set([b, c]), set([c])])
 
 
+    def test_multiPrimaryKey(self):
+        """
+        A table with a multi-column PRIMARY KEY clause will be parsed as a tuple
+        primaryKey attribute on the Table object.
+        """
+        s = Schema()
+        addSQLToSchema(
+            s, "create table a (b integer, c integer, primary key(b, c))")
+        a = s.tableNamed("a")
+        self.assertEquals(a.primaryKey,
+                          (a.columnNamed("b"), a.columnNamed("c")))
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110307/6dc8ce58/attachment.html>


More information about the calendarserver-changes mailing list