google-code-export / pymssql

Automatically exported from code.google.com/p/pymssql
GNU Lesser General Public License v2.1
0 stars 0 forks source link

better handling for byte strings that don't represent ascii data #46

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a test:

test_sqlalchemy:TestSA.test_pickle_type

that fails currently.  When this column is created, it is created as a 
varchar(50) column.  There is a note and monkey patch in:

sqlalchemy.dialects.mssql.pymssql.MSDialect_pymssql.dbapi

referring to the fact that pymssql does not have a Binary method.  I am a 
little over my head on this one as to what we need to do to fix it.  

Original issue reported on code.google.com by rsyr...@gmail.com on 15 Apr 2011 at 9:42

GoogleCodeExporter commented 9 years ago
I have a pymssql only tests now for this in test_types.py:TestTypes.test_image. 
 There is also a commit in [bea17389d31e] which fixes this problem from a 
technical standpoint.  It simply turns all type(str) values into a hex 
representation and sends that to MSSQL.  This seems to work well from a 
technical perspective.

However, the down-side is that it makes debugging difficult.  If someone is 
trying to debug a problem by watching SQL Server traces, they are only going to 
see the hex coming over.  Since character data will probably be the most common 
type(str) to be sent over, this seems unideal.

Therefore, in [5ba20a7b7d70] I made the quote function smarter so that anything 
that can be decoded as ascii will get put directly in the string.  Everything 
else gets hex encoded.

These changes are currently in my bb repo but I would appreciate a look over 
what I have done to make sure it looks good.

Original comment by rsyr...@gmail.com on 16 Apr 2011 at 5:37