- 论坛徽章:
- 4
|
Sqlite 更新后,中文是乱码,因为这些数据是重别的地方导入进来的,
现在通过python保存后,就成乱码了
以下是保存程序的代码
saildate = self.saildate.GetValue().Format('%Y-%m-%d')
arrdate = self.arrdate.GetValue().Format('%Y-%m-%d')
sql = ""
upsql=""
blnodt = []
for col in self.column.split(","):
col = col.strip()
sql = sql + "?,"
upsql= upsql + col + "=?,"
tc = getattr(self, col)
blnodt.append(tc.GetValue())
sql = sql[0:-1]
upsql= upsql[0:-1]
if self.action == 'add':
sql = sql + ",?,?,?,?"
blnodt.append(str(saildate))
blnodt.append(str(arrdate))
blnodt.append(time.strftime( self.ISOTIMEFORMAT, time.localtime() ))
blnodt.append(time.strftime( self.ISOTIMEFORMAT, time.localtime() ))
# print tuple(blnodt)
con=sqlite.connect(r"db\vspersional.db")
con.text_factory=str
cur = con.cursor()
if self.action == 'add':
cur.execute("insert into basvslvoy ("+self.column+self.dt+") values("+sql+")",tuple(blnodt))
if self.action == 'edit':
cur.execute("update basvslvoy set "+upsql + " where mainkey="+self.mainkey,tuple(blnodt))
con.commit()
con.close()
[ 本帖最后由 lvxinzhi 于 2008-3-5 14:01 编辑 ] |
|