Skip to main content
Solved

python FMEUniversalReader open Oralce table

  • Oct 14, 2014 3:17 AM UTC
  • 3 replies
  • 71 views

Hi,

 

 

I am trying to open an Oracle table using FME through python but I seem to

 

be missing something. readSchema() keeps complaining:

 

'The tables which are to be used for translation must be specified'

 

 

This is the code:

 

 

import fmeobjects

 

  reader = fmeobjects.FMEUniversalReader('ORACLE8i',False) 

 

  parameters = ['SERVER_TYPE','ORACLE8i'

 

                          ,'USER_NAME','<username>'

 

                          ,'PASSWORD','<password>'

 

                          ,'WORKSPACE', 'LIVE'                       

 

                          ,'TABLELIST','<schema>.<tablename>']

 

  reader.open('<TNS_Name>',parameters)

 

  schema = reader.readSchema()

 

 

Thank you for your time!

 

Sirko

Best answer by david_r

Hi,

 

 

I recommend you do something like this:

 

 

sourceFormat, sourceDataset, directives = fmeobjects.FMEDialog().sourcePrompt('', '', [])

 

print sourceFormat

 

print sourceDataset

 

print directives

 

 

This way you can use the interactive GUI dialog to construct your parameters and copy/paste them into your code. It's a lot easier to get something going this way.

 

 

David
View original
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.

3 replies

david_r
Celebrity
  • Best Answer
  • Oct 14, 2014 6:57 AM UTC
Hi,

 

 

I recommend you do something like this:

 

 

sourceFormat, sourceDataset, directives = fmeobjects.FMEDialog().sourcePrompt('', '', [])

 

print sourceFormat

 

print sourceDataset

 

print directives

 

 

This way you can use the interactive GUI dialog to construct your parameters and copy/paste them into your code. It's a lot easier to get something going this way.

 

 

David

  • Author
  • Oct 14, 2014 11:57 PM UTC
Hi David,

 

 

Thank you for your response.

 

 

foo = dialog.sourcePrompt("ORACLE8i",'<TNS_Name>',parameters)

 

 

Using dialog.sourcePrompt()  was how I started to begin with. The key - value pairs I added to the parameters are derived from it but unfortunately I am still not getting any different results.

 

 

reader.readSchema() still fails like above and reader.read() returns nothing.

 

 

It would be great if someone could post an example or a link other than

 

http://docs.safe.com/fme/html/FME_Objects_Python_API/index.html to do some RTFM.

 

 

Cheers,

 

Sirko

 


  • Author
  • Oct 15, 2014 1:57 AM UTC
OK my bad David was right, after I passed the directives to fmeobjects.FMEUniversalReader()

 

things went as expected so I went and did this:

 

 

def get_oracle_directive(self,layer):

 

 

        oracle_macros = {'SERVER_TYPE':'ORACLE8i','USER_NAME':self.ORACLE_USER,'PASSWORD':self.ORACLE_PASSWORD

 

                         ,'WORKSPACE':'','PERSISTENT_CONNECTION':'YES','SHOW_SYSTEM_TABLES':'NO'

 

                         ,'REMOVE_SCHEMA_QUALIFIER':'NO','READ_3D_POLYGON_AS_FACE':'NO','TABLELIST':layer

 

                         ,'WHERE_CLAUSE':'','PARSE_MAPINFO_SYMBOLOGY':'NO','MAPINFO_SYMBOLOGY_STYLE_COLUMN':''

 

                         ,'MAPINFO_SYMBOLOGY_INDEX_COLUMN':'','EXPOSE_ATTRS_GROUP':'','ORACLE8I_EXPOSE_FORMAT_ATTRS':''

 

                         ,'USE_SEARCH_ENVELOPE':'NO','SEARCH_ENVELOPE_MINX':'0','SEARCH_ENVELOPE_MINY':'0'

 

                         ,'SEARCH_ENVELOPE_MAXX':'0','SEARCH_ENVELOPE_MAXY':'0','CLIP_TO_ENVELOPE':'NO',

 

                         }

 

       

 

        directives = []

 

        directives.append('ORACLE8I')

 

        directives.append(self.ORACLE_TNS_NAME)

 

        directives.append('RUNTIME_MACROS')

 

        runtime_marcos = ''

 

        for o in oracle_macros:

 

            runtime_marcos = runtime_marcos + o + ',' + oracle_macros[o] + ','           

 

        runtime_marcos = runtime_marcos +'_MERGE_SCHEMAS,YES'       

 

        directives.append(runtime_marcos)

 

        directives.append('META_MACROS')

 

        meta_macros = ''

 

        for o in oracle_macros:

 

            meta_macros = meta_macros + 'Source' + o + ',' + oracle_macros[o] + ','

 

        meta_macros = re.sub(',$','',meta_macros)

 

        directives.append(meta_macros)

 

        directives.append('METAFILE')

 

        directives.append('ORACLE8I')

 

        directives.append('COORDSYS')

 

        directives.append('')

 

        directives.append('IDLIST')

 

        directives.append(layer)

 

 

        return directives