I have created a web app page and I would like to connect it to a SQLite database, I have inserted (as I found on this forum) in the Open event the following code:
// Create Database Object, theDB, globally
theDB = New SQLiteDatabase
// Give it a file if necessary
theDB.databaseFile = SpecialFolder.Documents.child(“myappdatabase.sqlite”)
// Connect to the database
If theDB.databaseFile.exists = True Then
// The database file already exists, so we want to connect to it,
// otherwise you’ll have to create the folderitem yourself
If theDB.Connect = False Then
MagBox(“Unable to connect to database”) // there was an error connecting to the database
Quit
End If
But he gives multiple errors, such as: theDB = ‘‘New SQLiteDatabase does not exists’’ and ‘‘theDB.databaseFile = SpecialFolder.Documents.child(“mydatabase.sqlite”)
does not exists’’
The database has been located in the same directory as my Xojo project file.
theDB.databaseFile = “ehealthdatabase.sqlite” I also tried: theDB.databaseFile = ehealthdatabase.sqlite, and theDB.databaseFile = (“ehealthdatabase.sqlite”)
I still get multiple errors. Which options do I have left ?
I get the following errors for This item does not exist (every sentence is an error):
theDB = New SQLiteDatabase
theDB.databaseFile = SpecialFolder.Documents.child(“myappdatabase.sqlite”)
If theDB.databaseFile.exists = True Then
If theDB.Connect = False Then
I think that this is due to the fact that ‘‘theDB’’ has not been declared. Can you please let me know how I can declare this ?
You might want to start with User Guide book 1 (Fundamentals) to get a handle on that, but you are either going to need to declare theDB as a property or a variable declared in the code.
I am trying to implement a database connection as explained in the ‘User Guide Book 3 Framework’ page 117 the topic ‘Connecting to a database’, according to this I have called a method with the following details:
Dim dbFile As FolderItem
dbFile =
SpecialFolder.ApplicationData.Child(“MyDatabase.sqlite”)
If dbFile.Exists Then
Dim db As New SQLiteDatabase
db.DatabaseFile = dbFile
If db.Connect Then
// Use the database
End If
End if?
When I run this I get 2 errors:
Syntax error: dbFile =
You must use the value returned by this function
SpecialFolder.ApplicationData.Child(Mydatabase.sqlite)
What did I overlooked on this part ? Of course I had changed the ‘MyDatabase.sqlite’ into the real database.
I have put in place the following code to connect to my SQLite database:
Dim dbFile As FolderItem
dbFile = SpecialFolder.Desktop.Child(“mydatabase.sqlite”)
If dbFile.Exists Then
DB = New SQLiteDatabase
DB.DatabaseFile = dbFile
If DB.Connect Then
// Use the database
End If
End if
However I have to put the database on a different location, a directory on the Documents folder (OS X), called: Documents/app/sqlite
I have tried to replace the ‘Desktop’ into ‘Documents’ but it did not work out.
I have inserted your suggestion based on the assumption, that the projectfile is stored in the Documents/app directory and within the ‘app’ directory a sub directory called ‘sqlite’. When I do this I got an error called ‘Syntax error’.
The location of the error is: Session.ConnectToDB, line 2.