为什么将datetime类型插入Sqlite数据库后会丢失?
import sqlite3, datetime
dbconn = sqlite3.connect(':memory:')
c = dbconn.cursor()
c.execute('create table mytable(title text, t timestamp)')
c.execute('insert into mytable (title, t) values (?, ?)', ("hello2", datetime.datetime(2018,3,10,12,12,00)))
c.execute("select * from mytable")
for a in c.fetchall():
print a[0] # hello2
print type(a[0]) # <type 'unicode'>
print a[1] # 2018-03-10 12:12:00
print type(a[1]) # <type 'unicode'>
插入和查询后,datetime类型不应该改变吗?
注:由于这个问题,我浪费了将近一个小时的时间,所以现在我将使用“自问自答-分享您的知识,问答式”SO功能发布答案。
注意:这不是邻居问题的重复,因为它不涉及datetime如何存储/检索的问题。