If you do "Make the string unicode and then pass it to the sqlite3 module" It can handle multi-byte character strings without any problem.
python
import sqlite3,sys,os
con = sqlite3.connect("./temp.sqlite")
#Create table
sql = u"""
create table filepath(
id INTEGER PRIMARY KEY AUTOINCREMENT,
path text);"""
con.execute(sql)
#Receive file list from standard input
#Store in DB
for rwln in iter(sys.stdin.readline,""):
path = rwln.rstrip('\n') #Remove trailing newline
sql = u"""insert into filepath(path) values (?); """
cur = self.con.cursor()
#File system encoding is sys.getfilesystemencoding()Because you can get it with
#Use this to unicode()After conversion by function, pass it to sqlite module
cur.execute(sql,(unicode(path, sys.getfilesystemencoding()),))
Besides this method, it can be stored after base64 conversion, If the encoding can be specified, it is better to use unicode.
Recommended Posts