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

afa at codespeak.net afa at codespeak.net
Wed Nov 18 20:07:08 CET 2009


Author: afa
Date: Wed Nov 18 20:07:07 2009
New Revision: 69394

Modified:
   pypy/trunk/pypy/module/oracle/__init__.py
   pypy/trunk/pypy/module/oracle/config.py
   pypy/trunk/pypy/module/oracle/interp_variable.py
   pypy/trunk/pypy/module/oracle/test/test_stringvar.py
Log:
Implement BINARY datatype


Modified: pypy/trunk/pypy/module/oracle/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/__init__.py	(original)
+++ pypy/trunk/pypy/module/oracle/__init__.py	Wed Nov 18 20:07:07 2009
@@ -9,6 +9,7 @@
         'NUMBER': 'interp_variable.VT_Float',
         'STRING': 'interp_variable.VT_String',
         'DATETIME': 'interp_variable.VT_DateTime',
+        'BINARY': 'interp_variable.VT_Binary',
         'Variable': 'interp_variable.W_Variable',
     }
 

Modified: pypy/trunk/pypy/module/oracle/config.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/config.py	(original)
+++ pypy/trunk/pypy/module/oracle/config.py	Wed Nov 18 20:07:07 2009
@@ -3,6 +3,7 @@
 WITH_UNICODE = False
 
 MAX_STRING_CHARS = 4000
+MAX_BINARY_BYTES = 4000
 
 if WITH_UNICODE:
     CHARSETID = roci.OCI_UTF16ID

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	Wed Nov 18 20:07:07 2009
@@ -149,7 +149,7 @@
         # allocate the indicator for the variable
         self.indicator = lltype.malloc(rffi.CArrayPtr(roci.sb2).TO,
                                        self.allocatedElements,
-                                       flavor='raw', zero=True) # XXX
+                                       flavor='raw', zero=True)
 
         # ensure that all variable values start out NULL
         for i in range(self.allocatedElements):
@@ -159,7 +159,7 @@
         if self.isVariableLength:
             self.returnCode = lltype.malloc(rffi.CArrayPtr(roci.ub2).TO,
                                             self.allocatedElements,
-                                            flavor='raw', zero=True) # XXX
+                                            flavor='raw', zero=True)
 
         # perform extended initialization
         self.initialize(cursor)
@@ -170,6 +170,8 @@
             lltype.free(self.actualLength, flavor='raw')
         if self.data:
             lltype.free(self.data, flavor='raw')
+        if self.returnCode:
+            lltype.free(self.returnCode, flavor='raw')
 
     def getBufferSize(self):
         return self.size
@@ -490,8 +492,9 @@
     size = 18
     isVariableLength = False
 
-class VT_Binary(W_Variable):
-    pass
+class VT_Binary(VT_String):
+    oracleType = roci.SQLT_BIN
+    size = config.MAX_BINARY_BYTES
 
 class VT_LongBinary(W_Variable):
     pass

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	Wed Nov 18 20:07:07 2009
@@ -4,7 +4,6 @@
 
     def test_rowid(self):
         cur = self.cnx.cursor()
-        var = cur.var(oracle.NUMBER)
         cur.execute("select rowid from dual")
         rowid, = cur.fetchone()
         cur.execute("select * from dual where rowid = :r",
@@ -92,3 +91,18 @@
         assert tablelen.getvalue() == 20
         # dbms_utility.comma_to_table returns a 'NULL-terminated' table
         assert arrayvar.getvalue() == array + [None]
+
+    def test_binary(self):
+        cur = self.cnx.cursor()
+        try:
+            cur.execute("drop table pypy_temp_table")
+        except oracle.DatabaseError:
+            pass
+        cur.execute("create table pypy_temp_table (rawcol raw(30))")
+
+        cur.setinputsizes(p=oracle.BINARY)
+        cur.execute("insert into pypy_temp_table values (:p)",
+                    p="raw string")
+        cur.execute("select * from pypy_temp_table")
+        data = cur.fetchall()
+        assert data == [("raw string",)]



More information about the Pypy-commit mailing list