'Script Won't Write Updates to Database
I cannot get the following code to write to the database even though I get no errors when it runs. If the value of playCount is NULL and the value of lastPLayed is not NULL then I want to write the value of lastPlayed to NULL.
#!/usr/bin/env python3
import sqlite3
try:
conn = sqlite3.connect("/home/mp/Desktop/MyVideos116.db")
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
print("connected to database successfully")
query = "SELECT * from files"
playCount = cursor.execute(query).fetchall()
for i in playCount:
if (i["playCount"]) == None and (i["lastPlayed"] != None):
update = "UPDATE files SET playCount = ? WHERE lastPlayed = ?"
data = (None, None)
cursor.execute(update, data)
print (i["playCount"], i["lastPlayed"])
conn.commit()
# Closing the connection
conn.close()
except:
print("database error")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
