[CalendarServer-changes] [5101] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 12 13:26:48 PST 2010


Revision: 5101
          http://trac.macosforge.org/projects/calendarserver/changeset/5101
Author:   cdaboo at apple.com
Date:     2010-02-12 13:26:48 -0800 (Fri, 12 Feb 2010)
Log Message:
-----------
Index creation differs from one SQL server to another.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/database.py
    CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py

Modified: CalendarServer/trunk/twistedcaldav/database.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/database.py	2010-02-12 21:24:12 UTC (rev 5100)
+++ CalendarServer/trunk/twistedcaldav/database.py	2010-02-12 21:26:48 UTC (rev 5101)
@@ -408,6 +408,9 @@
     def _test_table(self, name):
         raise NotImplementedError
 
+    def _create_index(self, name, ontable, columns, ifnotexists=False):
+        raise NotImplementedError
+
     def _prepare_statement(self, sql):
         raise NotImplementedError
         
@@ -453,6 +456,17 @@
         """ % (name,)))
         returnValue(result)
 
+    @inlineCallbacks
+    def _create_index(self, name, ontable, columns, ifnotexists=False):
+        
+        statement = "create index %s%s on %s (%s)" % (
+            "if not exists " if ifnotexists else "",
+            name,
+            ontable,
+            ", ".join(columns),
+        )
+        yield self._db_execute(statement)
+
     def _prepare_statement(self, sql):
         # We are going to use the sqlite syntax of :1, :2 etc for our
         # internal statements so we do not need to remap those
@@ -512,6 +526,26 @@
             returnValue(result)
     
         @inlineCallbacks
+        def _create_index(self, name, ontable, columns, ifnotexists=False):
+            
+            statement = "create index %s on %s (%s)" % (
+                name,
+                ontable,
+                ", ".join(columns),
+            )
+            
+            try:
+                yield self._db_execute(statement)
+            except pgdb.DatabaseError:
+                
+                if not ifnotexists:
+                    raise
+                
+                result = (yield self._test_table(name))
+                if not result:
+                    raise 
+    
+        @inlineCallbacks
         def _db_init_schema_table(self):
             """
             Initialise the underlying database tables.

Modified: CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py	2010-02-12 21:24:12 UTC (rev 5100)
+++ CalendarServer/trunk/twistedcaldav/directory/calendaruserproxy.py	2010-02-12 21:26:48 UTC (rev 5101)
@@ -719,15 +719,17 @@
             ifnotexists=True,
         )
 
-        yield self._db_execute(
-            """
-            create index if not exists GROUPNAMES on GROUPS (GROUPNAME)
-            """
+        yield self._create_index(
+            "GROUPNAMES",
+            "GROUPS",
+            ("GROUPNAME",),
+            ifnotexists=True,
         )
-        yield self._db_execute(
-            """
-            create index if not exists MEMBERS on GROUPS (MEMBER)
-            """
+        yield self._create_index(
+            "MEMBERS",
+            "GROUPS",
+            ("MEMBER",),
+            ifnotexists=True,
         )
 
     @inlineCallbacks
@@ -740,15 +742,17 @@
 
         # Add index if old version is less than "4"
         if int(old_version) < 4:
-            yield self._db_execute(
-                """
-                create index if not exists GROUPNAMES on GROUPS (GROUPNAME)
-                """
+            yield self._create_index(
+                "GROUPNAMES",
+                "GROUPS",
+                ("GROUPNAME",),
+                ifnotexists=True,
             )
-            yield self._db_execute(
-                """
-                create index if not exists MEMBERS on GROUPS (MEMBER)
-                """
+            yield self._create_index(
+                "MEMBERS",
+                "GROUPS",
+                ("MEMBER",),
+                ifnotexists=True,
             )
 
     def _db_empty_data_tables(self):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100212/811ddde5/attachment.html>


More information about the calendarserver-changes mailing list