简体   繁体   中英

SQLite database returning two different values for the same column

I'm currently making a NodeJS application and I'm using SQLite as the backend database. I've run into a problem when trying to soft-delete entries in a table. When I use the application to change the 'deleted' attribute, the changes appear in the SQLite CLI, but the application still displays each record as not deleted. These are the steps I use to test the application and database:

  1. In SQLite CLI, call the createDB.sql script to delete all tables and set them up again.
  2. Call the populateDB.sql script to input test data into each of the tables
  3. Check in SQLite CLI that the records are correct (SELECT id, deleted FROM table1;)
  4. Check in application console that records are correct
  5. In the application, change deleted attribute for a single entry
  6. Output entry to console Console shows entry not deleted
  7. In the application, change deleted attribute for all entries
  8. Output entry to console Console shows entries not deleted
  9. Check in SQLite CLI that the records are correct Output shows deleted attribute has changed for all records
  10. Output to application console the deleted attribute Still shows all entries are not deleted

These are the steps I have take to try and resolve the issue:

  • The data type for the deleted field is BOOLEAN. SQLite doesn't have a specific boolean type, but converts it to 1 or 0. I have tried using 1 and 0, 'true' and 'false' and even 'yes' or 'no' with no change in the behaviour.
  • I have tried this using both relative and absolute file paths for the database.
  • I added time delays to the application in case there is a delay updating the database.
  • I looked into file locking and learned that SQLite prevents two processes accessing a file concurrently. Makes sense. I killed my CLI process and tried to update the deleted attribute from the application only, making sure it was the only thing connected to the database, but got the same result.

After all this testing I believe the application is writing to the actual database file, but is reading from a cache. Is this an accurate conclusion? If so, how do I tell the application to refresh it's cache after executing an update query?

The application was writing to the database file, and reading from the same database, not a cache. However my query was set up to SELECT * FROM table1 LEFT OUTER JOIN table2 LEFT OUTER JOIN table3 LEFT OUTER JOIN table4 . table1, table2 and table3 all have a column called "deleted". I was updating table1.deleted but reading table2.deleted . I've amended the query to only select the columns I need from now on!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM