[CalendarServer-changes] [4662] CalendarServer/branches/users/wsanchez/deployment-4548-fb-rollback/ twistedcaldav/index.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Oct 29 10:56:20 PDT 2009
Revision: 4662
http://trac.macosforge.org/projects/calendarserver/changeset/4662
Author: cdaboo at apple.com
Date: 2009-10-29 10:56:19 -0700 (Thu, 29 Oct 2009)
Log Message:
-----------
All version == "8" to be treated as a valid version for the index.
Modified Paths:
--------------
CalendarServer/branches/users/wsanchez/deployment-4548-fb-rollback/twistedcaldav/index.py
Modified: CalendarServer/branches/users/wsanchez/deployment-4548-fb-rollback/twistedcaldav/index.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment-4548-fb-rollback/twistedcaldav/index.py 2009-10-29 17:48:33 UTC (rev 4661)
+++ CalendarServer/branches/users/wsanchez/deployment-4548-fb-rollback/twistedcaldav/index.py 2009-10-29 17:56:19 UTC (rev 4662)
@@ -288,6 +288,79 @@
% (name, self.resource))
self.deleteResource(name)
+ def _db(self):
+ """
+ Access the underlying database.
+ @return: a db2 connection object for this index's underlying data store.
+ """
+ if not hasattr(self, "_db_connection"):
+ db_filename = self.dbpath
+ try:
+ if self.autocommit:
+ self._db_connection = sqlite.connect(db_filename, isolation_level=None)
+ else:
+ self._db_connection = sqlite.connect(db_filename)
+ except:
+ log.err("Unable to open database: %s" % (self,))
+ raise
+
+ #
+ # Set up the schema
+ #
+ q = self._db_connection.cursor()
+ try:
+ # Create CALDAV table if needed
+
+ if self._test_schema_table(q):
+ q.execute(
+ """
+ select VALUE from CALDAV
+ where KEY = 'SCHEMA_VERSION'
+ """)
+ version = q.fetchone()
+
+ if version is not None: version = version[0]
+
+ q.execute(
+ """
+ select VALUE from CALDAV
+ where KEY = 'TYPE'
+ """)
+ type = q.fetchone()
+
+ if type is not None: type = type[0]
+
+ if (version != self._db_version()) and (version != "8") or (type != self._db_type()):
+
+ # Clean-up first
+ q.close()
+ q = None
+ self._db_connection.close()
+ del(self._db_connection)
+
+ if version != self._db_version():
+ log.err("Database %s has different schema (v.%s vs. v.%s)"
+ % (db_filename, version, self._db_version()))
+
+ # Upgrade the DB
+ return self._db_upgrade(version)
+
+ if type != self._db_type():
+ log.err("Database %s has different type (%s vs. %s)"
+ % (db_filename, type, self._db_type()))
+
+ # Delete this index and start over
+ os.remove(db_filename)
+ return self._db()
+
+ else:
+ self._db_init(db_filename, q)
+
+ self._db_connection.commit()
+ finally:
+ if q is not None: q.close()
+ return self._db_connection
+
def _db_version(self):
"""
@return: the schema version assigned to this index.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091029/19b20de7/attachment.html>
More information about the calendarserver-changes
mailing list