[pypy-svn] r69405 - in pypy/trunk/pypy/module/oracle: . test

afa at codespeak.net afa at codespeak.net
Thu Nov 19 00:34:07 CET 2009


Author: afa
Date: Thu Nov 19 00:34:06 2009
New Revision: 69405

Modified:
   pypy/trunk/pypy/module/oracle/interp_variable.py
   pypy/trunk/pypy/module/oracle/roci.py
   pypy/trunk/pypy/module/oracle/test/test_stringvar.py
Log:
start supporting long strings


Modified: pypy/trunk/pypy/module/oracle/interp_variable.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/interp_variable.py	(original)
+++ pypy/trunk/pypy/module/oracle/interp_variable.py	Thu Nov 19 00:34:06 2009
@@ -482,7 +482,26 @@
     pass
 
 class VT_LongString(W_Variable):
-    pass
+    oracleType = roci.SQLT_LVC
+    isVariableLength = True
+    size = 128 * 1024
+
+    def setValueProc(self, space, pos, w_value):
+        buf = config.StringBuffer()
+        buf.fill(space, w_value)
+
+        try:
+            # ensure that the buffer is large enough
+            if buf.size + rffi.sizeof(roci.ub4) > self.bufferSize:
+                self.resize(buf.size + rffi.sizeof(roci.ub4))
+
+            # copy the string to the Oracle buffer
+            data = rffi.ptradd(self.data, pos * self.bufferSize)
+            rffi.cast(roci.Ptr(roci.ub4), data)[0] = rffi.cast(roci.ub4, buf.size)
+            for index in range(buf.size):
+                data[index + rffi.sizeof(roci.ub4)] = buf.ptr[index]
+        finally:
+            buf.clear()
 
 class VT_FixedNationalChar(W_Variable):
     pass
@@ -496,7 +515,7 @@
     oracleType = roci.SQLT_BIN
     size = config.MAX_BINARY_BYTES
 
-class VT_LongBinary(W_Variable):
+class VT_LongBinary(VT_LongString):
     pass
 
 class VT_NativeFloat(W_Variable):
@@ -872,7 +891,10 @@
 
     if space.is_true(space.isinstance(w_value, space.w_str)):
         size = space.int_w(space.len(w_value))
-        return VT_String, size, numElements
+        if size > config.MAX_STRING_CHARS:
+            return VT_LongString, size, numElements
+        else:
+            return VT_String, size, numElements
 
     # XXX Unicode
 

Modified: pypy/trunk/pypy/module/oracle/roci.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/roci.py	(original)
+++ pypy/trunk/pypy/module/oracle/roci.py	Thu Nov 19 00:34:06 2009
@@ -62,7 +62,7 @@
     OCI_IND_NULL OCI_IND_NOTNULL
     OCI_STMT_SELECT OCI_STMT_CREATE OCI_STMT_DROP OCI_STMT_ALTER
     OCI_STMT_INSERT OCI_STMT_DELETE OCI_STMT_UPDATE
-    SQLT_CHR SQLT_LNG SQLT_AFC SQLT_RDD SQLT_BIN SQLT_LBI
+    SQLT_CHR SQLT_LNG SQLT_AFC SQLT_RDD SQLT_BIN SQLT_LBI SQLT_LVC
     SQLT_BFLOAT SQLT_IBFLOAT SQLT_BDOUBLE SQLT_IBDOUBLE
     SQLT_NUM SQLT_VNU SQLT_DAT SQLT_ODT SQLT_DATE SQLT_TIMESTAMP
     SQLT_TIMESTAMP_TZ SQLT_TIMESTAMP_LTZ SQLT_INTERVAL_DS

Modified: pypy/trunk/pypy/module/oracle/test/test_stringvar.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/test/test_stringvar.py	(original)
+++ pypy/trunk/pypy/module/oracle/test/test_stringvar.py	Thu Nov 19 00:34:06 2009
@@ -106,3 +106,14 @@
         cur.execute("select * from pypy_temp_table")
         data = cur.fetchall()
         assert data == [("raw string",)]
+
+    def test_longstring(self):
+        cur = self.cnx.cursor()
+        cur.execute("""
+            declare
+              t_Temp varchar2(10000);
+            begin
+              t_Temp := :bigString;
+            end;""",
+            bigString="X" * 10000)
+



More information about the Pypy-commit mailing list