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 ?
-
You are not getting "a gibrish", you are getting the raw binary data.Esteban Küber– Esteban Küber2010年02月23日 17:51:17 +00:00Commented Feb 23, 2010 at 17:51
-
But how i can convert it to hex format like what shown in microsoft enterprise managerdan– dan2010年02月23日 17:52:53 +00:00Commented Feb 23, 2010 at 17:52
1 Answer 1
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.