On Thu, 17 Aug 2006 20:00:11 +0200, Junkone <junkone1 / gmail.com> wrote:

> HI
> When i run this sql, i get error

[snip probably unimportant SQL spam]

> How do i clean up the data before inserting into the database.  I tried
> str.dump but it ends up escaping my strings for eg,
>  values('CHINA',16 became  values("'CHINA'","16" ......
>
> How can i clean it up without escaping the characters.

Hmm, this doesn't quite have enough details to go by, but...

<inane>
You can't have nonbinary characters in a string - they're all binary ;;P
</inane>

Are you building up the query string yourself, or using one of the methods  
your database driver (most certainly) provides?

The usual pattern is to use something like db_connection.execute('insert  
into womble(fluff) values(?, ?)', 'foo', 'bar'), and any self-respecting  
DB library should be able to determine the needed encoding and escape and  
convert string data by itself. Avoid hacking your own query string  
escaping routines, that's newbly and tends to break when you least expect  
it.

I think your problem is that you're inserting the 'ยป' character on the end  
in Latin 1 (where it's 0xBB), which is probably invalid in UTF-8 - the  
encoding probably used by the database. If the database driver doesn't do  
that, you'll have to convert encodings by hand (which might get a bit  
sensitive if you'll ever deploy that application on multiple computers) -  
look at the documentation to the 'iconv' library, which is part of the  
standard distribution unless memory fails me.\

David Vallner