I have some Python code that inserts integer values to a database, as below:
if value: #if it's not None
self._conn.execute(
'''UPDATE table_name SET value_holder = ? WHERE
key_one = ? AND key_two = ? and key_three = ?''',
[value, key_one, key_two, key_three])
If I run that query, table will contain empty fields, or NULL fields whenever value is 0. If I change the query setup to below, however, the fields will contain 0 instead of NULL.
if value==0:
self._conn.execute(
'''UPDATE table_name SET value_holder = ? WHERE
key_one = ? AND key_two = ? and key_three = ?''',
[0, key_one, key_two, key_three])
elif value: #if it's not None
self._conn.execute(
'''UPDATE table_name SET value_holder = ? WHERE
key_one = ? AND key_two = ? and key_three = ?''',
[value, key_one, key_two, key_three])
How is it possible that inserting 0 vs inserting value (when value==0) results in different values in the database?
SQLite version 3.3.6.
if valuewill not be true whenvalueis 0.if value: #if it's not None. That's not how you check forNone.if value is not Noneis how you do it. docs.python.org/2/library/stdtypes.html#truth-value-testingNone, but rather 0 evaluates toFalse