My Database is being deleted after each restart of my code. How can I fix it?
(1) By anonymous on 2021-07-13 13:22:00 [link] [source]
Hi, I'm making a discord bot and I want it to have a custom prefix feature. I've decided to use sqlite for it. And it's kind of working, but each time I restart it - all the data from my database is gone.
Why is it happening?
(2) By Richard Hipp (drh) on 2021-07-13 13:28:34 in reply to 1 [link] [source]
What filename are you using for the database?
(3) By Ryan Smith (cuz) on 2021-07-13 13:40:15 in reply to 1 [link] [source]
This must be a contender for the gold-medalist in the least-specific-questions category.
Your question sounds like this to me:
I've decided to learn to drive, and use a car for it. I'm kinda doing ok so far, but every time I look in my garage, there is no car there.
Why is it happening?
We could spend all day guessing.
Could you tell us please:
- Which operating system,
- What is the file path (including name) of the SQLite that is opened (and then magically disappearing),
- How are you opening it,
- Are you using a wrapper, library, compiled-in SQLite, or something else?
- Can you open the file with another SQLite tool or the CLI? At least before it disappears?
- Have you ever seen the file appear?
We are not politicians, we can't inform public opinion on the skantest of suggestions, we need hard evidence and understanding to form ideas or suggestions.
(4) By Larry Brasfield (larrybr) on 2021-07-13 13:48:21 in reply to 1 [link] [source]
I'm not willing to make many guesses, or spend much of my day making them, but I do have a couple:
Perhaps you are using :memory: as your database name. Those DBs are assured a lifetime not extending beyond closing the connection.
Perhaps your tables are being created as temporary ones. Without seeing your DDL, this is among the prime candidates.
I could go on, but that's enough guessing for today.
(5) By Harald Hanche-Olsen (hanche) on 2021-07-14 07:17:42 in reply to 1 [source]
I can play the guessing game too: A transaction was not closed before exiting. I think some language bindings (python?) open a transaction automatically, but leaves it up to the user to commit it.
(6) By Simon Slavin (slavin) on 2021-07-14 12:47:37 in reply to 1 [link] [source]
Does your bot neatly close the database connection when it stops, or is it just crashing ?
When is the database file being deleted, if it is being deleted at all ? In other words, does the database file exist in storage
- while your bot is running ?
- after your bot has stopped ?
If you use the same bot to open a text file in the same folder, and append text to it each time it starts up, do you actually get one additional piece of text every time it starts up ?