Advertisement
Guest User

Untitled

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