2005年06月09日 星期四 16:03
请问我写了一个读sqlite数据库的小程序 import pysqlite2.dbapi2 as sqlite import BTTime import SingleTablePanel def createData(): cx = sqlite.connect( "alarm.sqlite" ) cu = cx.cursor() cu.execute( "create table alarmhistory ( uuid varchar( 50 ),time INTEGER, guizheno INTEGER,ip varchar( 30 ),name TEXT, value TEXT, state TEXT, descr TEXT, type INTEGER, panbi INTEGER ,PRIMARY KEY ( uuid, type ) )" ) def getData( ): cx = sqlite.connect( "alarm.sqlite" ) cu = cx.cursor() cu.execute("select * FROM alarmhistory") data = {} count = 0 for uuid ,t, guizheno,ip,name , value , state , descr , type , panbi in cu.fetchall(): if type == 0: data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "error" ) elif type == 1: data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "resume" ) elif type == 2: data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "change" ) elif type == 3: data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "delete" ) return data 当我调用getData时发生下面的错误,alarm.sqlite文件是用c ++生成的,有的项 中有中文。 Traceback (most recent call last): File "AlarmTable.py", line 123, in ? run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) File "D:\work\python\run.py", line 157, in main app = RunApp(name, module, useShell) File "D:\work\python\run.py", line 47, in __init__ wx.App.__init__(self, redirect=False) File "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", line 5301, in __init__ self._BootstrapApp() File "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", line 4980, in _BootstrapApp return _core_.PyApp__BootstrapApp(*args, **kwargs) File "D:\work\python\run.py", line 75, in OnInit win = self.demoModule.runFrame(frame, frame, Log()) File "D:\work\python\AlarmTable.py", line 117, in runFrame win = SingleTablePanel.TablePanel(nb, "AlarmTable","DATA/"+dbname + "/HISTORY/DATA/ALARM.SQLITE",log) File "D:\work\python\SingleTablePanel.py", line 60, in __init__ self.datalist = self.__getData( ) File "D:\work\python\SingleTablePanel.py", line 35, in __getData return self.datatable.getData(); File "D:\work\python\AlarmTable.py", line 17, in getData tables = cu.fetchall() UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: invalid data 请问怎样解决了这个问题
2005年06月09日 星期四 16:12
alarm.sqlite是用C++生成的?那是sqlite的格式吗?sqlite有自已的文件格式的,不是简单的文本文件。同时pysqlite2的字符串数据变成了unicode了,因此要注意编码转换。至于它保存在数据库中是什么编码,我猜可能是utf-8。 在 05-6-9,run_mei<run_mei at 163.com> 写道: > 请问我写了一个读sqlite数据库的小程序 > import pysqlite2.dbapi2 as sqlite > import BTTime > import SingleTablePanel > > def createData(): > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute( "create table alarmhistory ( uuid varchar( 50 ),time > INTEGER, guizheno INTEGER,ip varchar( 30 ),name TEXT, value TEXT, state > TEXT, descr TEXT, type INTEGER, panbi INTEGER ,PRIMARY KEY ( uuid, type > ) )" ) > > def getData( ): > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute("select * FROM alarmhistory") > data = {} > count = 0 > for uuid ,t, guizheno,ip,name , value , state , descr , type , panbi in > cu.fetchall(): > if type == 0: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "error" ) > elif type == 1: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "resume" ) > elif type == 2: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "change" ) > elif type == 3: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "delete" ) > > return data > > 当我调用getData时发生下面的错误,alarm.sqlite文件是用c ++生成的,有的项 > 中有中文。 > Traceback (most recent call last): > File "AlarmTable.py", line 123, in ? > run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) > File "D:\work\python\run.py", line 157, in main > app = RunApp(name, module, useShell) > File "D:\work\python\run.py", line 47, in __init__ > wx.App.__init__(self, redirect=False) > File "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", > line 5301, in __init__ > self._BootstrapApp() > File "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", > line 4980, in _BootstrapApp > return _core_.PyApp__BootstrapApp(*args, **kwargs) > File "D:\work\python\run.py", line 75, in OnInit > win = self.demoModule.runFrame(frame, frame, Log()) > File "D:\work\python\AlarmTable.py", line 117, in runFrame > win = SingleTablePanel.TablePanel(nb, "AlarmTable","DATA/"+dbname + > "/HISTORY/DATA/ALARM.SQLITE",log) > File "D:\work\python\SingleTablePanel.py", line 60, in __init__ > self.datalist = self.__getData( ) > File "D:\work\python\SingleTablePanel.py", line 35, in __getData > return self.datatable.getData(); > File "D:\work\python\AlarmTable.py", line 17, in getData > tables = cu.fetchall() > UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: > invalid data > > 请问怎样解决了这个问题 > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > -- I like python! My Donews Blog: http://www.donews.net/limodou New Google Maillist: http://groups-beta.google.com/group/python-cn
2005年06月09日 星期四 16:53
用c++生成有,当然是用sqlite的c++库,否则我哪知道它的格式,而且是用 sqlite2的c++接口库,我怎样进行 编码转换呢?谢谢! limodou 写道: >alarm.sqlite是用C++生成的?那是sqlite的格式吗?sqlite有自已的文件格式的,不是简单的文本文件。同时pysqlite2的字符串数据变成了unicode了,因此要注意编码转换。至于它保存在数据库中是什么编码,我猜可能是utf-8。 > >在 05-6-9,run_mei<run_mei at 163.com> 写道: > > >>请问我写了一个读sqlite数据库的小程序 >>import pysqlite2.dbapi2 as sqlite >>import BTTime >>import SingleTablePanel >> >>def createData(): >>cx = sqlite.connect( "alarm.sqlite" ) >>cu = cx.cursor() >>cu.execute( "create table alarmhistory ( uuid varchar( 50 ),time >>INTEGER, guizheno INTEGER,ip varchar( 30 ),name TEXT, value TEXT, state >>TEXT, descr TEXT, type INTEGER, panbi INTEGER ,PRIMARY KEY ( uuid, type >>) )" ) >> >>def getData( ): >>cx = sqlite.connect( "alarm.sqlite" ) >>cu = cx.cursor() >>cu.execute("select * FROM alarmhistory") >>data = {} >>count = 0 >>for uuid ,t, guizheno,ip,name , value , state , descr , type , panbi in >>cu.fetchall(): >>if type == 0: >>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "error" ) >>elif type == 1: >>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "resume" ) >>elif type == 2: >>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "change" ) >>elif type == 3: >>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "delete" ) >> >>return data >> >>当我调用getData时发生下面的错误,alarm.sqlite文件是用c ++生成的,有的项 >>中有中文。 >>Traceback (most recent call last): >>File "AlarmTable.py", line 123, in ? >>run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) >>File "D:\work\python\run.py", line 157, in main >>app = RunApp(name, module, useShell) >>File "D:\work\python\run.py", line 47, in __init__ >>wx.App.__init__(self, redirect=False) >>File "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", >>line 5301, in __init__ >>self._BootstrapApp() >>File "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", >>line 4980, in _BootstrapApp >>return _core_.PyApp__BootstrapApp(*args, **kwargs) >>File "D:\work\python\run.py", line 75, in OnInit >>win = self.demoModule.runFrame(frame, frame, Log()) >>File "D:\work\python\AlarmTable.py", line 117, in runFrame >>win = SingleTablePanel.TablePanel(nb, "AlarmTable","DATA/"+dbname + >>"/HISTORY/DATA/ALARM.SQLITE",log) >>File "D:\work\python\SingleTablePanel.py", line 60, in __init__ >>self.datalist = self.__getData( ) >>File "D:\work\python\SingleTablePanel.py", line 35, in __getData >>return self.datatable.getData(); >>File "D:\work\python\AlarmTable.py", line 17, in getData >>tables = cu.fetchall() >>UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: >>invalid data >> >>请问怎样解决了这个问题 >> >>_______________________________________________ >>python-chinese list >>python-chinese at lists.python.cn >>http://python.cn/mailman/listinfo/python-chinese >> >> >> > > > > >------------------------------------------------------------------------ > >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050609/19dac175/attachment-0001.html
2005年06月09日 星期四 17:28
建议先使用pysqlite1.X版将数据卸出来,然后再使用pysqlite2写一个转换程序(主要是将中文转为unicode)装到数据库中去。 在 05-6-9,run_mei<run_mei at 163.com> 写道: > 用c++生成有,当然是用sqlite的c++库,否则我哪知道它的格式,而且是用sqlite2的c++接口库,我怎样进行 > 编码转换呢?谢谢! > > limodou 写道: > alarm.sqlite是用C++生成的?那是sqlite的格式吗?sqlite有自已的文件格式的,不是简单的文本文件。同时pysqlite2的字符串数据变成了unicode了,因此要注意编码转换。至于它保存在数据库中是什么编码,我猜可能是utf-8。 > > 在 05-6-9,run_mei<run_mei at 163.com> 写道: > > > 请问我写了一个读sqlite数据库的小程序 > import pysqlite2.dbapi2 as sqlite > import BTTime > import SingleTablePanel > > def createData(): > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute( "create table alarmhistory ( uuid varchar( 50 ),time > INTEGER, guizheno INTEGER,ip varchar( 30 ),name TEXT, value TEXT, state > TEXT, descr TEXT, type INTEGER, panbi INTEGER ,PRIMARY KEY ( uuid, type > ) )" ) > > def getData( ): > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute("select * FROM alarmhistory") > data = {} > count = 0 > for uuid ,t, guizheno,ip,name , value , state , descr , type , panbi in > cu.fetchall(): > if type == 0: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "error" ) > elif type == 1: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "resume" ) > elif type == 2: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "change" ) > elif type == 3: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "delete" ) > > return data > > 当我调用getData时发生下面的错误,alarm.sqlite文件是用c ++生成的,有的项 > 中有中文。 > Traceback (most recent call last): > File "AlarmTable.py", line 123, in ? > run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) > File "D:\work\python\run.py", line 157, in main > app = RunApp(name, module, useShell) > File "D:\work\python\run.py", line 47, in __init__ > wx.App.__init__(self, redirect=False) > File > "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", > line 5301, in __init__ > self._BootstrapApp() > File > "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", > line 4980, in _BootstrapApp > return _core_.PyApp__BootstrapApp(*args, **kwargs) > File "D:\work\python\run.py", line 75, in OnInit > win = self.demoModule.runFrame(frame, frame, Log()) > File "D:\work\python\AlarmTable.py", line 117, in runFrame > win = SingleTablePanel.TablePanel(nb, "AlarmTable","DATA/"+dbname + > "/HISTORY/DATA/ALARM.SQLITE",log) > File "D:\work\python\SingleTablePanel.py", line 60, in > __init__ > self.datalist = self.__getData( ) > File "D:\work\python\SingleTablePanel.py", line 35, in > __getData > return self.datatable.getData(); > File "D:\work\python\AlarmTable.py", line 17, in getData > tables = cu.fetchall() > UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: > invalid data > > 请问怎样解决了这个问题 > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > > ________________________________ > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- I like python! My Donews Blog: http://www.donews.net/limodou New Google Maillist: http://groups-beta.google.com/group/python-cn
2005年06月09日 星期四 18:48
我试了将c++中的字符串转换成utf-8的,存到数据库中仍然不行 limodou 写道: >建议先使用pysqlite1.X版将数据卸出来,然后再使用pysqlite2写一个转换程序(主要是将中文转为unicode)装到数据库中去。 > >在 05-6-9,run_mei<run_mei at 163.com> 写道: > > >>用c++生成有,当然是用sqlite的c++库,否则我哪知道它的格式,而且是用sqlite2的c++接口库,我怎样进行 >> 编码转换呢?谢谢! >> >> limodou 写道: >>alarm.sqlite是用C++生成的?那是sqlite的格式吗?sqlite有自已的文件格式的,不是简单的文本文件。同时pysqlite2的字符串数据变成了unicode了,因此要注意编码转换。至于它保存在数据库中是什么编码,我猜可能是utf-8。 >> >>在 05-6-9,run_mei<run_mei at 163.com> 写道: >> >> >> 请问我写了一个读sqlite数据库的小程序 >>import pysqlite2.dbapi2 as sqlite >>import BTTime >>import SingleTablePanel >> >>def createData(): >>cx = sqlite.connect( "alarm.sqlite" ) >>cu = cx.cursor() >>cu.execute( "create table alarmhistory ( uuid varchar( 50 ),time >>INTEGER, guizheno INTEGER,ip varchar( 30 ),name TEXT, value TEXT, state >>TEXT, descr TEXT, type INTEGER, panbi INTEGER ,PRIMARY KEY ( uuid, type >>) )" ) >> >>def getData( ): >>cx = sqlite.connect( "alarm.sqlite" ) >>cu = cx.cursor() >>cu.execute("select * FROM alarmhistory") >>data = {} >>count = 0 >>for uuid ,t, guizheno,ip,name , value , state , descr , type , panbi in >>cu.fetchall(): >>if type == 0: >>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "error" ) >>elif type == 1: >>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "resume" ) >>elif type == 2: >>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "change" ) >>elif type == 3: >>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "delete" ) >> >>return data >> >>当我调用getData时发生下面的错误,alarm.sqlite文件是用c ++生成的,有的项 >>中有中文。 >>Traceback (most recent call last): >>File "AlarmTable.py", line 123, in ? >>run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) >>File "D:\work\python\run.py", line 157, in main >>app = RunApp(name, module, useShell) >>File "D:\work\python\run.py", line 47, in __init__ >>wx.App.__init__(self, redirect=False) >>File >>"C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", >>line 5301, in __init__ >>self._BootstrapApp() >>File >>"C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", >>line 4980, in _BootstrapApp >>return _core_.PyApp__BootstrapApp(*args, **kwargs) >>File "D:\work\python\run.py", line 75, in OnInit >>win = self.demoModule.runFrame(frame, frame, Log()) >>File "D:\work\python\AlarmTable.py", line 117, in runFrame >>win = SingleTablePanel.TablePanel(nb, "AlarmTable","DATA/"+dbname + >>"/HISTORY/DATA/ALARM.SQLITE",log) >>File "D:\work\python\SingleTablePanel.py", line 60, in >>__init__ >>self.datalist = self.__getData( ) >>File "D:\work\python\SingleTablePanel.py", line 35, in >>__getData >>return self.datatable.getData(); >>File "D:\work\python\AlarmTable.py", line 17, in getData >>tables = cu.fetchall() >>UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: >>invalid data >> >>请问怎样解决了这个问题 >> >>_______________________________________________ >>python-chinese list >>python-chinese at lists.python.cn >>http://python.cn/mailman/listinfo/python-chinese >> >> >> >> >> ________________________________ >> >>_______________________________________________ >>python-chinese list >>python-chinese at lists.python.cn >>http://python.cn/mailman/listinfo/python-chinese >> >> >> >>_______________________________________________ >>python-chinese list >>python-chinese at lists.python.cn >>http://python.cn/mailman/listinfo/python-chinese >> >> >> >> >> > > > > >------------------------------------------------------------------------ > >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050609/decc735e/attachment.html
2005年06月09日 星期四 19:47
到底是不是使用utf-8存的我只是猜测,还是使用pysqlite2来进行插入吧。别用C++来做。 在 05-6-9,run_mei<run_mei at 163.com> 写道: > 我试了将c++中的字符串转换成utf-8的,存到数据库中仍然不行 > > limodou 写道: > 建议先使用pysqlite1.X版将数据卸出来,然后再使用pysqlite2写一个转换程序(主要是将中文转为unicode)装到数据库中去。 > > 在 05-6-9,run_mei<run_mei at 163.com> 写道: > > > 用c++生成有,当然是用sqlite的c++库,否则我哪知道它的格式,而且是用sqlite2的c++接口库,我怎样进行 > 编码转换呢?谢谢! > > limodou 写道: > alarm.sqlite是用C++生成的?那是sqlite的格式吗?sqlite有自已的文件格式的,不是简单的文本文件。同时pysqlite2的字符串数据变成了unicode了,因此要注意编码转换。至于它保存在数据库中是什么编码,我猜可能是utf-8。 > > 在 05-6-9,run_mei<run_mei at 163.com> 写道: > > > 请问我写了一个读sqlite数据库的小程序 > import pysqlite2.dbapi2 as sqlite > import BTTime > import SingleTablePanel > > def createData(): > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute( "create table alarmhistory ( uuid varchar( 50 ),time > INTEGER, guizheno INTEGER,ip varchar( 30 ),name TEXT, value TEXT, state > TEXT, descr TEXT, type INTEGER, panbi INTEGER ,PRIMARY KEY ( uuid, type > ) )" ) > > def getData( ): > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute("select * FROM alarmhistory") > data = {} > count = 0 > for uuid ,t, guizheno,ip,name , value , state , descr , type , panbi in > cu.fetchall(): > if type == 0: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "error" ) > elif type == 1: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "resume" ) > elif type == 2: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "change" ) > elif type == 3: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "delete" ) > > return data > > 当我调用getData时发生下面的错误,alarm.sqlite文件是用c ++生成的,有的项 > 中有中文。 > Traceback (most recent call last): > File "AlarmTable.py", line 123, in ? > run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) > File "D:\work\python\run.py", line 157, in main > app = RunApp(name, module, useShell) > File "D:\work\python\run.py", line 47, in __init__ > wx.App.__init__(self, redirect=False) > File > "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", > line 5301, in __init__ > self._BootstrapApp() > File > "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", > line 4980, in _BootstrapApp > return _core_.PyApp__BootstrapApp(*args, **kwargs) > File "D:\work\python\run.py", line 75, in OnInit > win = self.demoModule.runFrame(frame, frame, Log()) > File "D:\work\python\AlarmTable.py", line 117, in runFrame > win = SingleTablePanel.TablePanel(nb, "AlarmTable","DATA/"+dbname + > "/HISTORY/DATA/ALARM.SQLITE",log) > File "D:\work\python\SingleTablePanel.py", line 60, in > __init__ > self.datalist = self.__getData( ) > File "D:\work\python\SingleTablePanel.py", line 35, in > __getData > return self.datatable.getData(); > File "D:\work\python\AlarmTable.py", line 17, in getData > tables = cu.fetchall() > UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: > invalid data > > 请问怎样解决了这个问题 > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > > ________________________________ > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > > > > ________________________________ > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- I like python! My Donews Blog: http://www.donews.net/limodou New Google Maillist: http://groups-beta.google.com/group/python-cn
2005年06月10日 星期五 16:33
我发现这样也不能执行 cx = sqlite.connect( "alarm.sqlite" ) cu = cx.cursor() cu.execute(unicode( 'insert into bb values( "人了在下面更清空文","若在下面更清要试图","要sssssssssssssssssssssssssss" ) ',"utf-8")) > 我试了将c++中的字符串转换成utf-8的,存到数据库中仍然不行 > > limodou 写道: > >>建议先使用pysqlite1.X版将数据卸出来,然后再使用pysqlite2写一个转换程序(主要是将中文转为unicode)装到数据库中去。 >> >>在 05-6-9,run_mei<run_mei at 163.com> 写道: >> >> >>>用c++生成有,当然是用sqlite的c++库,否则我哪知道它的格式,而且是用sqlite2的c++接口库,我怎样进行 >>> 编码转换呢?谢谢! >>> >>> limodou 写道: >>>alarm.sqlite是用C++生成的?那是sqlite的格式吗?sqlite有自已的文件格式的,不是简单的文本文件。同时pysqlite2的字符串数据变成了unicode了,因此要注意编码转换。至于它保存在数据库中是什么编码,我猜可能是utf-8。 >>> >>>在 05-6-9,run_mei<run_mei at 163.com> 写道: >>> >>> >>> 请问我写了一个读sqlite数据库的小程序 >>>import pysqlite2.dbapi2 as sqlite >>>import BTTime >>>import SingleTablePanel >>> >>>def createData(): >>>cx = sqlite.connect( "alarm.sqlite" ) >>>cu = cx.cursor() >>>cu.execute( "create table alarmhistory ( uuid varchar( 50 ),time >>>INTEGER, guizheno INTEGER,ip varchar( 30 ),name TEXT, value TEXT, state >>>TEXT, descr TEXT, type INTEGER, panbi INTEGER ,PRIMARY KEY ( uuid, type >>>) )" ) >>> >>>def getData( ): >>>cx = sqlite.connect( "alarm.sqlite" ) >>>cu = cx.cursor() >>>cu.execute("select * FROM alarmhistory") >>>data = {} >>>count = 0 >>>for uuid ,t, guizheno,ip,name , value , state , descr , type , panbi in >>>cu.fetchall(): >>>if type == 0: >>>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "error" ) >>>elif type == 1: >>>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "resume" ) >>>elif type == 2: >>>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "change" ) >>>elif type == 3: >>>data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "delete" ) >>> >>>return data >>> >>>当我调用getData时发生下面的错误,alarm.sqlite文件是用c ++生成的,有的项 >>>中有中文。 >>>Traceback (most recent call last): >>>File "AlarmTable.py", line 123, in ? >>>run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) >>>File "D:\work\python\run.py", line 157, in main >>>app = RunApp(name, module, useShell) >>>File "D:\work\python\run.py", line 47, in __init__ >>>wx.App.__init__(self, redirect=False) >>>File >>>"C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", >>>line 5301, in __init__ >>>self._BootstrapApp() >>>File >>>"C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", >>>line 4980, in _BootstrapApp >>>return _core_.PyApp__BootstrapApp(*args, **kwargs) >>>File "D:\work\python\run.py", line 75, in OnInit >>>win = self.demoModule.runFrame(frame, frame, Log()) >>>File "D:\work\python\AlarmTable.py", line 117, in runFrame >>>win = SingleTablePanel.TablePanel(nb, "AlarmTable","DATA/"+dbname + >>>"/HISTORY/DATA/ALARM.SQLITE",log) >>>File "D:\work\python\SingleTablePanel.py", line 60, in >>>__init__ >>>self.datalist = self.__getData( ) >>>File "D:\work\python\SingleTablePanel.py", line 35, in >>>__getData >>>return self.datatable.getData(); >>>File "D:\work\python\AlarmTable.py", line 17, in getData >>>tables = cu.fetchall() >>>UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: >>>invalid data >>> >>>请问怎样解决了这个问题 >>> >>>_______________________________________________ >>>python-chinese list >>>python-chinese at lists.python.cn >>>http://python.cn/mailman/listinfo/python-chinese >>> >>> >>> >>> >>> ________________________________ >>> >>>_______________________________________________ >>>python-chinese list >>>python-chinese at lists.python.cn >>>http://python.cn/mailman/listinfo/python-chinese >>> >>> >>> >>>_______________________________________________ >>>python-chinese list >>>python-chinese at lists.python.cn >>>http://python.cn/mailman/listinfo/python-chinese >>> >>> >>> >>> >>> >> >> >> >> >>------------------------------------------------------------------------ >> >>_______________________________________________ >>python-chinese list >>python-chinese at lists.python.cn >>http://python.cn/mailman/listinfo/python-chinese >> >> > >------------------------------------------------------------------------ > >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050610/07642932/attachment.html
2005年06月10日 星期五 16:56
是空表吗?同时是使用pysqlite2吗?还是写一个完整的程序测试一下吧,最好连建库的程序都有了。 在 05-6-10,run_mei<run_mei at 163.com> 写道: > 我发现这样也不能执行 > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute(unicode( 'insert into bb values( > "人了在下面更清空文","若在下面更清要试图","要sssssssssssssssssssssssssss" ) > ',"utf-8")) > > > > > 我试了将c++中的字符串转 换成utf-8的,存到数据库中仍然不行 > > > limodou 写道: > 建议先使用pysqlite1.X版将数据卸出来,然后再使用pysqlite2写一个转换程序(主要是将中文转为unicode)装到数据库中去。 > > 在 05-6-9,run_mei<run_mei at 163.com> 写道: > > > 用c++生成有,当然是用sqlite的c++库,否则我哪知道它的格式,而且是用sqlite2的c++接口库,我怎样进行 > 编码转换呢?谢谢! > > limodou 写道: > alarm.sqlite是用C++生成的?那是sqlite的格式吗?sqlite有自已的文件格式的,不是简单的文本文件。同时pysqlite2的字符串数据变成了unicode了,因此要注意编码转换。至于它保存在数据库中是什么编码,我猜可能是utf-8。 > > 在 05-6-9,run_mei<run_mei at 163.com> 写道: > > > 请问我写了一个读sqlite数据库的小程序 > import pysqlite2.dbapi2 as sqlite > import BTTime > import SingleTablePanel > > def createData(): > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute( "create table alarmhistory ( uuid varchar( 50 ),time > INTEGER, guizheno INTEGER,ip varchar( 30 ),name TEXT, value TEXT, state > TEXT, descr TEXT, type INTEGER, panbi INTEGER ,PRIMARY KEY ( uuid, type > ) )" ) > > def getData( ): > cx = sqlite.connect( "alarm.sqlite" ) > cu = cx.cursor() > cu.execute("select * FROM alarmhistory") > data = {} > count = 0 > for uuid ,t, guizheno,ip,name , value , state , descr , type , panbi in > cu.fetchall(): > if type == 0: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "error" ) > elif type == 1: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "resume" ) > elif type == 2: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "change" ) > elif type == 3: > data[ ( uuid, type ) ] = ( BTTime( t ), ip,name, descr , "delete" ) > > return data > > 当我调用getData时发生下面的错误,alarm.sqlite文件是用c ++生成的,有的项 > 中有中文。 > Traceback (most recent call last): > File "AlarmTable.py", line 123, in ? > run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) > File "D:\work\python\run.py", line 157, in main > app = RunApp(name, module, useShell) > File "D:\work\python\run.py", line 47, in __init__ > wx.App.__init__(self, redirect=False) > File > "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", > line 5301, in __init__ > self._BootstrapApp() > File > "C:\Python24\Lib\site-packages\wx-2.5.3-msw-unicode\wx\_core.py", > line 4980, in _BootstrapApp > return _core_.PyApp__BootstrapApp(*args, **kwargs) > File "D:\work\python\run.py", line 75, in OnInit > win = self.demoModule.runFrame(frame, frame, Log()) > File "D:\work\python\AlarmTable.py", line 117, in runFrame > win = SingleTablePanel.TablePanel(nb, "AlarmTable","DATA/"+dbname + > "/HISTORY/DATA/ALARM.SQLITE",log) > File "D:\work\python\SingleTablePanel.py", line 60, in > __init__ > self.datalist = self.__getData( ) > File "D:\work\python\SingleTablePanel.py", line 35, in > __getData > return self.datatable.getData(); > File "D:\work\python\AlarmTable.py", line 17, in getData > tables = cu.fetchall() > UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1: > invalid data > > 请问怎样解决了这个问题 > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > > ________________________________ > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > > > > ________________________________ > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > ________________________________ > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > > > -- I like python! My Donews Blog: http://www.donews.net/limodou New Google Maillist: http://groups-beta.google.com/group/python-cn
Zeuux © 2025
京ICP备05028076号