[CalendarServer-changes] [7860] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 8 18:19:54 PDT 2011


Revision: 7860
          http://trac.macosforge.org/projects/calendarserver/changeset/7860
Author:   glyph at apple.com
Date:     2011-08-08 18:19:54 -0700 (Mon, 08 Aug 2011)
Log Message:
-----------
truncate names in emitted statements as well, so the tables can be used

Modified Paths:
--------------
    CalendarServer/trunk/twext/enterprise/dal/syntax.py
    CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
    CalendarServer/trunk/twext/enterprise/ienterprise.py
    CalendarServer/trunk/txdav/common/datastore/sql_tables.py

Modified: CalendarServer/trunk/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/syntax.py	2011-08-09 01:19:42 UTC (rev 7859)
+++ CalendarServer/trunk/twext/enterprise/dal/syntax.py	2011-08-09 01:19:54 UTC (rev 7860)
@@ -443,6 +443,17 @@
 
 
 
+def _nameForDialect(name, dialect):
+    """
+    If the given name is being computed in the oracle dialect, truncate it to 30
+    characters.
+    """
+    if dialect == ORACLE_DIALECT:
+        name = name[:30]
+    return name
+
+
+
 class TableSyntax(Syntax):
     """
     Syntactic convenience for L{Table}.
@@ -462,7 +473,7 @@
         """
         # XXX maybe there should be a specific method which is only invoked
         # from the FROM clause, that only tables and joins would implement?
-        return SQLFragment(self.model.name)
+        return SQLFragment(_nameForDialect(self.model.name, metadata.dialect))
 
 
     def __getattr__(self, attr):

Modified: CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py	2011-08-09 01:19:42 UTC (rev 7859)
+++ CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py	2011-08-09 01:19:54 UTC (rev 7860)
@@ -1069,3 +1069,27 @@
             )
         )
 
+
+    def test_oracleTableTruncation(self):
+        """
+        L{Table}'s SQL generation logic will truncate table names if the dialect
+        (i.e. Oracle) demands it.  (See txdav.common.datastore.sql_tables for
+        the schema translator and enforcement of name uniqueness in the derived
+        schema.)
+        """
+
+        addSQLToSchema(
+            self.schema.model,
+            "create table veryveryveryveryveryveryveryverylong "
+            "(foo integer);"
+        )
+        vvl = self.schema.veryveryveryveryveryveryveryverylong
+        self.assertEquals(
+            Insert({vvl.foo: 1}).toSQL(FixedPlaceholder(ORACLE_DIALECT, "?")),
+            SQLFragment(
+                "insert into veryveryveryveryveryveryveryve (foo) values "
+                "(?)", [1]
+            )
+        )
+
+

Modified: CalendarServer/trunk/twext/enterprise/ienterprise.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/ienterprise.py	2011-08-09 01:19:42 UTC (rev 7859)
+++ CalendarServer/trunk/twext/enterprise/ienterprise.py	2011-08-09 01:19:54 UTC (rev 7860)
@@ -42,6 +42,7 @@
 
 POSTGRES_DIALECT = 'postgres-dialect'
 ORACLE_DIALECT = 'oracle-dialect'
+ORACLE_TABLE_NAME_MAX = 30
 
 
 

Modified: CalendarServer/trunk/txdav/common/datastore/sql_tables.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_tables.py	2011-08-09 01:19:42 UTC (rev 7859)
+++ CalendarServer/trunk/txdav/common/datastore/sql_tables.py	2011-08-09 01:19:54 UTC (rev 7860)
@@ -26,6 +26,7 @@
 from twext.enterprise.dal.syntax import FixedPlaceholder
 from twext.enterprise.ienterprise import ORACLE_DIALECT
 from twext.enterprise.dal.syntax import Insert
+from twext.enterprise.ienterprise import ORACLE_TABLE_NAME_MAX
 from twext.enterprise.dal.parseschema import schemaFromPath
 
 
@@ -222,7 +223,7 @@
         # The only table name which actually exceeds the length limit right now
         # is CALENDAR_OBJECT_ATTACHMENTS_MODE, which isn't actually _used_
         # anywhere, so we can fake it for now.
-        shortName = table.model.name[:30]
+        shortName = table.model.name[:ORACLE_TABLE_NAME_MAX]
         if shortName in shortNames:
             raise SchemaBroken("short-name conflict between %s and %s" %
                                (table.model.name, shortNames[shortName]))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110808/e49d147b/attachment.html>


More information about the calendarserver-changes mailing list