Closed alexobviously closed 3 years ago
same question
This part is handled by sqlite3 package. In the README there is a snipped that shows how to bundle libsqlite3.so with your app that you could try.
Also I'm not sure on which platform you are getting the issue (linux? android?). I recommend using sqflite (not sqflite_common_ffi) on Android
Also I'm not sure on which platform you are getting the issue (linux? android?). I recommend using sqflite (not sqflite_common_ffi) on Android
I'm building for android/ios but I also have some tools that needs to run in dart alone, which is why I wasn't just using sqflite (I have a large static db that is only read from the app but I have a dart script to build it).
I have built two separate versions of the sqlite interface now, one using sqflite, but I've run into a different problem - it doesn't seem like it works in an isolate, and that's unfortunately necessary for my application. I've had a bit of a look around here and correct me if I'm wrong but it seems like sqlite doesn't work outside of the main isolate at all?
So I think I need to find a different type of database for this app. I'm trying Hive at the moment but it seems like it suffers from the same problem, so if anyone has any suggestions I'd appreciate them.
correct me if I'm wrong but it seems like sqlite doesn't work outside of the main isolate at all?
That's correct. sqflite has its own native threading mechanism and should be used from the main isolate only. (sqflite_common_ffi runs in a separate isolate but must also be used from the main isolate only)
I have a multiplatform app that I'm writing and doing a proof of concept. I have an app that has a prebuilt db, yet most of the samples, simply build the db in code. In android and ios, you have to copy the prebuilt db from the assets folder to the path that the library gives you . The copying is done byte by byte. After that copy is done, one can do the db stuff as expected and as the tutorials show.
So the question is how to do this? Is there an example for a
My sample code for proof of concept works with the android OS. I want it to work with the ffi on linux but there is no code example. my git repo for such and example is located at: https://github.com/bksubhuti/mydbtest
@bksubhuti I don't have an example for your exact situation but you can find:
My repo I posted above https://github.com/bksubhuti/mydbtest does copy from the assets using the same technique as the first link you posted. Everyone uses the same example which is mostly the same as this example. However that is only for Android & iOS. . I will look at the second link you gave .but I suspect it is done without a pre-populated assets db as the first example used. Perhaps.one does not need to copy a db to the runtime area like mobiles do.
I'm totally new to flutter and just doing a test for proof of concept before we rewrite a Buddhist Pali reading app (tipitaka Pali Projector). So far I'm impressed and pro-flutter. I'll come.back to report later tonight. Using the ffi still on the mobile emulator is different and there an error as reported on this thread.
I will look at the second link you gave .but I suspect it is done without a pre-populated assets db
Correct if just show how to use sqflite on linux
Perhaps.one does not need to copy a db to the runtime area like mobiles do.
Correct, the code (to copy the asset database to a writable location) should be similar, you need to copy the asset file somewhere. I guess you could use path_provider
to find the proper destination on Desktop.
Well then if I was I was correct as suspected (not from assets). then can you make a small example that opens a single table query from prepopulated database from assets and works on all platforms? I suspect this has never been done before and no example code exist nor has this been tested. It would be required for the ffi library to say "functional" on all platforms. Since I'm one or two weeks into flutter and a few days into SQLite, this would be a difficult task for me.
I follow the doc here on how to use sqflite on linux and was able to run your example on linux with very few changes. I created a pull request so you can see the changes made.
can you make a small example that opens a single table query from prepopulated database from assets and works on all platforms?
Hard for me to create an example for all cases unfortunately. I develop and maintain this library in my free time. However examples are welcome!
It would be required for the ffi library to say "functional" on all platforms.
I know the documentation is poor. The notepad example is a way to say "functional" on all platforms. Copying an asset file is not sqflite specific. So maybe you can find more information in flutter docs regarding how to deal with assets: https://flutter.dev/docs/development/ui/assets-and-images
That is excellent. I'm new to GitHub and need to figure out how to do admin for pull req . Not sure what that is It is easier to make you a contributer to the main repo since this is just test stuff anyways. . I'm also part time doing sw dev and a monk full time. I have been away from programming since the 90's. Flutter and even SQLite are well documented compared to other FOSS platforms. But my old days were msvc++ in the 90's . I'm learning now as I try to make free religious reading apps for my own use and others too.
I pulled the new project, but the flutter run -d linux failed. I did this with another project.. got a similar error in the terminal command window, however, the project worked and ran. I did a flutter upgrade but it still gave the error and launched the mydb app but did not do a query. However, your changes did work with the android emulator
There was a note on stackexhange about using AUR instead of snap for flutter install. I hope not. I did the upgrade, not sure what more to do.
$ flutter run -d linux
Launching lib/main.dart on Linux in debug mode...
/snap/flutter/current/usr/bin/ld: warning: /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0008002
/snap/flutter/current/usr/bin/ld: warning: //lib/x86_64-linux-gnu/libdl.so.2: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0008002
Building Linux application...
Syncing files to device Linux...
We are going away from the original issue here sorry. You should first try to build a linux project without sqflite. If necessary you might have to delete the linux folder and re-create the project. If you manage to run and build a linux project without sqflite and fail when adding sqflite, please open a new issue.
I said in the previous that i did build an app without sqlite and got the same error, but it did run. When i did linux build, it ran but hung on the listbuild from the db. I changed the channel from master to stable (and then did flutter upgrade) but it still failed in the same way. However, I trust that you tested in linux, because a couple of generated files popped into the linux folder when I did the pull. Linux is still new as well, so maybe that is the problem. Did you test on Linux? If so, i think , yes this issue is closed.
I was able to get the project to work on ubuntu 21.04 by removing the flutter snap and installing the flutter gz downloaded from the flutter website. Then I changed the path to reflect the new flutter path and rebooted
I was able run a base app with zero errors showing
However, the mydbtest was still hanging so I ran the debugger and stepped into the code. It could not find libsqlite3.so shared library and threw and exception when trying to open or get the path.. i forget. However, I obviously had sqlite3 tools installed and could open the db and run queries through the command line. Reinstalling sqlite3 was not working and dangerous for a purge.
I installed libsqlite3-dev and ran sudo apt-cache policy sqlite3 and everything worked.. So maybe this needs documentation or working with the ubuntu people.
I appreciate you making the mydbtest program working on your end (and now my end too). It is amazing that flutter has so much support. I'm quite sold on it, but still testing.
by installing the following:
$ sudo apt-get install sqlite3 libsqlite3-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
sqlite3 is already the newest version (3.34.1-3).
The following packages were automatically installed and are no longer required:
html2text libgranite-common libgranite5 linux-headers-5.11.0-18
linux-headers-5.11.0-18-generic linux-image-5.11.0-18-generic
linux-modules-5.11.0-18-generic linux-modules-extra-5.11.0-18-generic
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
libsqlite3-dev
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 753 kB of archives.
After this operation, 2,622 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu hirsute/main amd64 libsqlite3-dev amd64 3.34.1-3 [753 kB]
Fetched 753 kB in 5s (142 kB/s)
Selecting previously unselected package libsqlite3-dev:amd64.
(Reading database ... 346361 files and directories currently installed.)
Preparing to unpack .../libsqlite3-dev_3.34.1-3_amd64.deb ...
Unpacking libsqlite3-dev:amd64 (3.34.1-3) ...
Setting up libsqlite3-dev:amd64 (3.34.1-3) ...
$ sudo apt-cache policy sqlite3
sqlite3:
Installed: 3.34.1-3
Candidate: 3.34.1-3
Version table:
*** 3.34.1-3 500
500 http://us.archive.ubuntu.com/ubuntu hirsute/main amd64 Packages
100 /var/lib/dpkg/status
@bksubhuti
I installed libsqlite3-dev and ran sudo apt-cache policy sqlite3 and everything worked.. So maybe this needs documentation or working with the ubuntu people.
I was not aware of the need of calling: sudo apt-cache policy sqlite3
. Sorry for the poor documentation. Some notes on Ubuntu support are here: https://github.com/tekartik/sqflite/blob/master/sqflite_common_ffi/README.md#linux
PR are welcome to improve the documentation!
I'm not sure if apt-cache policy sqlite3 is required as I installed the dev file at the same time.
However, the sqlite3-dev file is probably needed for sure and I didn't know that.
I do have it working now (on my machine) which is most important
I will try to change the doc and imply for the next person to test if the apt-cache policy sqlite3 is needed.
I don't know pull-requests but i can learn . Surely it is easier than flutter SQLite.
ante Bhikkhu Subhūti
Website: https://AmericanMonk.org
On Thu, Aug 5, 2021, 14:16 Alexandre Roux @.***> wrote:
@bksubhuti https://github.com/bksubhuti
I installed libsqlite3-dev and ran sudo apt-cache policy sqlite3 and everything worked.. So maybe this needs documentation or working with the ubuntu people.
I was not aware of the need of calling: sudo apt-cache policy sqlite3. Sorry for the poor documentation. Some notes on Ubuntu support are here: https://github.com/tekartik/sqflite/blob/master/sqflite_common_ffi/README.md#linux
PR are welcome to improve the documentation!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tekartik/sqflite/issues/505#issuecomment-893242189, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEKXQWBSKHI3GRDVYWPTFGLT3I6WDANCNFSM4RFF3MQQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .
I've got a flutter app using both sqflite_ffi, with a script that works fine when I run it as pure dart but crashes with this error when I trigger it as part of the flutter app:
Flutter doctor -v
I'm also using the standard sqflite plugin as part of this app for something totally separate. Don't know if that affects anything but that part is running fine. I'm only using sqflite_ffi for this part because it needs to run outside flutter sometimes too and sqflite doesn't support that. I'm not doing anything special when it crashes, just opening a static asset database.