lundi 29 juin 2015

Storing Unicode strings to SQLite database using PeeWee

Working with peewee to create a simple sqlite database that stores items form a parsed MRSS feed, specifically video URLs and video titles.

I have a little dedupe script that I wrote that checks whether or not the URL and video title that's just been parsed is already in the database. I've noticed that when I pass URL strings to the database, there are no issues, dedupe works fine. When I browser through the database for the URLs I've stored there, using an app like sqlitebrowser, I see the URLs with no Unicode encoding, they looks like regular old strings, no u'.

However, when I pass unicode video titles — like this: (u'Animals doing the strangest things',) the dedupe script wasn't "seeing" the video titles in the database. The solution was to do a simple conversion with the video title object like this: videoName = str(videoName) — however, I have no clue why this works now. When I browse the videoName column in my database using sqlitebrowser, I see the video names, but they're still in Unicode and look the same as they did before: (u'Animals doing the strangest things',)

Any idea what the heck is going on here? Does this have something to do with a weird bug with how PeeWee is handling string serialization?

Aucun commentaire:

Enregistrer un commentaire