[CalendarServer-changes] [7135] CalendarServer/branches/users/glyph/oracle/txdav/base/datastore/ dbapiclient.py

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


Revision: 7135
          http://trac.macosforge.org/projects/calendarserver/changeset/7135
Author:   glyph at apple.com
Date:     2011-03-07 19:03:54 -0800 (Mon, 07 Mar 2011)
Log Message:
-----------
Cursor wrapper sketch for dealing with cx_Oracle LOB semantics.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/oracle/txdav/base/datastore/dbapiclient.py

Modified: CalendarServer/branches/users/glyph/oracle/txdav/base/datastore/dbapiclient.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/txdav/base/datastore/dbapiclient.py	2011-03-08 03:03:43 UTC (rev 7134)
+++ CalendarServer/branches/users/glyph/oracle/txdav/base/datastore/dbapiclient.py	2011-03-08 03:03:54 UTC (rev 7135)
@@ -63,7 +63,41 @@
         return results
 
 
+try:
+    import cx_Oracle
+except ImportError:
+    pass
 
+
+class OracleCursorWrapper(DiagnosticCursorWrapper):
+    """
+    Wrapper for cx_Oracle DB-API connections which implements fetchall() to read
+    all CLOB objects into strings.
+    """
+
+    def fetchall(self):
+        accum = []
+        for row in self.realCursor:
+            newRow = []
+            for column in row:
+                if hasattr(column, 'read'):
+                    newRow.append(column.read())
+                else:
+                    newRow.append(column.read())
+        return accum
+
+
+    def execute(self, sql, args=()):
+        realArgs = []
+        for arg in args:
+            if isinstance(arg, (str, unicode)) and len(arg) > 1024:
+                v = self.realCursor.var(cx_Oracle.CLOB, len(arg) + 1)
+                v.setvalue(0, arg)
+            realArgs.append(v)
+        return super(OracleCursorWrapper, self).execute(sql, realArgs)
+
+
+
 class DiagnosticConnectionWrapper(object):
     """
     Diagnostic wrapper around a DB-API 2.0 connection for debugging connection
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110307/b60e9e17/attachment.html>


More information about the calendarserver-changes mailing list