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

java.sql.Connection.unwrap throws JavaException: Invalid python object for this argument #22

Closed
imd opened this issue Aug 24, 2012 · 4 comments

Comments

@imd
Copy link

imd commented Aug 24, 2012

Running this code under Jython works. Running the equivalent Java works. I'm doing it just as the docs say to. But PyJNIus prints:

Traceback (most recent call last):
  File "test.py", line 25, in <module>
    olapConnection = connection.unwrap(OlapConnection)
  File "jnius_export_class.pxi", line 487, in jnius.JavaMethod.__call__ (jnius/jnius.c:11969)
  File "jnius_conversion.pxi", line 58, in jnius.populate_args (jnius/jnius.c:4110)
jnius.JavaException: Invalid python object for this argument. Want 'java/lang/Class', got <class 'jnius.reflect.org.olap4j.OlapConnection'>

for the following code:

import sys

_is_jython = sys.platform.startswith("java")
if _is_jython:
    from java.sql import DriverManager
    from org.olap4j import OlapConnection
else:
    from jnius import autoclass
    DriverManager = autoclass('java.sql.DriverManager')
    OlapConnection = autoclass('org.olap4j.OlapConnection')


url = "jdbc:mondrian:JdbcDrivers=org.postgresql.Driver;Jdbc=jdbc:postgresql://localhost/foodmart?user=postgres&password=password;Catalog=demo/FoodMart.xml;"

mdx = '''
SELECT
  [Measures].[Customer Count] ON COLUMNS,
  [Gender].[Gender].Members ON ROWS
FROM [Sales]
'''

connection = DriverManager.getConnection(url)
olapConnection = connection.unwrap(OlapConnection)
result = olapConnection.prepareOlapStatement(mdx).executeQuery()

(To run the test code, use same setup procedure as bug #21.)

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@apalala
Copy link
Contributor

apalala commented Aug 24, 2012

#1 Jnius is not parsing the classes of objects returned from Java, and #2 it is not handling inheritance in parameter passing. Any help with those features would be appreciated.

@ghost
Copy link

ghost commented Oct 1, 2012

@imd could test this with the master version of jnius because there have been updates regarding this issue, you can install the lastest version of jnius using the following pip command if you have all the required pip libraries:

pip install git+git://github.com/kivy/pyjnius.git

Thanks.

@imd
Copy link
Author

imd commented Dec 27, 2012

I can't install that. I get the following output from pip install:

Downloading/unpacking git+git://github.com/kivy/pyjnius.git
  Cloning git://github.com/kivy/pyjnius.git to /tmp/pip-LCFF6F-build
  Running setup.py egg_info for package from git+git://github.com/kivy/pyjnius.git

Requirement already satisfied (use --upgrade to upgrade): cython in /usr/lib/pymodules/python2.7 (from jnius==1.1-dev)
Installing collected packages: jnius
  Running setup.py install for jnius
    building 'jnius' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include -I/usr/include/linux -I/usr/include/python2.7 -c jnius/jnius.c -o build/temp.linux-x86_64-2.7/jnius/jnius.o
    gcc: error: jnius/jnius.c: No such file or directory
    gcc: fatal error: no input files
    compilation terminated.
    error: command 'gcc' failed with exit status 4
    Complete output from command /home/ian/my_new_env/bin/python -c "import setuptools;__file__='/tmp/pip-LCFF6F-build/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-TOMvhq-record/install-record.txt --single-version-externally-managed --install-headers /home/ian/my_new_env/include/site/python2.7:
    running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-2.7

creating build/lib.linux-x86_64-2.7/jnius

copying jnius/reflect.py -> build/lib.linux-x86_64-2.7/jnius

copying jnius/__init__.py -> build/lib.linux-x86_64-2.7/jnius

running build_ext

building 'jnius' extension

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/jnius

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include -I/usr/include/linux -I/usr/include/python2.7 -c jnius/jnius.c -o build/temp.linux-x86_64-2.7/jnius/jnius.o

gcc: error: jnius/jnius.c: No such file or directory

gcc: fatal error: no input files

compilation terminated.

error: command 'gcc' failed with exit status 4

----------------------------------------
Command /home/ian/my_new_env/bin/python -c "import setuptools;__file__='/tmp/pip-LCFF6F-build/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-TOMvhq-record/install-record.txt --single-version-externally-managed --install-headers /home/ian/my_new_env/include/site/python2.7 failed with error code 1 in /tmp/pip-LCFF6F-build
Storing complete log in /home/ian/.pip/pip.log

@KeyWeeUsr
Copy link
Contributor

Can't reproduce and it is a foreign package. In the future assemble a minimal example for both Python and Java side, so that the error can be reproduced. You don't need to use Android at all, you just need to have Java installed on your PC and Python+PyJNIus too. Also, there were some critical issues fixed recently, so you might want to try with master branch or wait for the next release.

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

3 participants