Open GoogleCodeExporter opened 8 years ago
Good catch. I've reproduced it, but I'm not sure what to do about it so far.
The Unicode Access unit tests work great. ODBC returns the correct length; for
a
254 character field, the length is 508 bytes.
When retrieving the remarks field, the value "this is a description" is
returned as
84 bytes, which would mean 42 Unicode characters which is exactly twice as wide
as
the actual value.
It appears to be this Access driver bug: http://support.microsoft.com/kb/q236871
Unfortunately it says both "BUFFER_LENGTH and CHAR_OCTET_LENGTH are 30 when
they
should also be 15" and "This behavior is by design". I'm not sure how
something can
both be wrong and by design, but it appears it is.
It looks like it always has a terminating NULL, so that's a potential way to
fix
it. I'm not sure I'm ready to always try to trim strings since it would (1)
affect
performance and (2) break code that expects embedded NULLs. Perhaps I should
set a
flag when Cursor.columns is used?
In the meantime, you can use something like the following to work around it:
cleaned = row and row.remarks.split(chr(0), 1)[0] or None
Original comment by mkleehammer
on 8 Aug 2009 at 3:46
Wow, that's interesting... Leave it to Microsoft to make a "By Design" bug...
ugh.
Thanks for the work-around idea, it's much better than mine (I, of course,
thought
about the problem way too close to the issue, and made a for-loop that pulled
characters one at a time,rebuilding a new string from it, up to the NULL). DOH.
I also noticed a second issue on the same field: I can enter text as long as I
want
into that field in Access, but if I exceed 128 characters, the string is
returned
as "None" or an empty string (can't remember which), in Python. I don't think
that
one's nearly as work-around'able at this point :-( I've had to just keep my
text
short and keep people aware of the issue when they add text as well.
Thanks for investigating the bug, I really appreciate it!!
Roger
Original comment by rogermilne@gmail.com
on 13 Aug 2009 at 5:01
Original issue reported on code.google.com by
rogermilne@gmail.com
on 11 Jun 2009 at 6:32Attachments: