Hi to all…
I’m working on my little project and I need know how to refer to files stored into my project.
EXPLAIN:
I created manually a database with external application
from XoJo I insert it into my project (Insert > DataBase > Select SQLite Database…)
run my XojoApp
Now, I need refer to this file and to do a copy to a directory…
Is DataBase file is inside the executable XoJoApp file? Or where? And how can I refer to it?
You can put the database file wherever you want. For me, I create a database and store it in /Library/ApplicationSupport (on a Mac) as then any user can access the particular database file (which is what I want in my case). In other cases you might want to store it in the user library.
Rather than copy the database file into Xojo as you did, it’s better and easier just to reference it as a folder item like anything else. So in my case I do something like below. One database is stored in either the defined preferences folder (i.e.: PrefsFolder folder item) or it is a place where the User has selected to load the database (DBPath folder item).
MSDB is my database file object that is a property in a module in my app. SwitchDB is a second database I use that has a number of commands I parse to do specific communications in my app.
System.DebugLog("Setting up Database")
If DBPath <> Nil Then
DBFile = DBPath
Else
DBFile = PrefsFolder.Child("MSData.rsd")
End IF
MSDB = New SQLiteDatabase // Create the database object in code
MSDB.DatabaseFile = DBFile // Set the file name
MSDB.MultiUser = True
// Set up the database file
If DBFile <> Nil Then
If Not DBFile.Exists Then
CreateDatabaseFile // Call the method to create the file
System.DebugLog("Created Database")
End If
Call ConnectTo_AndSetup_Database // Method I have to connect to the database and make sure it has all the right tables.
//Now I have a second database I load that always sits in the folder where the application's executable resides
SwitchDB = New SQLiteDatabase
SwitchFile = GetFolderItem("switches.rsd")
SwitchDB.DatabaseFile = SwitchFile
System.DebugLog("Setting Switch Database")
If SwitchFile <> Nil Then
If Not SwitchDB.Connect() Then
MsgBox("There was a problem connecting to the switch database."+EndOfLine+EndOfLine+SwitchDB.ErrorMessage)
Quit
End If
End If