I’ve got a Xojo Web app working very well right now. It loads in a browser, accepts data entry, exports the entered data to a CSV file and emails that CSV file. I now want to attach a SQLite database to it for data storage. In the Session’s Open event, I have this simple code to see if it sees the new database file:
Dim dbFile As FolderItem
dbFile = GetFolderItem("mydatabase.sqlite")
If dbFile.Exists = False Then
MsgBox "No database file."
End If
Though mydatabase.sqlite does indeed exist in the same folder as the project, when I Run the project, it always reports (via Msg Box you see there) the database doesn’t exist. What might I not understand here? It must be something very fundamental.
Well, that certainly explains my frustration at trying to get this to work. Thanks, Parnell. So it sounds like my best bet is to just load the database and test to see if it is connected.
I think the LR is in error. Maybe there was confusion with GetOpenFolderItem which does not exist in Web.
I just tested, GetFolderItem works just fine.
However, in the code posted, the code assumes the file is next to the executable, which may not be the case for a Windows debug, and also the type of path is not specified. That probably explains.
Instead of placing the file manually, use a CopyFile build step to copy the file in the executable directory. That way it should work in debug run as well.
Dim currentFolder As FolderItem
currentFolder = GetFolderItem("")
MsgBox(currentFolder.Name)
and indeed found the current folder was the window.debug folder, so that was the problem. I ended up placing my database file in my Documents folder for now, and use this:
Dim dbFile As FolderItem
dbFile = SpecialFolder.Documents.Child("mydatabase.sqlite")
If dbFile.Exists = False Then
MsgBox "No database file."
End If
and that works fine. When I finally deploy this, I can change the code to look in the executable’s folder again.
[quote=247182:@Tim Parnell]The first thing I do when “somethings not working” is I check the docs to see how it works.
Silly me for assuming the documentation would be correct :P[/quote]
It’s alright. We all do. Except without reading the docs, I had used GetFolderItem before in Xojo Web, so I knew it worked
42550 - (Documentation) GetFolderItem works perfectly in Web
Status: Needs Review Rank: Not Ranked Product: Xojo Category: N/A
Ok. This seems to work. I just give a full path to the database file, which lives in the folder housing the executable, like this
Dim dbFile As FolderItem
dbFile = GetFolderItem("/Users/ralph/Dropbox/Xojo Projects/mydatabase.sqlite", FolderItem.PathTypeShell)
If dbFile.Exists = False Then
MsgBox "No database file found."
Session.Quit
End If
It fails if I don’t have FolderItem.PathTypeShell in there, as Michel suggested.
Actually, since I program on a Mac but the project might end up on a nonMac server (very likely), I changed it to this, assuming the database file is placed in the same folder as the executable:
If DebugBuild Then
dbFile = GetFolderItem("/Users/ralph/Dropbox/Xojo Projects/mydatabase.sqlite", FolderItem.PathTypeShell)
Else
dbFile = GetFolderItem("mydatabase.sqlite")
End If
If dbFile.Exists = False Then
MsgBox "No database file found."
Session.Quit
End If