encoding/decoding issue with python2.5 and pymssql

T

Tzury Bar Yochay

hi,

in my table the field row_id is type of uniqueidentifier.

when try to fetch the data, pymssql somehow, encodes the values in a
way which yields odd results.

for example:
the value
'EE604EE3-4AB0-4EE7-AF4D-018124393CD7'
is represent as
'\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7'

the only way I manged to pass this is by converting the value into
varchar at the server side.
I would like to solve this at the python side and not in the database
for several obvious reasons

see example:
conn = mymssql.connect(**connection_details)
cur = conn.cursor()
sql = "select row_id, cast(row_id as varchar(36)) from table_a"
cur.execute(sql)
rows = cur.fetchall()
rows[0]
('\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7', 'EE604EE3-4AB0-4EE7-
AF4D-018124393CD7')
 
D

Dennis Lee Bieber

for example:
the value
'EE604EE3-4AB0-4EE7-AF4D-018124393CD7'
is represent as
'\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7'
Are those direct cut&paste?
"".join(["%2.2X" % ord(x) for x in '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7'])
'E34E60EEB04AE74EAF4D018124393CD7'

or, putting in -

'E34E60EE-B04A-E74E-AF4D-018124393CD7'

The last half is a direct match... the front half looks to have some
byte-swapping

E34E60EE => (swap shorts) 60EEE34E
60EEE34E => (swap bytes) EE604EE3 ****

B04A => 4AB0 ****

E74E => 4EE7 ****


Anything on
http://www.sqljunkies.com/Article/4067A1B1-C31C-4EAF-86C3-80513451FC03.scuk
of any help (besides the facet of using a GUID to ID the page describing
GUIDs <G>)




--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
T

Tzury Bar Yochay

These are not cut&paste but typed by hand, yet they are identical to
the actual output.
seems like the first 8 bytes are swapped while the other half is
straightforward.

I deeply thank you for your assistance.

I am currently using a combination of reversed and list comprehension
to rebuild this byte array.


for example:
the value
'EE604EE3-4AB0-4EE7-AF4D-018124393CD7'
is represent as
'\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7'

        Are those direct cut&paste?
"".join(["%2.2X" % ord(x) for x in '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7'])

'E34E60EEB04AE74EAF4D018124393CD7'

or, putting in -

'E34E60EE-B04A-E74E-AF4D-018124393CD7'

        The last half is a direct match... the front half looks to have some
byte-swapping

E34E60EE => (swap shorts)    60EEE34E
60EEE34E => (swap bytes)     EE604EE3                ****

B04A => 4AB0         ****

E74E => 4EE7         ****

        Anything onhttp://www.sqljunkies.com/Article/4067A1B1-C31C-4EAF-86C3-80513451FC0...
of any help (besides the facet of using a GUID to ID the page describing
GUIDs <G>)

--
        Wulfraed        Dennis Lee Bieber               KD6MOG
        (e-mail address removed)             (e-mail address removed)
                HTTP://wlfraed.home.netcom.com/
        (Bestiaria Support Staff:               (e-mail address removed))
                HTTP://www.bestiaria.com/
 
R

Rob Williscroft

Tzury Bar Yochay wrote in @b1g2000hsg.googlegroups.com in comp.lang.python:
for example:
the value
'EE604EE3-4AB0-4EE7-AF4D-018124393CD7'
is represent as
'\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7'

from uuid import *

u = UUID( bytes = '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7')
print u

u = UUID( bytes_le = '\xe3N`\xee\xb0J\xe7N\xafM\x01\x81$9<\xd7')
print u

The "bytes_le" version prints: ee604ee3-4ab0-4ee7-af4d-018124393cd7
so I guess, this is what mysql is returning.

http://docs.python.org/lib/module-uuid.html

Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top