waliwali / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

Can't specify a table's schema when binding a preexisting table the declarative's way #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
A table CUSTOMER exists in the DATA schema (ie SQL queries access it as 
DATA.CUSTOMER)

1. Create an ibm_db_sa based engine :
  db2_engine=sqlalchemy.create_engine('ibm_db_sa://user:pwd@host:51001/DATABASE',echo=True)

2. Infer the Declarative Base class from it
  Base=declarative_base(db2_engine)

3. Define the class which will be mapped to the existing table
  class Customers(Base):
    __tablename__ = 'CUSTOMER'
    __table_args__ = {'autoload':True,'schema':'data'}

4. and later on use your engine to open a session (you would like to query on):

        metadata = Base.metadata
        Session = sessionmaker(bind=db2_engine)
        session = Session()

What is the expected output?
=>   Nothing, the mapping should occur without error, and the session should 
open.
   Then you could perform queries.

What do you see instead?
=> Traceback (most recent call last):
  File "extract.py", line 24, in <module>
    class Customers(Base):
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.7-py2.6.egg/sqlalchemy/ext/declarative.py", line 1175, in __init__
    _as_declarative(cls, classname, cls.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.7-py2.6.egg/sqlalchemy/ext/declarative.py", line 1065, in _as_declarative
    **table_kw)
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.7-py2.6.egg/sqlalchemy/schema.py", line 210, in __new__
    table._init(name, metadata, *args, **kw)
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.7-py2.6.egg/sqlalchemy/schema.py", line 266, in _init
    reflecttable(self, include_columns=include_columns)
  File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6.7-py2.6.egg/sqlalchemy/engine/base.py", line 1863, in reflecttable
    self.dialect.reflecttable(conn, table, include_columns)
  File "/usr/local/lib/python2.6/dist-packages/ibm_db_sa-0.2.0-py2.6.egg/ibm_db_sa/ibm_db_sa.py", line 218, in reflecttable
    col_args.append(schema.PassiveDefault(sql.text(def_value)))

What version of the product are you using? On what operating system?
=> sqlalchemy : '0.6.7'
=> ibm_db_sa : '0.2.0'

Regards

Original issue reported on code.google.com by julien.c...@gmail.com on 12 Sep 2011 at 4:26

GoogleCodeExporter commented 9 years ago
Thanks for reporting, I will inspect into this.

Original comment by jazlee on 28 Sep 2011 at 3:50

GoogleCodeExporter commented 9 years ago
Fixed on changeset #139 (http://code.google.com/p/ibm-db/source/detail?r=139). 

Original comment by jazlee on 28 Sep 2011 at 4:17