Open theoharr opened 6 years ago
Some quick investigation:
The first query is only returning None because of bad code in ibmdbpy:
This catches any and all exceptions during result set retrieval and ignores it. Catching and logging the exception provides a bit more detail:
> SELECT name from tjhtest
'utf-16-le' codec can't decode bytes in position 0-1: unexpected end of data
None
Number 2 (the large field) is https://github.com/jiangwen365/pypyodbc/blob/2aea5719369405743a1420cc2570f1e62f3f4d6f/pypyodbc.py#L1937-L1938. Not sure what's wrong there.
Number 3 (the boolean) works on my setup:
root@b081fa76a550:/code/ibmdbpy/tests# python
Python 3.6.4 (default, Feb 15 2018, 12:56:09)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ibmdbpy import IdaDataBase; idadb = IdaDataBase([...] verbose=True)
>>> query = "SELECT bool from tjhtest"
>>> print(idadb.ida_query(query))
> SELECT bool from tjhtest
0 1
1 0
That's with Db2 Warehouse 2.11, ibmdbpy 0.1.5, pypyodbc 1.3.4 on Python 3.5.
For Number 2 ... I'm pretty sure the problem is here
https://github.com/jiangwen365/pypyodbc/blob/master/pypyodbc.py#L632
I appears pypyodbc always allocates a 2K buffer for VARCHARs. I believe db2wh uses utf8 encoding by default ... so each char might be 2 bytes? This would explain why things seem to fail for any VARCHAR larger than 1024 characters.
Hmm, I'm confused. I'm not sure why Number 3 works for you but fails for me. I upgraded my ibmdbpy version to 0.1.5
...and my python version is very close. Maybe it has something to do with the db2wh version?
[moadmin@metaocean-tjh ~]$ pip freeze | egrep "ibmdbpy|pypy"
ibmdbpy==0.1.5
pypyodbc==1.3.4
It consistently fails for me:
[moadmin@metaocean-tjh ~]$ python3
Python 3.4.9 (default, Aug 14 2018, 21:28:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ibmdbpy import IdaDataBase;
>>> idadb = IdaDataBase('dashdb',uid='bluadmin',pwd='<PW>',verbose=True)
>>> query = "SELECT bool from tjhtest"
>>> print(idadb.ida_query(query))
> SELECT bool from tjhtest
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/site-packages/ibmdbpy/base.py", line 762, in ida_query
return sql.ida_query(self, query, silent, first_row_only, autocommit)
File "/usr/lib/python3.4/site-packages/ibmdbpy/sql.py", line 81, in ida_query
return _ida_query_ODBC(idadb, query, silent, first_row_only, autocommit)
File "/usr/lib/python3.4/site-packages/ibmdbpy/sql.py", line 94, in _ida_query_ODBC
cursor.execute(query)
File "/usr/lib/python3.4/site-packages/pypyodbc.py", line 1626, in execute
self.execdirect(query_string)
File "/usr/lib/python3.4/site-packages/pypyodbc.py", line 1654, in execdirect
self._UpdateDesc()
File "/usr/lib/python3.4/site-packages/pypyodbc.py", line 1806, in _UpdateDesc
self._CreateColBuf()
File "/usr/lib/python3.4/site-packages/pypyodbc.py", line 1712, in _CreateColBuf
target_type = SQL_data_type_dict[col_sql_data_type][2]
KeyError: 16
Can you run this query in your env too?
>>> query = "SELECT colname, typename, length FROM syscat.columns where tabschema='BLUADMIN' AND tabname='TJHTEST' order by colno"
>>> print(idadb.ida_query(query))
> SELECT colname, typename, length FROM syscat.columns where tabschema='BLUADMIN' AND tabname='TJHTEST' order by colno
colname typename length
0 NAME VARCHAR 128
1 BIGFIELD VARCHAR 4096
2 BOOL BOOLEAN 1
I believe the problem is that pypyodbc doesn't have any support for the BOOLEAN type:
https://github.com/jiangwen365/pypyodbc/blob/master/pypyodbc.py#L617
I get the same output as you when querying the system catalog. Do you have access to a system with a more recent Db2 Warehouse container that you could test on? If not, please let me know off-Github and I can find you a system for a few hours.
My system:
I believe most of the limitations are actually due to problems in the odbc connector (pypyodbc). In any case, the problems I've identified are:
I set up this table to test against:
If I query the table from the db2wh ui I get:
When I query the name, I get nothing:
When I query the large field, I get an exception:
When I query the BOOLEAN, I also get an exception:
To get around this, I swapped out the odbc connector ... I replaced pypyodbc with pyodbc:
Once I made that change, the first two tests worked ... BOOLEAN still seems to have problems: