[egenix-users] unicode, sql command, mxODBC

Khawaja-Shahzad Butt kshahzadbutt at gmail.com
Wed Nov 10 09:25:45 CET 2004


Hi,
     As far my knowledge goes.  I guess with mxODBC you can 
not run SQL involving unicode strings. You have to encode them
into utf-8.  Here a suggestion:

try:
        var1=var1.encode('utf8'); ;
    except:
        var1=var1; and so on

store you values which you want to insert into variables, then
encode all the variables into utf-8. then try the insert statement.

query_str = "INSERT INTO table\
    (a,b,c)\
    VALUES (?,?,?)" 
   
    cursor.execute(query_str, (var1,var2, var3,))

Try this and let me know.
Hope this helps.

On Wed, 10 Nov 2004 04:34:53 -0800 (PST), zhihua ouyang
<zxo102 at yahoo.com> wrote:
> Hi everyone,
>   I need your help. I have tried for a while to make
> unicoded sql command work with mxODBC in window
> xp(Chinese Version) but failed since some unicode
> chinese characters are in it.
> 
> Here is my case:
>  1.  A Excel file in c:\\test.xls which contains
> chinese characters.
>  2. I got the data from test.xls using the following
> code
> 
>     from win32com.client import DispatchEx
>     xApp = DispatchEx("Excel.Application")
>     xBook = xApp.Workbooks.Open('c:\\test.xls')
>     sheet = xBook.Worksheets('sheet1')
>     aaa = []
>     for i in range(10):
>       aaa.append(sheet.Cell(5,i).Value)
>      ......
> 
> and generate sql command dynamically with those
> chinese data. The following is an example:
> 
>     sqlCommandStr = u"INSERT INTO instruments VALUES
> ('0401', 23800.0,
> 0.0,'\u4e2d\u56fd','156','2000-1-1','\u5f20\u6167\u82ac');"
> 
> But mxODBC gives error info: "sql command must be a
> string".
> 
>   If chinese characters are inserted into the sql
> command like
>     "INSERT INTO instruments VALUES ('0401', 23800.0,
> 0.0,'²âÊÔ','156','2000-1-1','²âÊÔ');"
>   everything is fine. But I don't know how to
> generate it in above condition.
> 
>    Does mxODBC accept the unicoded sql command?
> 
> Thanks.
> 
> Ouyang
> 
> __________________________________
> Do you Yahoo!?
> Check out the new Yahoo! Front Page.
> www.yahoo.com
> 
> _______________________________________________________________________
> eGenix.com User Mailing List                     http://www.egenix.com/
> http://lists.egenix.com/mailman/listinfo/egenix-users
>



More information about the egenix-users mailing list