Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance access to ObjectType attribute types #227

Open
Elias481 opened this issue Oct 4, 2018 · 7 comments
Open

Enhance access to ObjectType attribute types #227

Elias481 opened this issue Oct 4, 2018 · 7 comments

Comments

@Elias481
Copy link

Elias481 commented Oct 4, 2018

For general questions:

Sometimes I need the possibility to create Objects via ObjectType and populate values.
This works in case I know the attribute types. But if an attribute that is not a collection is an ObjectType itself I need to know which type is needed here and look it up separatly to be able to create an Object of that specific type. Also there is no way to check type of object attributes or collection members if they are non Object-Types.

For the first issue (get ObjectType of ObjectAttribute if applicable) it's just about making the type attribute of ObjectAttribute available.

For the second issue it would be fine if the ObjectAttribute had an additional vartype attribute (or method) to get an idea which kind of value is expected for this attribute. Same applies for the ObjectType if the ObjectType is a collection. We have (undocumented) elementType attribute here to access ObjectType for collection members but no information about expected collection members if they are not Objects themselves.

I implemented that to have it work for a specific need but would like to have something similiar implemented in official releases.
For the first shot I added some overhead to ObjectType object creation (looking up the vartype for all attributes). This could be implemented different (as methods that look up the vartype only on demand, for example).
You can find my changes at https://github.com/Elias481/python-cx_Oracle/pull/1/files to understand what I mean exactly. (The change of .gitmodules/ref to odpi is unrelated to this...)

Answer the following questions:

  1. What is your version of Python? Is it 32-bit or 64-bit?
    Different (64-bit 2.6, 2.7, 3.4 at most)

  2. What is your cx_Oracle version?
    Latest (7.0.0) / master from github

  3. What exact command caused the problem (e.g. what command did you try to install with)? Who were you logged in as?
    Trying to access type information for ObjectAttributes available from ObjectType attributes to be able to pupulate an empty Object or Attribute.

  4. What error(s) you are seeing?
    I would see something like "AttributeError: 'cx_Oracle.ObjectAttribute' object has no attribute 'type'"

  5. What OS (and version) is Python executing on?
    Linux 64 Bit (mostly Centos or Redhat 5-7)

  6. What is your version of the Oracle client (e.g. Instant Client)? How was it installed? Where is it installed?
    Different (11.2.0.4, 12.1.0.2, 18.3.0.0). Sometimes Instant-Client sometimes ORACLE_HOME client. More or less properly installed (but working if less properly installed..).

  7. What is your Oracle Database version?
    11.2.0.4, 12.1.0.2, 18.3.0.0

  8. What is the PATH environment variable (on Windows) or LD_LIBRARY_PATH (on Linux) set to? On macOS, what is in ~/lib?
    Depends... Whatever I need for the setup and what is the users/applications default...

  9. What Oracle environment variables did you set? How exactly did you set them?
    ORACLE_HOME if applicable, sometimes NLS_LANG. How exactly I set them depends...

  10. Do you have a small, single Python script that immediately runs to show us the problem?
    I could provide but does not makes much sense here...

@anthony-tuininga
Copy link
Member

Thanks. I'll take a look at implementing this. It will probably be a few weeks, though, as I have a conference to prepare for and attend!

@domingues
Copy link

Any news with this issue?

@anthony-tuininga
Copy link
Member

Sorry! I lost sight of this. I'll take a look again. Do you have the same needs as the original poster? Or did you have a different reason for wanting this enhancement?

@domingues
Copy link

My needs are similar. I'm building a code generator and currently the only way that I found to to know the type of an attribute is to look at ALL_TYPE_ATTRS table, but this only show attributes of global types. Also I can't get the element type of non Object-Types collections.

@anthony-tuininga
Copy link
Member

Thanks for letting me know. I have an idea of what can be done to implement this in a reasonable way -- and hopefully in a reasonable period of time, too -- though I can't promise anything!

@domingues
Copy link

Thanks!
Is possible to also provide the package name of the type, if any?

@LatvianPython
Copy link

Quote from original poster:

For the first issue (get ObjectType of ObjectAttribute if applicable) it's just about making the type attribute of ObjectAttribute available.

Could this be implemented in some future release?

I see that object type information is already being obtained during object attribute initialization.

attr->type = cxoObjectType_new(connection,
info.typeInfo.objectType);

I think this should be as simple as exposing it in the member declaration here:

static PyMemberDef cxoObjectAttrMembers[] = {
{ "name", T_OBJECT, offsetof(cxoObjectAttr, name), READONLY },
{ NULL }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants