If I have a statement like so:
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.
Retrieving the hair_color will be u'None' rather than a NoneType.
I know I can just do a simple check to see if it’s equal to a unicode “None” but rather than specifying this condition, is there a way to tell python that I want fields that have “None” to be replaced with a NoneType when I do a fetchone() or fetchall()?
MYTABLE is (Id INTEGER PRIMARY KEY, name TEXT, age INTEGER, hair_color TEXT)
Sorry guys, I just figured it out.
As it turns out, I have to explicitly tell sqlite3 that I want python to automatically convert between types.
So the solution was to do this: