开发者

python & sql server

When I do a select statement for 开发者_如何学运维varbinary field in microsoft enterprise manager i get the field on readabel hex format like ab2c2f2d... but when i do the same statment with pymssql i get a gibrish

the select statment is : select x from table --where x the varbinary field

could someone help with this issue ?


Microsoft Enterprise Manager is converting the binary value to a hexadecimal string for you.

One option is to change your query to SELECT CAST( x AS varchar ) FROM table. This will have SQL Server convert the varbinary to a hexdecimal string for you, http://msdn.microsoft.com/en-us/library/aa226054(SQL.80).aspx

Another option is to use the python module, binascii to convert the binary data to a hexadecimal string yourself. You use the functions binascii.b2a_hex(data) or binascii.hexlify(data) to do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