Convert object type handling to use new cxString functions and add test case

to ensure that it was done correctly.
This commit is contained in:
Anthony Tuininga 2008-10-16 03:25:30 +00:00
parent bef9439b3e
commit d50847e92b
4 changed files with 35 additions and 10 deletions

View File

@ -256,19 +256,18 @@ static PyObject *ExternalObjectVar_GetAttributeValue(
{
dvoid *valueIndicator, *value;
OCIInd scalarValueIndicator;
ub4 nameLength;
udt_StringBuffer buffer;
sword status;
OCIType *tdo;
char *name;
// get the value for the attribute
name = PyString_AS_STRING(attribute->name);
nameLength = PyString_GET_SIZE(attribute->name);
if (StringBuffer_Fill(&buffer, attribute->name) < 0)
return NULL;
status = OCIObjectGetAttr(self->objectType->environment->handle,
self->objectType->environment->errorHandle, self->instance,
self->indicator, self->objectType->tdo, (const OraText**) &name,
&nameLength, 1, 0, 0, &scalarValueIndicator, &valueIndicator,
&value, &tdo);
self->indicator, self->objectType->tdo,
(const OraText**) &buffer.ptr, (ub4*) &buffer.size, 1, 0, 0,
&scalarValueIndicator, &valueIndicator, &value, &tdo);
if (Environment_CheckForError(self->objectType->environment, status,
"ExternalObjectVar_GetAttributeValue(): getting value") < 0)
return NULL;

View File

@ -295,7 +295,7 @@ static int ObjectType_Initialize(
if (Environment_CheckForError(self->environment, status,
"ObjectType_Initialize(): get schema name") < 0)
return -1;
self->schema = PyString_FromStringAndSize(name, size);
self->schema = cxString_FromEncodedString(name, size);
if (!self->schema)
return -1;
@ -305,7 +305,7 @@ static int ObjectType_Initialize(
if (Environment_CheckForError(self->environment, status,
"ObjectType_Initialize(): get name") < 0)
return -1;
self->name = PyString_FromStringAndSize(name, size);
self->name = cxString_FromEncodedString(name, size);
if (!self->name)
return -1;
@ -433,7 +433,7 @@ static int ObjectAttribute_Initialize(
if (Environment_CheckForError(connection->environment, status,
"ObjectAttribute_Initialize(): get name") < 0)
return -1;
self->name = PyString_FromStringAndSize(name, size);
self->name = cxString_FromEncodedString(name, size);
if (!self->name)
return -1;

View File

@ -38,3 +38,16 @@ class TestObjectVar(BaseTestCase):
cx_Oracle.Timestamp(2007, 6, 21, 0, 0, 0),
cx_Oracle.Timestamp(2007, 12, 13, 7, 30, 45)), None)
def testObjectType(self):
"test object type data"
self.cursor.execute("""
select ObjectCol
from TestObjects
where ObjectCol is not null
and rownum <= 1""")
objValue, = self.cursor.fetchone()
self.failUnlessEqual(objValue.type.schema,
self.connection.username.upper())
self.failUnlessEqual(objValue.type.name, "UDT_OBJECT")
self.failUnlessEqual(objValue.type.attributes[0].name, "NUMBERVALUE")

View File

@ -38,3 +38,16 @@ class TestObjectVar(BaseTestCase):
cx_Oracle.Timestamp(2007, 6, 21, 0, 0, 0),
cx_Oracle.Timestamp(2007, 12, 13, 7, 30, 45)), None)
def testObjectType(self):
"test object type data"
self.cursor.execute(u"""
select ObjectCol
from TestObjects
where ObjectCol is not null
and rownum <= 1""")
objValue, = self.cursor.fetchone()
self.failUnlessEqual(objValue.type.schema,
self.connection.username.upper())
self.failUnlessEqual(objValue.type.name, u"UDT_OBJECT")
self.failUnlessEqual(objValue.type.attributes[0].name, "NUMBERVALUE")