免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4527 | 回复: 3
打印 上一主题 下一主题

Sqlite 更新后,中文是乱码 [复制链接]

论坛徽章:
4
天蝎座
日期:2013-11-06 11:39:34巳蛇
日期:2014-01-16 16:53:14午马
日期:2014-08-25 21:42:302015年迎新春徽章
日期:2015-03-03 17:21:44
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-05 13:55 |只看该作者 |倒序浏览
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 编辑 ]

Image00001.jpg (46.75 KB, 下载次数: 31)

Image00001.jpg

论坛徽章:
0
2 [报告]
发表于 2008-03-05 14:15 |只看该作者
转为unicode或utf-8进行保存。

论坛徽章:
4
天蝎座
日期:2013-11-06 11:39:34巳蛇
日期:2014-01-16 16:53:14午马
日期:2014-08-25 21:42:302015年迎新春徽章
日期:2015-03-03 17:21:44
3 [报告]
发表于 2008-03-05 14:32 |只看该作者

回复 #2 limodou 的帖子

# --*-- encoding: UTF-8 --*--

我在文件头已经引用了这一行,

论坛徽章:
0
4 [报告]
发表于 2008-03-05 14:48 |只看该作者
那只是程序本身是,并不表示所处理的数据是。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP