Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def connect_database(db_params=_db_params):
- if 'java' in sys.platform.lower():
- from com.ziclix.python.sql import zxJDBC, PyExtendedCursor
- import inspect
- zxJDBC.autocommit = 0
- conn = zxJDBC.connect(
- 'jdbc:postgresql://%s/%s?stringtype=unspecified' % tuple([db_params[x] for x in ('host','database')]),
- db_params['user'], db_params['password'], 'org.postgresql.Driver')
- PyExtendedCursor.execute = execute_wrapper(PyExtendedCursor.execute)
- PyExtendedCursor.executemany = execute_wrapper(PyExtendedCursor.executemany)
- else:
- import psycopg2
- conn = psycopg2.connect(**db_params)
- return conn
- def execute_wrapper(func):
- 'Converts psycopg* query to zxJDBC (s/%s/?/g)'
- @wraps(func)
- def execute(*args, **kwargs):
- if 'query' in kwargs:
- kwargs['query'] = kwargs['query'].replace('%s','?')
- else:
- args = list(args)
- args[1] = args[1].replace('%s','?')
- return func(*args, **kwargs)
- return execute
- #################
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "/work/quorum/analytics/db_postgres.py", line 37, in execute
- return func(*args, **kwargs)
- java.lang.ClassCastException: org.python.core.PyNone cannot be cast to com.ziclix.python.sql.PyCursor
- at com.ziclix.python.sql.CursorFunc.__call__(PyCursor.java:1020)
- at org.python.core.PyObject._callextra(PyObject.java:527)
- at analytics.db_postgres$py.execute$3(/work/quorum/analytics/db_postgres.py:37)
- at analytics.db_postgres$py.call_function(/work/quorum/analytics/db_postgres.py)
- at org.python.core.PyTableCode.call(PyTableCode.java:165)
- at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
- at org.python.core.PyBaseCode.call(PyBaseCode.java:157)
- at org.python.core.PyFunction.__call__(PyFunction.java:338)
- at org.python.core.PyMethod.__call__(PyMethod.java:139)
- at org.python.pycode._pyx7.f$0(<stdin>:1)
- at org.python.pycode._pyx7.call_function(<stdin>)
- at org.python.core.PyTableCode.call(PyTableCode.java:165)
- at org.python.core.PyCode.call(PyCode.java:18)
- at org.python.core.Py.runCode(Py.java:1261)
- at org.python.core.Py.exec(Py.java:1305)
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement