turbodbc icon indicating copy to clipboard operation
turbodbc copied to clipboard

Support binary types

Open TWAC opened this issue 7 years ago • 4 comments

Feature request, SQL_VARBINARY / SQL_LONGVARBINARY does not seem to work today.

Tried this with postgresql and python 3.5

CREATE TABLE mybtest
(
  fooid integer,
  foobin bytea
);
insert into mybtest (fooid, foobin) values (123, 'foo');
from turbodbc import connect
conn = connect(DRIVER="PostgreSQL ANSI", ...)
cursor = conn.cursor()
cursor.execute("select * from mybtest")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "python3.5/site-packages/turbodbc/exceptions.py", line 31, in wrapper
    return f(*args, **kwds)
  File "python3.5/site-packages/turbodbc/cursor.py", line 72, in execute
    self.impl.execute()
RuntimeError: Error! Unsupported type identifier '-3'

TWAC avatar Mar 14 '17 15:03 TWAC

Yes, this is currently not supported. Would you agree with the following behavior?

Python 2:

Reading:

  • DB SQL_VARBINARY -> Python str
  • DB SQL_VARCHAR -> Python unicode Writing:
  • Python str|unicode -> SQL_VARCHAR

Python 3:

Reading:

  • DB SQL_VARBINARY -> Python bytes
  • DB SQL_VARCHAR -> Python str Writing:
  • Python str -> SQL_VARCHAR
  • Python bytes -> SQL_VARBINARY

MathMagique avatar Mar 14 '17 15:03 MathMagique

For Python 3 that definitely makes sense.

On Python 2 I don't have any strong opinion. Since turbodbc does not currently use unicode, it is probably best to keep everything str. But perhaps with the new prefer_unicode option consider returning unicode for SQL_VARCHAR. Not sure if it would be a good idea to write str as SQL_VARBINARY with prefer_unicode, might be confusing.

TWAC avatar Mar 14 '17 16:03 TWAC

Well, turbodbc already supports Unicode, just via the UTF-8 path ;-). I have corrected it above.

MathMagique avatar Mar 15 '17 08:03 MathMagique

@MathMagique do you have an example of how to add support for a new data type? E.g. a pull request that was merged, in which this was done? I just want to see if it is something I could take on because lack of binary support is a blocker for my adoption. I don't want to have to modify queries to do conversion.

dstandish avatar Nov 17 '19 04:11 dstandish