Problem with odbc (pywin32) and unicode

Frank Millman frank at chagford.com
Fri Jan 27 07:22:03 EST 2006


Diez B. Roggisch wrote:
> Frank Millman wrote:
>
> >
> > This does not work -
> >     cur.execute("select * from users where userid = ?", [u'frank'])  #
> > new style
> >
> > I get the following error -
> > OdbcError: Found an insert row that didn't have 1 columns [sic]
>
> To me it looks as if your problem stems from not encoding the parameter as a
> string, but pasing a unicode-object that maybe internally causes trouble -
> and a misleading error message.
>
> So I suggest you try this:
>
> cur.execute("select * from users where userid = ?",
> [u'frank'.encode("utf-8"])
>
>
> If that works, we know the problem. Make sure that your DB is expecting
> UTF-8, or use the encoding it wants instead!
>

Thanks, Diez - I tried it and it works.

Unicode is one of those grey areas that I know I will have to try to
understand one day, but I am putting off that day as long as possible!

When you say it causes trouble internally, do you mean internal to the
odbc module? Is it something that should be reported as a bug?

What should I do in the meantime? Make encode("utf-8") a permanent
feature of my program?

BTW, the reason I am getting unicode objects is that I use wxPython as
my front end. You can opt for a unicode or a non-unicode build. I
decided to go for unicode to cater for future requirements. This is the
first time it has bitten me - I am sure it will not be the last.

Many thanks for your help

Frank




More information about the Python-list mailing list