Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support binary types #56

Open
TWAC opened this issue Mar 14, 2017 · 4 comments
Open

Support binary types #56

TWAC opened this issue Mar 14, 2017 · 4 comments
Labels

Comments

@TWAC
Copy link

TWAC commented Mar 14, 2017

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'
@MathMagique
Copy link
Member

MathMagique commented Mar 14, 2017

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

@TWAC
Copy link
Author

TWAC commented Mar 14, 2017

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.

@MathMagique
Copy link
Member

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

@dstandish
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants