0

This worked earlier, some of my rows have valid entries, but a lot of them don't...

def setLength(vid, seconds):
    db_conn.execute("UPDATE Videos SET length= '" + str(seconds//1) + "' WHERE ID='"+str(vid)+"';")
    db_conn.commit()
    result = my_cursor.execute("SELECT length, title FROM Videos WHERE ID = " + "'" + str(vid) + "';")
    for row in result:
        print(vid, row[0])
    print("gets here")

gives the output:

gets here

even when I run it with a valid ID.

Edit: I can use the same ID to get the title column from that row, but trying to UPDATE the length column just leaves the cell empty.

Bridget G
  • 1
  • 2
  • Are any errors reported? What do you mean by 'some rows have valid entries, but others dont`. What makes them invalid? – TeddyBearSuicide Jun 05 '21 at 22:31
  • I think that you're expecting the function to print a row inside your `for` loop, but it is not printing that row. So, I think you have the same problem without the `db_conn` statements. You don't have an update problem. The record `ID` is not in the database behind `my_cursor`. – user212514 Jun 05 '21 at 22:33
  • See edit. The ID is definitely in the database because I can use it to read the video title. Some videos have lengths for some reason, and others are just an empty string. I can’t make heads or tails of it. – Bridget G Jun 06 '21 at 08:38
  • Does it work if you use parameter substitution, as described in the answers to [this question](https://stackoverflow.com/q/902408/5320906)? Note that sqlite uses `?` as a placeholder, not `%s`. For example `dbconn.execute("UPDATE Videos SET length= ? WHERE ID= ?", (seconds//1, vid))` (and similar for the select) – snakecharmerb Jun 06 '21 at 08:56

1 Answers1

0

Probably extremely specific but the reason it wasn't updating was because when inserting into the table some of the IDs were converted to scientific notation. Those that were would have their titles found, because the function I used for the title search was sensitive to that. My bad.

ID Title Filename Length
1.72986707541665e+ untitled 253c95c4b27116e.mp None
263857279641976794 ShowIWanttoWatchEp Videos/ShowIWantto 1144.0
185690842836020994 ShowIWanttoWatchEp Videos/ShowIWantto 1174.0
1.7317732968119e+6 untitled 9231941.m4v None
212666122173993805 ShowIWanttoWatchEp Videos/ShowIWantto 995.0
1.69406306986304e+ untitled hls-1.mp4 None
877482402128334556 ShowIWanttoWatchEp Videos/ShowIWantto 1214.0
Bridget G
  • 1
  • 2