Copy a file to app data folder in 2019r2. Something change?

Hi. I’ve been using the following code in my projects for several years. I am working on an update. Everything worked well on the Mac, but the below code does not seem to work on Windows any longer. The old database file I am trying to replace is still the old one and not the new one. Has something changed in 2019r2.1? I know there were a lot of changes starting in r2, and I have not gone through and converted anything over yet with the new naming convention

This checks the table version number, which I increment manually when I make changes to this db. If the versionNo is less than the the new version, then this deletes the old and replaces with the new which is in the Resources folder

[code]dim sql as String = “SELECT * FROM DBversion”
Dim rs as RecordSet = db.SQLSelect(sql)

if rs.Field(“versionNo”).IntegerValue < 33 then
Dim dbFile As FolderItem

db = new SQLiteDatabase

'finds the database in the Data folder
dbFile = SpecialFolder.ApplicationData.Child(“com.visualveggies.rdexamstudysuite”).Child(“examRDDTR.sqlite”)

db.DatabaseFile = dbFile

'delete old db
dbFile.Delete

'copy new db
DoesExamTableExist

ReconnectToDB
end if
[/code]

What’s not working about it? What kind of errors do you get? What do you expect to happen?

The old file hasn’t been closed before you try to delete it, in this code.

Hi Thom. Mac is working as expected. On Windows, I have files located in the Roaming folder, one of which is a filled database. In this past update to the app, I made some changes to the filled db file and want to replace it. I changed the version number in the db table so the app will recognize that there is a newer version of the db file. What should happen on first run is that the app checks a method IsDBNewer. It should see that the new version should be 33 in the code above. If this is true, then the old db file in the Roaming folder is deleted, and the updated db file is then copied over to the folder in place of the old one.

In the Build Settings in Xojo, I have under macOS and Windows a CopyFiles with the db file present. The CopyFiles is under the Build (gear icon) under each. When I just built the app and tested the update on my Mac and Windows computers, the Mac did have the newer db file present (worked as expected), but on Windows, I can tell the older db file is still present (did not get replaced) based on the date of the file (was October 23, 2019… the last update to the file before today’s update) and the content in the app is not reflective of the new content

I recently updated Xojo to 2019r2.1, so am wondering if something has changed with the method I have above in the code that affects Windows. Again, Mac worked like a charm

After I build the app, I have to rename the Resources folder to “Resources”. When it builds, it generates the Resource folder to be “RD Exam Study Suite Resources”. This was something that changed about 2 years or so ago in Xojo. I can confirm the new db file is present in the Resources folder, but it is just not copying over

@Jeff Tullin is that something new? I have not done this in the past

Here is the code to copy the new dbfile. Does this look ok? This is the same code I’ve used for years and has not changed. Anything different here?

[code]// Find original DB file
Dim sourceDB As FolderItem
#If TargetMacOS
sourceDB = app.ExecutableFile.Parent.Parent.Child(“Resources”).Child(“examRDDTR.sqlite”)
#elseif TargetWindows
sourceDB = GetFolderItem(“Resources”).Child(“examRDDTR.sqlite”)
#endif

If sourceDB <> Nil And sourceDB.Exists Then
// Create destination folder
Dim appData As FolderItem = SpecialFolder.ApplicationData
Dim appFolder As FolderItem = appData.Child(“com.visualveggies.rdexamstudysuite”)
appFolder.CreateAsFolder

// Copy DB to destination
sourceDB.CopyFileTo(appFolder)
End If[/code]

Your Windows code doesn’t account for the fact that Resources changes names in debug mode. Are you running in debug mode when you see these problems? You don’t have a condition to announce the error if the file does not exist (which it won’t in debug).

You should definitely replace that top bit with dim fSourceDB as FolderItem = SpecialFolder.Resources.Child("examRDDTR.sqlite")

Thanks Tim. It wasn’t a test during debug. It was after the build. I am aware that the Resources folder is different in debug mode. I don’t test the copy file piece until after the project is built

Is this referring to the code below? Is your suggestion to use this one liner in place of the #if TargetMacOS… #elseif TargetWindows?

[code]// Find original DB file
Dim sourceDB As FolderItem
#If TargetMacOS
sourceDB = app.ExecutableFile.Parent.Parent.Child(“Resources”).Child(“examRDDTR.sqlite”)
#elseif TargetWindows
sourceDB = GetFolderItem(“Resources”).Child(“examRDDTR.sqlite”)
#endif

If sourceDB <> Nil And sourceDB.Exists Then
// Create destination folder
Dim appData As FolderItem = SpecialFolder.ApplicationData
Dim appFolder As FolderItem = appData.Child(“com.visualveggies.rdexamstudysuite”)
appFolder.CreateAsFolder

// Copy DB to destination
sourceDB.CopyFileTo(appFolder)
End If[/code]

Yes, that way you’ll always be sure you’re getting the Resources folder from the framework.

I would also add a failure message, an else to your if sourceDB.Exists check. At the very least it would help with debugging the issue.

After a lot of testing, I found that the use of the db.Close and omitting the following from my first part of the post may have done the trick

db = new SQLiteDatabase db.DatabaseFile = dbFile

I also changed the one part per Tim’s suggestion of condensing the #if Target… into one line.

Being that I was making a lot of changes at a time, building, testing, going back, and spending about 3 hours on this, I’m not sure exactly what it was that did the trick. The above code I have with the db = new SQL… I’m not sure where that came from years ago, if it does anything, and if it was the cause of the issue

Who knows. It’s fixed, and that’s what matters. Thank you all for chiming in