SQLite Forum

Database on android SD CARD
Login

Database on android SD CARD

(1) By Webalchemist on 2021-10-23 23:19:38 [source]

Hi I hit so Many brick walls trying to make my own database on android without using android studio.

I just want to make calls to the db using shell on my SD card.

Can I install sqlite on my SD card and put the db in the same directory and have it run there?

Please help. Burned up so many hours trying to get this working

(2) By Simon Slavin (slavin) on 2021-10-24 01:48:13 in reply to 1 [link] [source]

There's no problem with storing a SQLite database on an SD card. You need all privs for card access, including the privs needed to create new files, and to change file attributes.

You don't really 'install' SQLite. SQLite is an API, a programmer's library, a set of functions your program can call. You build it into your program. If you don't want to call Android's own library

https://developer.android.com/training/data-storage/sqlite

then download the amalgamation source code

https://sqlite.org/download.html

add it to your project, and call that. You can find precompiled binaries for Android on the same download page.

(3) By Webalchemist on 2021-10-26 19:18:58 in reply to 2 [link] [source]

thank you so much for this excellent reply!

Some specifics of my project: I'm not using andriod studio. I'm working with Macrodroid and shell command.

So, instead of the andriod binaries, I downloaded Precompiled Binaries for Linux and was able to move the sqlite file to my sdcard

I then called it in my shell like:

/storage/2EA5-2D26/Xenno/sqlite /storage/2EA5-2D26/Xenno/zztest.db

the result I got was:

/system/bin/sh: <stdin>[25] /storage/.../sqlite3 can't execute: Permission denied

I then used the LS command and the sqlite3 file is set to rwxrwx---

I tried using chmod o=rwx /storage/2EA5-2D26/Xenno/sqlite but I get no result

I've spent so many hours on this. Any help is much appreciated. If only I could make sqlqueries!? it'd be a whole other world!

(4) By Stephan Beal (stephan) on 2021-10-26 19:41:30 in reply to 3 [link] [source]

/storage/.../sqlite3 can't execute: Permission denied

That SD card is very likely formatted with the FAT filesystem and linux distributions will mount such filesystems with the "noexec" option, making it impossible to run executables. Copy the sqlite3 binary to /tmp (or some other non-FAT place) and run it from there.

(5.1) By Webalchemist on 2021-10-26 21:22:47 edited from 5.0 in reply to 4 [link] [source]

It says generic hierarchical.

What if I format the SD card?

I tried navigating to

cd /tmp but I got invalid directory.

I have no idea of any other "nonFAT" places. How can I solve it?

---- update

I tried reformatting but android didn't offer me any alternative formats.

As an aside,

I moved my files to the storage/emulated/0/test directory and there was a difference.

On my SD card the permissions were RWXRWX--- but on my emulated storage its rw rw ---

I selected the 20 FE phone specifically for the SD card so I could do this project without rooting my phone.

I'm on the verge of giving up on SQLite even though I really really want it to work!!

Any last ideas?

(6) By Larry Brasfield (larrybr) on 2021-10-26 21:46:55 in reply to 5.1 [link] [source]

On my SD card the permissions were RWXRWX--- but on my emulated storage its rw rw ---

That's a decent clue that Stephan's "noexec" tip is pertinent.

I selected the 20 FE phone specifically for the SD card so I could do this project without rooting my phone.

The "cannot root phone" constraint is not one likely to be catered to.

I'm on the verge of giving up on SQLite even though I really really want it to work!!

If wishes were fishes, ...

What makes you think this has anything to do with SQLite, other than that it is ultimately executed (like anything else running) and your environment is blocking execution?

You should go to an Android development forum to get advice on your problem. You have a platform issue rather than a SQLite issue.

(7) By Webalchemist on 2021-10-27 16:45:55 in reply to 6 [link] [source]

Thank you Larry for your fun and insightful reply...

The reason for not wanting to root is that I wanted to develop an application / extension that others could easily use without rooting their phone. If it were just for me, fine, but if I want others to use it who may not be as enthusiastic about rooting, wouldn't it be great if it could work?

When you said its a clue that the comment noexec is relevant, How can you say that when the permission says RWXRWX--- Doesn't that say that the base user should be able to execute? Unless for some reason my app (macrodroid) is somehow belonging to the "other" group.

While you are likely right that my issue is with my environment and not with SQLite, my hope is that other SQLite enthusiasts may have bumped up against this issue and be able to help with how to solve it.

(8) By RandomCoder on 2021-10-27 18:39:29 in reply to 7 [link] [source]

One thing I've not see in this thread:

How are you building the SQLite shell? Or, are you just trying to run the linux/x86 build on an Android device?

(9) By Webalchemist on 2021-10-28 03:12:01 in reply to 8 [link] [source]

well, since sqlite3 is not installed on my device, I tried adding the sqlite3 file to my sdcard and calling it like storage/sdcard/sqlite3 storage/sdcard/my.db but I couldn't get it working.

I also tried the tasker sqlite plugin within macrodroid. I also ran into some roadblocks there.

Any other ideas / suggestions?

(10) By RandomCoder on 2021-10-28 04:38:41 in reply to 9 [link] [source]

Where did you get the file named sqlite3 that you placed on the SD card for your device?

(11) By Keith Medcalf (kmedcalf) on 2021-10-28 06:09:22 in reply to 9 [link] [source]

I couldn't get it working.

I tried to paint the house blue. That did not work either!

It might be perspicacous to be more specific.

What exactly was the problem?

The battery was dead? -- buy a new battery will probably fix this.

You got gangrene and your fingers fell off? -- go see a prosthetician and see if they can do anything for you

Unfortunately, the number of possible reason for "did not work" is effectively unlimited. Perhaps a vasectomy will be helpful.

