Skip to content

Add support to XML type #14

@rafaelreuber

Description

@rafaelreuber

Hi,

The XML type is not supported on cx_Oracle. When I run a code like below, I get the error: AttributeError: 'cx_Oracle.OBJECT' object has no attribute 'read'

result = cursor.execute(
  """SELECT XMLElement("Date", hire_date)
  FROM hr.employees
  WHERE employee_id = 203"""
 )

for res in result:
	# The exception occours right here
	raw_xml = res[0].read()

But there are simple workaround. Just use the function GETCLOBVAL:

result = cursor.execute(
  """SELECT XMLElement("Date", hire_date).GETCLOBVAL()
  FROM hr.employees
  WHERE employee_id = 203"""
 )

for res in result:
	import xml.etree.ElementTree as ET
	xml_string = res[0].read()
	tree = ET.fromstring(xml_string)

The workaround works. But I think that would more pythonic if the cx_Oracle do this automatically:

result = cursor.execute(
  """SELECT XMLElement("Date", hire_date)
  FROM hr.employees
  WHERE employee_id = 203"""
 )

for res in result:
	xml = res[0].read()
	type(xml) # <class 'xml.etree.ElementTree.Element'>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions