SQLite - problem

Try this:

  1. Remove the importDatabase blocks (this just makes a copy)
  2. Set DBName to //Synospa.db
  3. OpenDatabase

Does this now work ? (remember you will only be able to "read" from a database file in the assets.)

If not you may have to copy your db file to your ASD/private storage or sdcard - somewhere that has a "proper" path, and use that path in DBName.

are you using an Android 10 or 11 device for your tests?
it might be, that the extension was not updated and still uses the old location for the assets
the assets directory for the companion app is now in the ASD - Applicaiton Specific Directory

my sqlite extension correctly can load databases from the assets also for Android 10 and 11 devices...

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Yes, Taifun is correct there. For Android <10 the path needs to be clarified to the MIT provided path for assets in Companion or for ASD (application specific directory) when compiled.

In companion, to load myhtml.db file:

Good day.
After a long time, I returned to the project with SQLite.
I'm testing it on a mobile with Android 6.0.
I'm trying to find out if the db was imported correctly, but the table name from the db doesn't show me, so it's probably wrong ...
It will only show me this on my mobile:

DB vymazaná....
DB importovaná...
DB existuje....
(android_metadata)
/storage/emulated/0/Android/data/edu.mit.
appinventor.aicompanion3/files/assets/
Synopsa-ev.db

Where am I making a mistake?
Thanks.
Ondrej

  1. Why so complicated ?
  2. You cannot delete a file in the assets
  3. Try this (using your database file in assets):

image

image

Hello.
I did it this way.
I also added a list of open tables ...
Number of lists:
1
But Call.SQlite1.TableNames only prints:
(android_metadata)

Ondrej

Can you share your db file: Synopsa-ev.db for testing here?

You can send it by private message if you do not want to place on the open forum.

OK.
What email can I send that database to?
Ondrej

Send private message on this community/forum

  1. Click on your icon top right
  2. Click on the envelope
  3. Click on the Down Arrow bar at the bottom of the list

(or for 2&3 just double click the envelope)

  1. Click on New Message, select/type user etc. attach file (you may need to rename the extension to .txt

remember: that path is only valid for the companion app...
Taifun

Yep, we have not progressed beyond that stage yet :wink:

Hello.
Can anyone advise?
Is there a difference in using SQLite depending on the development environment in which the db is created?
I created the first db in SQLiteStudio, I created the second db in DB Browser (SQlite).
In neither case does the command want to work for me: call SQLite1 TableNames. Only show there (android_metadata).
Can't you send me your training db myhtml.db to try it out?
This time I tried to run it through BlueStacks.
Thanks.
Ondrej

I will make up a couple of example sqlite databases to test with....

Here an sqlite database created in DB Browser and loaded to assets. app running in Companion:

image

Try this.

Sorry need to attach the db file/s. You will need to remove the .txt file extension.

testbrow.db.txt (12 KB)

Hello.
Thanks for help.
And how did you do ImportDatabase?
It falls to me at this point.
The DatabaseExist statement ends with FALSE
Ondrej

I showed you in the blocks: when running companion...the database is in the assets, then open the database using the full path. The path will be different if you have Android version 9 or less and different again if using a compiled app.

Please advise on your test environment. You mentioned you were using Android 6 device earlier, is this when running the latest companion app in development mode ?

Getting database path which is uploaded in media as asset is a little bit tricky. I found following solution from a thread of Juan Antonio.

That may well only work in companion....in later versions of Android....

You should be able to use the double slash for both companion and compiled to import:

image

You do not want to "open" a database from assets, as the file will be read only.

1 Like