Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. def connect_database(db_params=_db_params):
  2.     if 'java' in sys.platform.lower():
  3.         from com.ziclix.python.sql import zxJDBC, PyExtendedCursor
  4.         import inspect
  5.         zxJDBC.autocommit = 0
  6.         conn = zxJDBC.connect(
  7.                 'jdbc:postgresql://%s/%s?stringtype=unspecified' % tuple([db_params[x] for x in ('host','database')]),
  8.                 db_params['user'], db_params['password'], 'org.postgresql.Driver')
  9.         PyExtendedCursor.execute = execute_wrapper(PyExtendedCursor.execute)
  10.         PyExtendedCursor.executemany = execute_wrapper(PyExtendedCursor.executemany)
  11.     else:
  12.         import psycopg2
  13.         conn = psycopg2.connect(**db_params)
  14.     return conn
  15.  
  16. def execute_wrapper(func):
  17.     'Converts psycopg* query to zxJDBC (s/%s/?/g)'
  18.     @wraps(func)
  19.     def execute(*args, **kwargs):
  20.         if 'query' in kwargs:
  21.             kwargs['query'] = kwargs['query'].replace('%s','?')
  22.         else:
  23.             args = list(args)
  24.             args[1] = args[1].replace('%s','?')
  25.         return func(*args, **kwargs)
  26.     return execute
  27.  
  28. #################
  29.  
  30. Traceback (most recent call last):
  31.   File "<stdin>", line 1, in <module>
  32.   File "/work/quorum/analytics/db_postgres.py", line 37, in execute
  33.     return func(*args, **kwargs)
  34. java.lang.ClassCastException: org.python.core.PyNone cannot be cast to com.ziclix.python.sql.PyCursor
  35.         at com.ziclix.python.sql.CursorFunc.__call__(PyCursor.java:1020)
  36.         at org.python.core.PyObject._callextra(PyObject.java:527)
  37.         at analytics.db_postgres$py.execute$3(/work/quorum/analytics/db_postgres.py:37)
  38.         at analytics.db_postgres$py.call_function(/work/quorum/analytics/db_postgres.py)
  39.         at org.python.core.PyTableCode.call(PyTableCode.java:165)
  40.         at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
  41.         at org.python.core.PyBaseCode.call(PyBaseCode.java:157)
  42.         at org.python.core.PyFunction.__call__(PyFunction.java:338)
  43.         at org.python.core.PyMethod.__call__(PyMethod.java:139)
  44.         at org.python.pycode._pyx7.f$0(<stdin>:1)
  45.         at org.python.pycode._pyx7.call_function(<stdin>)
  46.         at org.python.core.PyTableCode.call(PyTableCode.java:165)
  47.         at org.python.core.PyCode.call(PyCode.java:18)
  48.         at org.python.core.Py.runCode(Py.java:1261)
  49.         at org.python.core.Py.exec(Py.java:1305)
  50. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement