无论如何有使用烧瓶sqlalchemy连接到denodo数据库?

时间:2020-06-21 03:05:01

标签: sqlalchemy flask-sqlalchemy denodo

我目前能够使用我编译并与pyodbc一起使用的denodo驱动程序连接到denodo数据库,并且如果我直接使用psycopg2,我还可以连接并查询表。但是,如果可以利用Sqlalchemy的ORM,那将是理想的选择。该驱动程序基于postgresql,但是当前sqlalchemy不支持方言和DBAPI的组合。这导致我尝试使用指向我编译的驱动程序的方言mysql + pyodbc以及尝试psycopg2。

我应该提到我的意图是仅对数据库中的一个表执行SELECT语句。

使用mysql + pyodbc时出现错误:

numpy-recarray

使用postgres + psycopg2时,出现以下异常:

qlalchemy.engine.base.Engine.DENODO-READER b"SHOW VARIABLES LIKE 'character_set%%'"
2020-06-21 02:56:52,972 INFO sqlalchemy.engine.base.Engine.DENODO-READER ()
[2020-06-21 02:56:52 +0000] [8] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/decomm_reader/wsgi.py", line 5, in <module>
    APP = create_app()
  File "/home/decomm_reader/app/__init__.py", line 33, in create_app
    DB.metadata.reflect(bind=DB.engine)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/sql/schema.py", line 4356, in reflect
    with bind.connect() as conn:
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 2272, in connect
    return self._connection_cls(self, **kwargs)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 104, in __init__
    else engine.raw_connection()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 2379, in raw_connection
    self.pool.unique_connection, _connection
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 2345, in _wrap_pool_connect
    return fn()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/pool/base.py", line 304, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/pool/base.py", line 495, in checkout
    rec = pool._do_get()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get
    self._dec_overflow()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
    exc_value, with_traceback=exc_tb,
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get
    return self._create_connection()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/pool/base.py", line 440, in __init__
    self.__connect(first_connect_check=True)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/pool/base.py", line 666, in __connect
    ).exec_once_unless_exception(self.connection, self)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/event/attr.py", line 314, in exec_once_unless_exception
    self._exec_once_impl(True, *args, **kw)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/event/attr.py", line 285, in _exec_once_impl
    self(*args, **kw)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/event/attr.py", line 322, in __call__
    fn(*args, **kw)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 1513, in go
    return once_fn(*arg, **kw)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 199, in first_connect
    dialect.initialize(c)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/dialects/mysql/base.py", line 2472, in initialize
    self._connection_charset = self._detect_charset(connection)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/dialects/mysql/pyodbc.py", line 89, in _detect_charset
    rs = connection.execute("SHOW VARIABLES LIKE 'character_set%%'")
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1012, in execute
    return self._execute_text(object_, multiparams, params)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1187, in _execute_text
    parameters,
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1324, in _execute_context
    e, statement, parameters, cursor, context
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1521, in _handle_dbapi_exception
    util.raise_(exc_info[1], with_traceback=exc_info[2])
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1284, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
TypeError: The first argument to execute must be a string or unicode query.

1 个答案:

答案 0 :(得分:0)

摘自文档:“ SQLAlchemy旨在与为特定数据库构建的DBAPI实现一起运行,并包括对最受欢迎的数据库的支持。”

PostgreSQL 的MySQL SQLite的 甲骨文 Microsoft SQL服务器 火鸟 Sybase公司 还有许多其他外部支持的驱动程序,例如DB2,Snowflake和redshift。使用SQLAlchemy连接到Denodo将需要开发和维护新的方言。据我所知,不支持任何jdbc驱动程序。