<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[2264] CalendarServer/branches/users/cdaboo/mysql-2262/twistedcaldav/sql.py</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.macosforge.org/projects/calendarserver/changeset/2264">2264</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2008-03-31 07:03:03 -0700 (Mon, 31 Mar 2008)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow choice of DB-API driver.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserscdaboomysql2262twistedcaldavsqlpy">CalendarServer/branches/users/cdaboo/mysql-2262/twistedcaldav/sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserscdaboomysql2262twistedcaldavsqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/mysql-2262/twistedcaldav/sql.py (2263 => 2264)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/mysql-2262/twistedcaldav/sql.py        2008-03-28 16:51:37 UTC (rev 2263)
+++ CalendarServer/branches/users/cdaboo/mysql-2262/twistedcaldav/sql.py        2008-03-31 14:03:03 UTC (rev 2264)
</span><span class="lines">@@ -29,6 +29,8 @@
</span><span class="cx"> except ImportError:
</span><span class="cx">     from pysqlite2 import dbapi2 as sqlite
</span><span class="cx"> 
</span><ins>+import MySQLdb
+
</ins><span class="cx"> from twisted.python import log
</span><span class="cx"> 
</span><span class="cx"> db_prefix = &quot;.db.&quot;
</span><span class="lines">@@ -38,7 +40,7 @@
</span><span class="cx">     A generic SQL database.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    def __init__(self, dbpath, persistent, autocommit=False):
</del><ins>+    def __init__(self, dbpath, persistent, autocommit=False, driver=&quot;sqlite&quot;):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         
</span><span class="cx">         @param dbpath: the path where the db file is stored.
</span><span class="lines">@@ -48,10 +50,17 @@
</span><span class="cx">         @type persistent: bool
</span><span class="cx">         @param autocommit: C{True} if auto-commit mode is desired, C{False} otherwise
</span><span class="cx">         @type autocommit: bool
</span><ins>+        @param driver: name of the database driver to use
+        @type driver: C{str}
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self.dbpath = dbpath
</span><span class="cx">         self.persistent = persistent
</span><span class="cx">         self.autocommit = autocommit
</span><ins>+        
+        self.driver = driver
+        self.dbdriver = {&quot;sqlite&quot;: sqlite, &quot;mysql&quot;: MySQLdb}.get(self.driver, None)
+        if self.dbdriver is None:
+            raise ValueError(&quot;SQl driver type: %s is not supported.&quot; % (driver,))
</ins><span class="cx"> 
</span><span class="cx">     def _db_version(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -74,9 +83,9 @@
</span><span class="cx">             db_filename = self.dbpath
</span><span class="cx">             try:
</span><span class="cx">                 if self.autocommit:
</span><del>-                    self._db_connection = sqlite.connect(db_filename, isolation_level=None)
</del><ins>+                    self._db_connection = self.dbdriver.connect(db_filename, isolation_level=None)
</ins><span class="cx">                 else:
</span><del>-                    self._db_connection = sqlite.connect(db_filename)
</del><ins>+                    self._db_connection = self.dbdriver.connect(db_filename)
</ins><span class="cx">             except:
</span><span class="cx">                 log.err(&quot;Unable to open database: %s&quot; % (db_filename,))
</span><span class="cx">                 raise
</span><span class="lines">@@ -220,7 +229,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         
</span><span class="cx">         if self.persistent:
</span><del>-            self._db_connection = sqlite.connect(self.dbpath, isolation_level=None)
</del><ins>+            self._db_connection = self.dbdriver.connect(self.dbpath, isolation_level=None)
</ins><span class="cx">             q = self._db_connection.cursor()
</span><span class="cx">             self._db_upgrade_data_tables(q, old_version)
</span><span class="cx">             self._db_upgrade_schema(q)
</span></span></pre>
</div>
</div>

</body>
</html>