Skip to main content
Solved

Reading Blobs from Oracle

  • October 21, 2019
  • 4 replies
  • 157 views

oliver.morris
Contributor
Forum|alt.badge.img+14

Hi, 

Is there a way to read an oracle blob file within FME. I know the structure and can read with python, is it possible to do something with FME? Is it possible at least to read in the blob with FME then use a python caller to extract using the struct library?

Many Thanks as always,

Oliver

cursor.execute("SELECT BLOB_DATA,DATATYPE,BYTES_USED,BLK_NO FROM {}.GEO_SHAPE WHERE VID={}".format(xxx,19971))
ORACLErow = cursor.fetchall()
for row in ORACLErow:
    print row
    print struct.unpack('>d',row[0].read(1,8))[0]
    print struct.unpack('>d',row[0].read(9,8))[0]
    print struct.unpack('>d',row[0].read(17,8))[0]
    print struct.unpack('25s',row[0].read(25,25))[0]
    print struct.unpack('>i',row[0].read(50,4))[0]

 

 

 

Best answer by daveatsafe

Hi @olivermorris,

FME will read the Oracle blob fields as binary attributes on the row feature. You can then use a PythonCaller to interpret them. Use FMEFeature.getAttribute() to read the attribute in Python.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

daveatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • Best Answer
  • October 21, 2019

Hi @olivermorris,

FME will read the Oracle blob fields as binary attributes on the row feature. You can then use a PythonCaller to interpret them. Use FMEFeature.getAttribute() to read the attribute in Python.


oliver.morris
Contributor
Forum|alt.badge.img+14
  • Author
  • Contributor
  • October 22, 2019

Hi @olivermorris,

FME will read the Oracle blob fields as binary attributes on the row feature. You can then use a PythonCaller to interpret them. Use FMEFeature.getAttribute() to read the attribute in Python.

Thank you, I have tried this and get an issue with my python:

import fme
import fmeobjects
import struct

def geo1(feature):
    myrow = feature.getAttribute('BLOB_DATA')
    ##xcoord = str(myrow)
    xcoord = struct.unpack('>d',myrow.read(1,8))[0]
    feature.setAttribute("xcoord",xcoord)

I get the error

2019-10-22 16:38:34|   0.5|  0.2|ERROR |Python Exception <AttributeError>: 'bytes' object has no attribute 'read'

yet this does work in python idle. Any ideas?

Thank you


oliver.morris
Contributor
Forum|alt.badge.img+14
  • Author
  • Contributor
  • October 22, 2019

Thank you, I have tried this and get an issue with my python:

import fme
import fmeobjects
import struct

def geo1(feature):
    myrow = feature.getAttribute('BLOB_DATA')
    ##xcoord = str(myrow)
    xcoord = struct.unpack('>d',myrow.read(1,8))[0]
    feature.setAttribute("xcoord",xcoord)

I get the error

2019-10-22 16:38:34|   0.5|  0.2|ERROR |Python Exception <AttributeError>: 'bytes' object has no attribute 'read'

yet this does work in python idle. Any ideas?

Thank you

I now get: byte indices must be integers or slices, not tuple


daveatsafe
Safer
Forum|alt.badge.img+20
  • Safer
  • October 22, 2019

I now get: byte indices must be integers or slices, not tuple

Hi @olivermorris,

According to the FMEObjects Python docs:

Binary blob attributes are returned as a bytearray in Python 2.7 or bytes in Python 3.

I think this is OK for struct in 3, but 2.7 you may need to use the workaround discussed in https://codereview.stackexchange.com/questions/37959/struct-unpack-on-a-bytearray-that-works-under-python-2-6-6-2-7-and-3-3.