如果我有这样的声明:
cursor.execute("INSERT INTO MYTABLE(name, age, hair_color) VALUES (?, ?, ?)" , ("Alice", 24, None))
cursor.execute("SELECT * FROM MYTABLE WHERE Id=?", (1,))
print cursor.fetchone()[2] is None # This is false! I want this to be true.
检索 hair_color 将u'None'
不是NoneType
.
我知道我可以做一个简单的检查,看看它是否等于一个 unicode “None”,而不是指定这个条件,有没有办法告诉 python 我想要用 NoneType 替换具有“None”的字段我做一个 fetchone() 还是 fetchall()?
MYTABLE 是(Id INTEGER PRIMARY KEY, name TEXT, age INTEGER, hair_color TEXT)