On 5/26/15 1:11 PM, skinle...@gmail.com wrote:
Hi,
I am getting this error when trying to do query() and CreateTable()
with XML data type on db2 database. (Using ibm_db_sa)
Any suggestions how to resolve this?
|
fromsqlalchemy importcreate_engine
fromsqlalchemy importMetaData
fromsqlalchemy importTable
fromsqlalchemy.schema importCreateTable
fromsqlalchemy.orm importsessionmaker
db2_engine =create_engine('ibm_db_sa://user:pass@server:50001/DBNAME')
meta =MetaData(bind=db2_engine,schema='udbadm')
table1 =Table('table1',meta,autoload=True)
Session=sessionmaker(bind=db2_engine)
session =Session()
res =session.query(table1).first()
print(res)
# Similar issue with CreateTable:
# print(CreateTable(table1))
|
the reflected object contains datatypes that are IBM specific. You
can't attempt to render them using the default "generic" compiler. so
the print(CreateTable) needs to be compiled in terms of the DB2 engine:
print(CreateTable(table1).compile(db2_engine)).
As far as the error with "query()", "query" does not make use of create
table, nor in a simple case like the above would it require attempting
to render a datatype unless you were using a function like CAST (which
the above example is not). The error you are getting for that is almost
certainly something else entirely.
|
Traceback(most recent call last):
File"defect_rep1.py",line 14,in<module>
print(CreateTable(table1))
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\elements.py",line
506,in__str__
returnunicode(self.compile()).encode('ascii','backslashreplace')
File"<string>",line 1,in<lambda>
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\elements.py",line
494,incompile
returnself._compiler(dialect,bind=bind,**kw)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\ddl.py",line
26,in_compiler
returndialect.ddl_compiler(dialect,self,**kw)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\compiler.py",line
190,in__init__
self.string=self.process(self.statement,**compile_kwargs)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\compiler.py",line
213,inprocess
returnobj._compiler_dispatch(self,**kwargs)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\visitors.py",line
81,in_compiler_dispatch
returnmeth(self,**kw)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\compiler.py",line
2153,invisit_create_table
(table.description,column.name,ce.args[0])
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\util\compat.py",line
199,inraise_from_cause
reraise(type(exception),exception,tb=exc_tb)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\compiler.py",line
2142,invisit_create_table
andnotfirst_pk)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\compiler.py",line
213,inprocess
returnobj._compiler_dispatch(self,**kwargs)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\visitors.py",line
81,in_compiler_dispatch
returnmeth(self,**kw)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\compiler.py",line
2173,invisit_create_column
first_pk=first_pk
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\compiler.py",line
2314,inget_column_specification
column.type,type_expression=column)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\compiler.py",line
261,inprocess
returntype_._compiler_dispatch(self,**kw)
File"C:\dev\test_ibm_db_sa\venv27\lib\site-packages\sqlalchemy\sql\visitors.py",line
79,in_compiler_dispatch
raiseexc.UnsupportedCompilationError(visitor,cls)
sqlalchemy.exc.CompileError:(intable 'table1',column
'text_xml'):Compiler<sqlalchemy.sql.compiler.GenericTypeCompilerobjectat
0x03792BB0>can't render element of type <class 'ibm_db_sa.base.XML'>
|
This is how the table is setup in DB2:
|
CREATE TABLE UDBADM.TABLE1
(
ID_TEST CHARACTER(36)NOT NULL,
TEXT_XML XML
PRIMARY KEY (ID_TEST)
);
|
Thanks,
SL
--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.