How to use SQLAlchemy reflection with Sybase? [answer: turns out it's not supported!]

久未见 提交于 2019-12-24 01:02:06

问题


I'm trying to learn more about the .egg concept and overriding methods in Python. Here's the error message I'm receiving:

Traceback (most recent call last):
  File "C:/local/work/scripts/plmr/plmr_db.py", line 42, in <module>
    insp.reflecttable(reo_daily_table, column_list)
  File "build\bdist.win32\egg\sqlalchemy\engine\reflection.py", line 370, in reflecttable
  File "build\bdist.win32\egg\sqlalchemy\engine\reflection.py", line 223, in get_columns
  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 260, in get_columns
NotImplementedError

Here's the specific function from base.py:

def get_columns(self, connection, table_name, schema=None, **kw):
    """Return information about columns in `table_name`.

    Given a :class:`.Connection`, a string
    `table_name`, and an optional string `schema`, return column
    information as a list of dictionaries with these keys:

    name
      the column's name

    type
      [sqlalchemy.types#TypeEngine]

    nullable
      boolean

    default
      the column's default value

    autoincrement
      boolean

    sequence
      a dictionary of the form
          {'name' : str, 'start' :int, 'increment': int}

    Additional column attributes may be present.
    """

    raise NotImplementedError()

So my question is - do I override this function by writing a new method in my main module? Or am I missing a step somewhere along the way with my imports? Or am I just completely off track here?

Any and all help is appreciated :)

edit: adding my code

import sys
from sqlalchemy import create_engine, select, Table, MetaData
from sqlalchemy.engine import reflection

dbPath = 'connection_string'
engine = create_engine(dbPath, echo=True)

connection = engine.connect()

#reflect tables into memory
meta = MetaData()
reo_daily_table = Table('reo_daily',meta)
insp = reflection.Inspector.from_engine(engine)
column_list=[...]
insp.reflecttable(reo_daily_table, column_list)

connection.close()

回答1:


EDIT:

The Sybase dialect currently lacks the ability to reflect tables.




回答2:


You have misunderstood completely. You do not need to subclass anything and this problem has nothing to do with eggs and .ini files at all.

You are not supposed to instantiate Inspector this way. If you read SQLAlchemy docs carefully, you will notice that you are not supposed to use Reflection constructor directly; instead you should write

insp = reflection.Inspector.from_engine(engine)


来源:https://stackoverflow.com/questions/9588345/how-to-use-sqlalchemy-reflection-with-sybase-answer-turns-out-its-not-suppor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!