caretdev / sqlalchemy-iris

https://pypi.org/project/sqlalchemy-iris/
MIT License
12 stars 6 forks source link

problem retrieving table data #1

Closed dkutac closed 1 year ago

dkutac commented 1 year ago

Hi Dmitry, I have this code: import sqlalchemy as db engine = db.create_engine("iris://kutac:pwd@localhost:51774/USER")

connection = engine.connect() metadata = db.MetaData()

city = db.Table('demo.citytable', metadata, autoload=True, autoload_with=engine)

print(city.columns.keys())

---- where demo.citytable is a simple IRIS table: Class Demo.CityTable Extends %Persistent {

Property Name As %String [ SqlColumnNumber = 2 ];

Property City As %String [ SqlColumnNumber = 6 ];

Property Age As %Integer [ SqlColumnNumber = 3 ];

Property Friends As %Integer [ SqlColumnNumber = 4 ];

Property Cash As %Numeric(SCALE = 2) [ SqlColumnNumber = 5 ];

--- runnning the code result in error below: PS C:\WORK\Projects\Python\sql-alchemy> & C:/Users/kutac/AppData/Local/Programs/Python/Python310/python.exe c:/WORK/Projects/Python/sql-alchemy/sqldemo.py Traceback (most recent call last): File "c:\WORK\Projects\Python\sql-alchemy\sqldemo.py", line 11, in city = db.Table('demo.citytable', metadata, autoload=True, autoload_with=engine) File "", line 2, in new File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\util\deprecations.py", line 309, in warned return fn(*args, *kwargs) File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\sql\schema.py", line 616, in new
with util.safereraise(): File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\util\langhelpers.py", line 70, in exit compat.raise( File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\util\compat.py", line 208, in raise_
raise exception File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\sql\schema.py", line 612, in new table._init(name, metadata,
args, **kw) File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\sql\schema.py", line 687, in _init self._autoload( File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\sql\schema.py", line 722, in _autoload conn_insp.reflect_table( File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\engine\reflection.py", line 774, in reflect_table for col_d in self.get_columns( File "C:\Users\kutac\AppData\Local\Programs\Python\Python310\lib\site-packages\sqlalchemy\engine\reflection.py", line 500, in get_columns for col_def in col_defs: TypeError: 'NoneType' object is not iterable

any idea?

daimor commented 1 year ago

Hi, thanks for report, yep, I see the issue, in my part and I'll fix it but, you have issue as well

The correct code should be

city = db.Table('CityTable', metadata, schema='Demo', autoload=True, autoload_with=engine)

Schema name, has to be passed separately

dkutac commented 1 year ago

ok, thanks Dmitry.

dkutac commented 1 year ago

with you proposed change, I was able to retrieve data from the table as well. closing this issue.