anthony-tuininga / ceODBC

Python module for accessing databases using the ODBC API.
https://anthony-tuininga.github.io/ceODBC/
12 stars 8 forks source link

sql server char type #9

Closed ibnadam closed 1 year ago

ibnadam commented 3 years ago

When executing a select query e.g.

select some_col from some_table

where some_col is defined as:

some_col char not null default 'N';

I get the following error:

  File "src/ceODBC/cursor.pyx", line 423, in ceODBC.driver.Cursor.execute
  File "src/ceODBC/cursor.pyx", line 269, in ceODBC.driver.Cursor._execute
  File "src/ceODBC/cursor.pyx", line 383, in ceODBC.driver.Cursor._prepare_result_set
  File "src/ceODBC/cursor.pyx", line 205, in ceODBC.driver.Cursor._create_var_for_result_set
  File "src/ceODBC/types.pyx", line 76, in ceODBC.driver.DbType._from_sql_data_type
  File "src/ceODBC/errors.pyx", line 83, in ceODBC.driver._raise_from_string
ceODBC.exceptions.NotSupportedError: SQL data type 1 not supported

Running from Ubuntu 20.04, driver "ODBC Driver 17 for SQL Server"

Thanks.

anthony-tuininga commented 3 years ago

I see it also with PostgreSQL. I am adding char columns to the test suite and will provide a patch shortly. Thanks for reporting this!

monofox commented 2 years ago

Same applies to -8:

Traceback (most recent call last):
  File "/home/mono/.projects/eup/md-sync-java/test.py", line 58, in <module>
    cursor.execute("select * from KDIDATV8.PBFSTSS limit 5000")
  File "src/ceODBC/cursor.pyx", line 423, in ceODBC.driver.Cursor.execute
  File "src/ceODBC/cursor.pyx", line 269, in ceODBC.driver.Cursor._execute
  File "src/ceODBC/cursor.pyx", line 383, in ceODBC.driver.Cursor._prepare_result_set
  File "src/ceODBC/cursor.pyx", line 205, in ceODBC.driver.Cursor._create_var_for_result_set
  File "src/ceODBC/types.pyx", line 79, in ceODBC.driver.DbType._from_sql_data_type
  File "src/ceODBC/errors.pyx", line 83, in ceODBC.driver._raise_from_string
ceODBC.exceptions.NotSupportedError: SQL data type -8 not supported

-8 is a GRAPHICS field (String) on IBM i DB2 (https://www.ibm.com/docs/en/i/7.4?topic=types-dbcs-graphic-fields#graphic) storing data in double byte.

anthony-tuininga commented 1 year ago

Looks like SQL data type -8 refers to SQL_WCHAR -- which I added support for in 3.1 (just released). Does that resolve the issue for you?

monofox commented 1 year ago

Yes, works @anthony-tuininga, thank you!