[pypy-svn] r69646 - in pypy/trunk/pypy/module/oracle: . test
afa at codespeak.net
afa at codespeak.net
Thu Nov 26 10:45:20 CET 2009
Author: afa
Date: Thu Nov 26 10:45:19 2009
New Revision: 69646
Modified:
pypy/trunk/pypy/module/oracle/interp_object.py
pypy/trunk/pypy/module/oracle/roci.py
pypy/trunk/pypy/module/oracle/test/test_objectvar.py
Log:
Test and fix in getting OBJECT attributes
Modified: pypy/trunk/pypy/module/oracle/interp_object.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/interp_object.py (original)
+++ pypy/trunk/pypy/module/oracle/interp_object.py Thu Nov 26 10:45:19 2009
@@ -335,8 +335,9 @@
)
class W_ExternalObject(Wrappable):
- def __init__(self, ref, objectType, instance, indicator, isIndependent=True):
- self.ref = ref
+ def __init__(self, var, objectType, instance, indicator,
+ isIndependent=True):
+ self.var = var # keepalive
self.objectType = objectType
self.instance = instance
self.indicator = indicator
@@ -388,7 +389,7 @@
valueIndicator = scalarvalueindicatorptr
value = valueptr[0]
- return convertToPython(
+ return convertObject(
space, environment,
attribute.typeCode,
value, valueIndicator,
@@ -410,8 +411,8 @@
__getattr__ = interp2app(W_ExternalObject.getattr),
)
-def convertToPython(space, environment, typeCode,
- value, indicator, var, subtype):
+def convertObject(space, environment, typeCode,
+ value, indicator, var, subtype):
# null values returned as None
if rffi.cast(roci.Ptr(roci.OCIInd), indicator)[0] == roci.OCI_IND_NULL:
return space.w_None
@@ -419,18 +420,20 @@
if typeCode in (roci.OCI_TYPECODE_CHAR,
roci.OCI_TYPECODE_VARCHAR,
roci.OCI_TYPECODE_VARCHAR2):
- strValue = value
- stringValue = roci.OCIStringPtr(environment.handle, strValue)
- stringSize = roci.OCIStringPtr(environment.handle, strValue)
- return config.w_string(space, stringValue, stringSize)
+ strValue = rffi.cast(roci.Ptr(roci.OCIString), value)[0]
+ ptr = roci.OCIStringPtr(environment.handle, strValue)
+ size = roci.OCIStringSize(environment.handle, strValue)
+ return config.w_string(space, ptr, size)
elif typeCode == roci.OCI_TYPECODE_NUMBER:
return transform.OracleNumberToPythonFloat(
environment,
rffi.cast(roci.Ptr(roci.OCINumber), value))
elif typeCode == roci.OCI_TYPECODE_DATE:
- return transform.OracleDateToPythonDate(environment, value)
+ dateValue = rffi.cast(roci.Ptr(roci.OCIDate), value)
+ return transform.OracleDateToPythonDateTime(environment, dateValue)
elif typeCode == roci.OCI_TYPECODE_TIMESTAMP:
- return transform.OracleTimestampToPythonDate(environment, value)
+ dateValue = rffi.cast(roci.Ptr(roci.OCIDateTime), value)
+ return transform.OracleTimestampToPythonDate(environment, dateValue)
elif typeCode == roci.OCI_TYPECODE_OBJECT:
return space.wrap(W_ExternalObject(var, subType, value, indicator,
isIndependent=False))
@@ -483,7 +486,7 @@
if eofptr[0]:
break
- element = convertToPython(
+ element = convertObject(
space, environment,
objectType.elementTypeCode,
valueptr[0], indicatorptr[0],
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 26 10:45:19 2009
@@ -108,6 +108,7 @@
OCIDefine = rffi.VOIDP
OCIDescribe = rffi.VOIDP
OCISnapshot = rffi.VOIDP
+OCIString = rffi.VOIDP
OCIDateTime = rffi.VOIDP
OCIInterval = rffi.VOIDP
OCILobLocator = rffi.VOIDP
@@ -671,6 +672,20 @@
oratext], # buf
sword)
+# OCI String Functions
+
+OCIStringPtr = external(
+ 'OCIStringPtr',
+ [OCIEnv, # envhp
+ OCIString], # vs
+ oratext)
+
+OCIStringSize = external(
+ 'OCIStringSize',
+ [OCIEnv, # envhp
+ OCIString], # vs
+ ub4)
+
# OCI Locale Functions
OCINlsCharSetIdToName = external(
Modified: pypy/trunk/pypy/module/oracle/test/test_objectvar.py
==============================================================================
--- pypy/trunk/pypy/module/oracle/test/test_objectvar.py (original)
+++ pypy/trunk/pypy/module/oracle/test/test_objectvar.py Thu Nov 26 10:45:19 2009
@@ -2,6 +2,7 @@
class AppTestObjectVar(OracleTestBase):
def test_fetch_object(self):
+ import datetime
cur = self.cnx.cursor()
try:
cur.execute("drop table pypy_test_objtable")
@@ -44,4 +45,6 @@
assert isinstance(arrayValue, list)
assert arrayValue == [5, 10, None, 20]
assert objValue.NUMBERCOL == 1
- raises(AttributeError, getattr, objValue, 'OTHERCOL')
+ assert objValue.STRINGCOL == "someText"
+ assert objValue.DATECOL == datetime.datetime(2007, 03, 06)
+ raises(AttributeError, getattr, objValue, 'OTHER')
More information about the Pypy-commit
mailing list