Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

node.js - 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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...