Search code examples
nsis

sqlite database file not deleted after application uninstall


I have written desktop windows application in Qt. I have used sqlite as my database for storing app related data. I have deployed the binaries by making a installer using NSIS Quick Script Generator. Everything works fine until I uninstall the application. When I uninstall the application, it seems like all the files are deleted, but in reality the database file(.sqlite) is not deleted, though it is not visible directly. I came to know this, when i again installed the application and the application began to use the old app's data. Then i used DB Browser for Sqlite to find out that the file still exists. Now i can delete the file by using that app. But my problem is the sqlite file should be deleted automatically and not by user manually using a third party app. Am I doing any wrong here? Is there any method to avoid this?


Solution

  • If NSIS is not putting the file in place itself (your program is creating it), it will not be creating a delete command to remove it - how is it supposed to know about it? You need to put a manual delete command in the NSIS script for any files you need deleted that the quick script generator does not know about.

    In the generated NSIS script, in the uninstall section, you need to add a command that will be something like "Delete PATH\Database.db". Change the Database.db to what your name for the database is. Change the PATH to the correct path to where the file will be. You can use NSIS constants to help set the path. Some possible constants are @INSTDIR (the install directory) $DOCUMENTS (the base documents folder), $APPDATA (the base appdata directory). So if your database is called foodata.db in a mysqliteapp folder in appdata, then the command would be

    Delete $APPDATA\mysqliteapp\foodata.db