turbodbc
turbodbc copied to clipboard
Support binary types
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'
Yes, this is currently not supported. Would you agree with the following behavior?
Python 2:
Reading:
- DB
SQL_VARBINARY
-> Pythonstr
- DB
SQL_VARCHAR
-> Pythonunicode
Writing: - Python
str
|unicode
->SQL_VARCHAR
Python 3:
Reading:
- DB
SQL_VARBINARY
-> Pythonbytes
- DB
SQL_VARCHAR
-> Pythonstr
Writing: - Python
str
->SQL_VARCHAR
- Python
bytes
->SQL_VARBINARY
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.
Well, turbodbc already supports Unicode, just via the UTF-8 path ;-). I have corrected it above.
@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.