why i need to declare every time this code even after make the mySQLiteDB as a global property?
Var mySQLiteDB As New SQLiteDatabase
Var mySQLiteDBFile As FolderItem = GetFolderItem("").child("Contents").child("Resources").child("FatCatDB.sqlite")
If mySQLiteDBFile <> Nil And mySQLiteDBFile.Exists Then
mySQLiteDB.DatabaseFile = mySQLiteDBFile
mySQLiteDB.Connect
End If
if i remove the first line, (and declare it on “app.open”) the code runs, no error. but i can’t insert on database file, only read from it!
why?
i just want to put it all on “app.open” and keep the sqlite connected, until i close it.
why i can’t just do it at “app.open” and keep the db open just like mysql?
mySQLiteDB is on a module
i have this on my app.opening:
mySQLiteDB = New SQLiteDatabase
openFatCatDB()
the openFatCatDB is:
#If (TargetMacOS Or TargetWindows Or TargetLinux) And DebugBuild Then
mySQLiteDB.DatabaseFile = SpecialFolder.Resources.Child("FatCatDB.sqlite")
mySQLiteDB.Connect
… etc
i can’t do any insert anywhere. ONLY if i put this before the insert code…
Var mySQLiteDB As New SQLiteDatabase
Var mySQLiteDBFile As FolderItem = GetFolderItem("").child("Contents").child("Resources").child("FatCatDB.sqlite")
If mySQLiteDBFile <> Nil And mySQLiteDBFile.Exists Then
mySQLiteDB.DatabaseFile = mySQLiteDBFile
mySQLiteDB.Connect
End If
Please don’t open a database from app resources. Consider the app itself to be read only. Depending on the computer, you may not have write permissions there. And changing the app bundle would break code signature.
Better make a copy of the database to the application data, preferences or documents folder. And then open it there.
Add a New Module (if your project does not already have one) and add there a SQLiteDatabase Property. Be sure it is Global there.
Also, avoid .Child as you use (more than one in a line): you never know who is Nil (because you cannot test those .Child). Use instead as needed lines and test each result after that line.
At last as Christian says, use SpécialFolder.ApplicationData: create a Folder there using your app signature (com.alexandre.cunha for example), then you are on your own.
There is/are examples in the Examples folder you can download from the IDE (New → Examples → Download).
At last, yes, I read what you wrote and the trouble lies there:
Var properties are active within the Code you wrote that line;
Module properties can be active through your application; and as someone wrote, using both is like having two drivers in your car: this does not works properly (as you experiment). Conflict of interest one cannot work for him when in his boss enterprise (shop, whatever; while at work).
Yes, in some cases, a Property in a Module needs extra work to be active as with SQLiteDatabase (and FolderItem, etc.).
I already shared this example (I wrote it for someone else)
Once you run it, click in
Create
Import (and choose the provided text file)
Read (to display the data)
Eventualy Tag Debut (to display the date as SQLDate stored in RowTag).
You can click in the first column to sort the entries by dates (if you cliked in the “Tag Debug” button).
Or simply ignore this entry: your choice.
PS: the .sqlite file is saved in the project folder, it was just an example.