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

afa at codespeak.net afa at codespeak.net
Tue Nov 17 22:31:36 CET 2009


Author: afa
Date: Tue Nov 17 22:31:34 2009
New Revision: 69358

Added:
   pypy/trunk/pypy/module/oracle/test/test_datetimevar.py   (contents, props changed)
Modified:
   pypy/trunk/pypy/module/oracle/interp_error.py
   pypy/trunk/pypy/module/oracle/interp_variable.py
Log:
Support of datetime.datetime in queries


Modified: pypy/trunk/pypy/module/oracle/interp_error.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/interp_error.py	(original)
+++ pypy/trunk/pypy/module/oracle/interp_error.py	Tue Nov 17 22:31:34 2009
@@ -22,6 +22,9 @@
         w_decimal = space.call(w_import, space.newlist(
             [space.wrap('decimal')]))
         self.w_DecimalType = space.getattr(w_decimal, space.wrap("Decimal"))
+        w_datetime = space.call(w_import, space.newlist(
+            [space.wrap('datetime')]))
+        self.w_DateTimeType = space.getattr(w_datetime, space.wrap("datetime"))
 
 
 def get(space): 

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	Tue Nov 17 22:31:34 2009
@@ -545,6 +545,33 @@
         dataptr = rffi.cast(roci.Ptr(roci.OCIDate), self.data)
         return transform.OracleDateToPythonDateTime(self.environment, dataptr)
 
+    def setValueProc(self, space, pos, w_value):
+        dataptr = rffi.ptradd(
+            rffi.cast(roci.Ptr(roci.OCIDate), self.data),
+            pos)
+        if space.is_true(space.isinstance(w_value, get(space).w_DateTimeType)):
+            year = space.int_w(space.getattr(w_value, space.wrap('year')))
+            month = space.int_w(space.getattr(w_value, space.wrap('month')))
+            day = space.int_w(space.getattr(w_value, space.wrap('day')))
+            hour = space.int_w(space.getattr(w_value, space.wrap('hour')))
+            minute = space.int_w(space.getattr(w_value, space.wrap('minute')))
+            second = space.int_w(space.getattr(w_value, space.wrap('second')))
+        elif space.is_true(space.isinstance(w_value, get(space).w_DateType)):
+            XXX
+        else:
+            raise OperationError(
+                space.w_TypeError,
+                space.wrap("expecting date data"))
+
+        # store a copy of the value
+        timePart = dataptr[0].c_OCIDateTime
+        rffi.setintfield(timePart, 'c_OCITimeHH', hour)
+        rffi.setintfield(timePart, 'c_OCITimeMI', minute)
+        rffi.setintfield(timePart, 'c_OCITimeSS', second)
+        rffi.setintfield(dataptr[0], 'c_OCIDateYYYY', year)
+        rffi.setintfield(dataptr[0], 'c_OCIDateMM', month)
+        rffi.setintfield(dataptr[0], 'c_OCIDateDD', day)
+
 class VT_Date(W_Variable):
     oracleType = roci.SQLT_ODT
     size = rffi.sizeof(roci.OCIDate)
@@ -707,7 +734,8 @@
 
     # XXX bool
 
-    # XXX datetime
+    if space.is_true(space.isinstance(w_value, get(space).w_DateTimeType)):
+        return VT_DateTime, 0, numElements
 
     # XXX date
 

Added: pypy/trunk/pypy/module/oracle/test/test_datetimevar.py
==============================================================================
--- (empty file)
+++ pypy/trunk/pypy/module/oracle/test/test_datetimevar.py	Tue Nov 17 22:31:34 2009
@@ -0,0 +1,12 @@
+from pypy.module.oracle.test.test_connect import OracleTestBase
+
+class AppTestDatetime(OracleTestBase):
+
+    def test_bind_date(self):
+        import datetime
+        cur = self.cnx.cursor()
+        cur.execute("select to_char(:d, 'YYYYMMDD-HH24MISS') from dual",
+                    d=datetime.datetime(2002, 12, 13, 9, 36, 15))
+        data = cur.fetchall()
+        assert data == [('20021213-093615',)]
+



More information about the Pypy-commit mailing list