(12) By Gunter Hick (gunter_hick) on 2021-10-28 09:12:23 in reply to 8 [link] [source]

The OP already stated thus: "So, instead of the andriod binaries, I downloaded Precompiled Binaries for Linux and was able to move the sqlite file to my sdcard"

(13) By Tim Streater (Clothears) on 2021-10-28 09:36:30 in reply to 12 [link] [source]

Which 'sqlite file'? The sqlite library, the sqlite CLI executable, or his sqlite database?

(14) By Gunter Hick (gunter_hick) on 2021-10-28 09:42:24 in reply to 13 [link] [source]

My guess is as good as yours. I'm inclined to think CLI executable because it does not have to have a file name suffix in Unix, whereas shareable images/libraries tend to end in .so

It may be irrelevant unless unix binaries can be run on android

(15) By RandomCoder on 2021-10-28 12:48:05 in reply to 14 [link] [source]

Unix binaries can be run, but only if they're for the right architecture.

None of the downloads on the SQLite downloads page are for Arm, so unless the OP has an unusual phone, it won't work.

(16) By Larry Brasfield (larrybr) on 2021-10-28 13:11:23 in reply to 7 [link] [source]

The reason for not wanting to root is that I wanted to develop an application / extension that others could easily use without rooting their phone. If it were just for me, fine, but if I want others to use it who may not be as enthusiastic about rooting, wouldn't it be great if it could work?

I do not question your motivation for wanting to avoid rooting a phone. I just don't think that's a constraint that is going to be flexible during troubleshooting or allow you to do the experiments that would allow you to figure out what the relevant factors are that lead to today's problem.

When you said its a clue that the comment noexec is relevant, How can you say that when the permission says RWXRWX--- Doesn't that say that the base user should be able to execute?

I saw the difference between "RWXRWX---" and "rw rw ---" (on your "emulated storage") as significant and related to the "noexec" mounting. It suggests that the 'x' bit is less significant (with respect to today's problem) than you seem to think.

The per-file execute permission is separate from the effect of the noexec mount option. I would not expect the per-file permission bits to reflect whether the block device was mounted with the noexec option. (They do not on Linux, and I'm too lazy to check this on other Unix-like systems.) They do not mean that that, once loaded, program image text segments from the file will be physically executable. IOW, the 'x' bits do not mean quite what you think they mean.

While you are likely right that my issue is with my environment and not with SQLite, my hope is that other SQLite enthusiasts may have bumped up against this issue and be able to help with how to solve it.

I do not hope to disabuse you of your hope(s). My recommendation of a different forum was intended to improve your odds of success and help keep this forum on-topic. Other Android developers are much more likely to have the pertinent knowledge, and on an Android forum they are less likely to regard the issue as off-topic which will also improve your odds of getting a useful answer.

(17) By Webalchemist on 2021-10-29 16:57:12 in reply to 14 [link] [source]

This is correct... The name of the package escapes me at the moment, but it had a folder with three files

Sqldiff sqlite3 sqlanalizer

So from what I understand the version I got is the CLI version However if there are dependencies that i'm missing, I'd love to know about it.

Some things I found since my last post:

I found somewhere that Android has a separate user for every application.

So that means that if I want to execute the file under the user permission, it needs to be owned by shell app ?

I also read somewhere some people are getting success with changing a linux file to linux_file.exe on SD card so that the SD card recognizes it as executable. Even with the EXE extension, some files are running properly.

I have yet to test it but I was considering using something like:

using cat to read sqlite3 and save it to a new file called sqlite3.exe. Hopefully this would accomplish two things at once: make a file that's owned by shell and make a file that the SD card is recognizing as executable. However if the ownership happens as i'm hoping, I wouldn't need to rename it to exe.

Another thing I don't know is if each instance of shell would create its own user, meaning I need to do all my shell commands in one session?

I suppose I could do two different sessions and see if the file ownership is the same.

I ran into another roadblock on this application so It took me away from this issue, but I appreciate all those who have posted here so responsively, thank you for all your support / engagement on this!

(18) By Webalchemist on 2021-10-29 16:59:54 in reply to 12 [link] [source]

Thanks for such close tracking on the thread! this is awesome!

(19) By Webalchemist on 2021-10-29 17:12:48 in reply to 16 [link] [source]

Larry, Thank you so much for your in-depth engagement here... Its clear that you have a very in-depth understanding about these things

I hear you saying that I'd have a better chance of figuring all this out if I root my phone.

You are probably right that I don't understand permissions. From what I read it's read write and execute. This makes me think that a user that does not own or belong to the root group would rely on an x in the the "other" group in order to execute the file EG ------rwx

However this is not my wheelhouse and I could be grossly mistaken.

I read somewhere that Andriod is giving a separate username to each application. This means that shell will never be the same user unless shell actually created the file.

Consequently, I was going to try using cat command to copy sqlite3 file to another file by shell and hopefully this would solve my ownership issue.

I also read some users are getting luck on SD cards by appending the file with .exe before they put it on the SD card. This makes the system treat the file as an executable. -- I have not yet tried it.

Thanks for encouraging me to get the best chance of good support

I also appreciate you and the other users for engaging my topic even though it may seem "off topic" explicitly to sqlite, I hope some others find it relevant and perhaps may even be helpful to someone else who is trying to get sqlite going on their phone.

(20) By RandomCoder on 2021-10-29 18:12:15 in reply to 17 [link] [source]

I'll try to be as direct as I can be:

Are you trying to run sqlite3 that you downloaded from SQLite's Download Page on your phone using a shell running on an Android device?

This has basically no hope of working. The download page includes x86 binaries, and your phone is running some version of arm, unless it's an unusual phone.