我正在读取sqlite3数据库中的记录.数据作为TEXT存储在数据库中,但是我正在获取缓冲区(使用Unicode并且我找不到任何东西似乎将它们转换为可用文本(Unicode或不是))
为了使它工作,我必须CAST到SQL查询中的TEXT.
我错过了什么?
举个例子:
import sqlite3
con = sqlite3.connect('D:\\test.db' )
cur = con.cursor()
print "Before CAST"
cur.execute('SELECT Type FROM \"Internet Explorer History\" ')
row = cur.fetchone()
print row
print row[0]
print type(row[0])
print str(row[0])
print str(row[0]).encode('utf-8')
print "----------------"
print "After CAST"
cur.execute('SELECT CAST( Type as TEXT) FROM \"Internet Explorer History\" ')
row = cur.fetchone()
print row
print row[0]
print type(row[0])
print str(row[0])
print str(row[0]).encode('utf-8')
Run Code Online (Sandbox Code Playgroud)
这给出了以下输出:
Before CAST
(<read-write buffer ptr 0x0276A890, size 24 at 0x0276A870>,)
C a c h e R e c o r d
<type 'buffer'>
C a c h e R e c o r d
C a c h e R e c o r d
----------------
After CAST
(u'Cache Record',)
Cache Record
<type 'unicode'>
Cache Record
Cache Record
Run Code Online (Sandbox Code Playgroud)
注意:CAST之前的"缓存记录"字母之间的空格为空.
谢谢.
归档时间: |
|
查看次数: |
3355 次 |
最近记录: |