SQLite File disappears - deleted

Trying to connect to an sqlite file in OSX Maverick and Yosemite the file gets deleted.

The following code works on Windows 7 with the same exisiting sqlite file, please advise a very frustrated user of XoJo.

Dim db As New SQLiteDatabase

Dim currentFolder As FolderItem
currentFolder = GetFolderItem("")
MsgBox(currentFolder.Name)

Dim dbFile As FolderItem
dbFile = GetFolderItem(“roster.sqlite”)

MsgBox(dbFile.Name)

If dbFile <> Nil Then
db.DatabaseFile = dbFile
MsgBox(“Database file exists”)
End If

''disappears at this point ???

If db.Connect Then
MsgBox(“Connected to database successfully!”)
Else
MsgBox("DB Connection Error: " + db.ErrorMessage)
End If

Dim sql As String
sql = “SELECT * FROM staff”

Dim data As RecordSet
data = db.SQLSelect(sql)

If db.Error Then
MsgBox("DB Error: " + db.ErrorMessage)
Return
End If

If data <> Nil Then
While Not data.EOF
ListBox1.AddRow(data.Field(“lname”).StringValue)
data.MoveNext
Wend
data.Close
End If

This part

If dbFile <> Nil Then db.DatabaseFile = dbFile MsgBox("Database file exists") End If

is not correct. You need to actually check the file exists, you’re only checking that it can exist.

If dbFile <> Nil Then If dbFile.Exists Then db.DatabaseFile = dbFile MsgBox("Database file exists") End If End If

Also be aware that when running in debug mode the current folder & it’s contents are deleted at the end of the debug session.

Thanks Wayne does not matter either way, if you have the following, the result are the same a vanishing database after the dbFile statements, before the programs end. Interesting enough it only displays MsgBox contents when dbfFile <> Nil, it seems to jump over if you have dbFile.Exists. Will try it out of debug mode.

If dbFile.Exists Then
db.DatabaseFile = dbFile
MsgBox(“Database file exists”)
End If

or

If dbFile.Exists And dbFile <> Nil Then
db.DatabaseFile = dbFile
MsgBox(“Database file exists”)
End If

or

as you suggested.

Seems to work as stand alone and not in debug mode.

In debug mode, you are running in a freshly created folder, which would not contain your database file. You can use code like

#if DebugBuild then
   dbFile = GetFolderItem("").Parent.Child("roster.sqlite")
#else
   dbFile = GetFolderItem("roster.sqlite")
#endif

Thank you Tim. Although I was placing the file once the folder was created initially, each time I ran it, the folder must be recreating itself, even though I replace the file. Works with your code.

Yes, the debug folder is deleted every time.