Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.delete_where() returns [] when it should return self #315

Closed
simonw opened this issue Aug 10, 2021 · 1 comment
Closed

.delete_where() returns [] when it should return self #315

simonw opened this issue Aug 10, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Aug 10, 2021

If the table doesn't exist it should still return self, not []:

def delete_where(self, where=None, where_args=None):
if not self.exists():
return []
sql = "delete from [{}]".format(self.name)
if where is not None:
sql += " where " + where
self.db.execute(sql, where_args or [])
return self

Spotted with mypy while working on #312.

@simonw simonw added the bug Something isn't working label Aug 10, 2021
@simonw
Copy link
Owner Author

simonw commented Aug 10, 2021

Or should we raise an error if you attempt to call .delete_where() on a table that doesn't exist?

@simonw simonw closed this as completed in 6155da7 Aug 10, 2021
simonw added a commit that referenced this issue Aug 10, 2021
simonw added a commit that referenced this issue Aug 10, 2021
NotJoeMartinez added a commit to NotJoeMartinez/yt-fts that referenced this issue May 29, 2023
sqlite_utils won't commit changes when deleting records in
`delete_channel`, might be something to do with the triggers added by
full text search.

Seems to be a known issue with the package
- simonw/sqlite-utils#315
- simonw/sqlite-utils#159

It doesn't seem to have a problem effecting the rows within the function
but the changes don't commit.
```python
    db = Database(db_name)
    cur  = db.execute(f"DELETE FROM Channels WHERE channel_id = ?", [channel_id])
    print(f"channels: {cur.rowcount}")
    cur = db.execute(f"DELETE FROM Subtitles WHERE video_id IN (SELECT video_id FROM Videos WHERE channel_id = ?)", [channel_id])
    print(f"subs: {cur.rowcount}")
    cur = db.execute(f"DELETE FROM Videos WHERE channel_id = ?", [channel_id])
    print(f"vids: {cur.rowcount}")

    # check if effectively deleted
    cur = db.execute(f"SELECT * FROM Channels WHERE channel_id = ?", [channel_id])
    print("channels after: ", cur, cur.fetchall())
    cur = db.execute(f"SELECT * FROM Videos WHERE channel_id = ?", [channel_id])
    print("Vids after", cur, cur.fetchall())
    cur = db.execute(f"SELECT * FROM Videos WHERE channel_id = ?", [channel_id])
```

other thing I tried:
```python
    db = Database(db_name)
    db["Channels"].delete_where("channel_id = ?", [channel_id])
    db["Subtitles"].delete_where("video_id IN (SELECT video_id FROM Videos WHERE channel_id = ?)", [channel_id])
    db["Videos"].delete_where("channel_id = ?", [channel_id])
```

Anyway there doesn't seem to be any issues with using python sqlite3 for
the delete operations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant