I have an app that uses a database. One of my users claims that all his data is lost. When he sends me a copy of his database, it is just the schema with no data in it. User is sure he is using the correct computer, correct Mac User Account and has not reformatted/deleted/partitioned his drive etc
This app has been used since 2015, and nobody else has made this claim, but I am worried. My method for creating the database is largely copied from the Learning Xojo guide that I read when I was new. Pretty standard stuff, I would have thought.
My app looks for a folder within the Application Support folder:
dim f as FolderItem = SpecialFolder.ApplicationData f = f.child("MyAppFolder") if f.Exists = false then // does the folder exist ? f.CreateAsFolder() // then create it end if
It then looks for the database file within that folder:
MyDBFile = SpecialFolder.ApplicationData.Child("MyAppFolder").Child("MyAppDb.dbs") If MyDBFile.Exists Then //found it? MyDatabase = New SQLiteDatabase MyDatabase.DatabaseFile = MyDBFile If MyDatabase.Connect() Then Return True End If Else Return CreateDatabase //no existing database - so create it End If
The CreateDatabase method looks like this
MyDBFile = SpecialFolder.ApplicationData.Child("MyAppFolder").Child("MyAppDb.dbs") //get the database from stored database If MyDBFile <> Nil Then //if the database exists on the drive... MyDatabase = New SQLiteDatabase //instantiate MyDatabase as a new sqlite database MyDatabase.DatabaseFile = MyDBFile //load MyDatabase with the existing database If MyDatabase.CreateDatabaseFile() Then //if we can create (or connect if it exists) to the database If MyDatabase.Connect() Then //connect CreateSchema // goes on to write tables etc Return True Else Return False End If Else Return False End If End If
I admit I am a little sketchy when it comes to the difference between
If folderitem <> nil
Is there any way this code can overwrite an existing database and thereby delete somebody's existing data?