16

I need a way to install or somehow get access to sqlite3 in the adb shell. I have rooted my device.

I've tried to find an answer but the closed I could come is: Why do I get a "sqlite3: not found" error on a rooted Nexus One when I try to open a database using the adb shell?

But I don't think it's good idea to push my windows sqlite3.exe on a linux system?

So is it possible to install the sqlite3 terminal browser somehow?

[SOLUTION]

From the different comments and some asking around at #android-dev (irc), I found a solution. First I copied the database file to my desktop. But fist I had to install BusyBox, because cp isn't included?!? After that ran I into the problem that I couldn't pull or push from anywhere but /sdcard/ . I could then use /sdcard/ as a "middle station" and pull/push my db.

Then I got exhausted! I really had to have my sqlite terminal explore. Then I got the idea to start the emulator pull the sqlite binary from /system/xbin/sqlite3. Then remount /system with rw:

# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system

and push sqlite to the /sdcard/, and from there copy it to /system/xbin/

Now it works :D

Community
  • 1
  • 1
DNRN
  • 2,397
  • 4
  • 30
  • 48
  • "I need a way to install or somehow get access to sqlite3 in the adb shell" -- why? If you have rooted your device, just download the database and look at it with your "windows sqlite3.exe" or a better SQLite client (e.g., SQLite Manager extension for Firefox). What are you gaining by having `sqlite3` on the device? – CommonsWare Mar 30 '11 at 11:54
  • 1
    If you want to play around with your app's db, why not pull the db out instead, and manipulate it on your pc – Rajath Mar 30 '11 at 11:55
  • How do I use my sqlite3 browser from within the adb shell? – DNRN Mar 30 '11 at 12:00
  • 2
    I need to do CRUD from the terminal.. – DNRN Mar 30 '11 at 12:06
  • Awesome! You need to post what you did as solution, and accept it. – Samik R Dec 13 '12 at 21:42
  • another relevant answer https://stackoverflow.com/a/60892396/2655092 – whoopdedoo Mar 27 '20 at 18:52

4 Answers4

5

Download this app from google play will help you install sqlite3 on android https://play.google.com/store/apps/details?id=ptSoft.util.sqlite3forroot

ax003d
  • 3,278
  • 29
  • 26
3

You don't need root to pull the database from your device. Simply run the following commands:

adb shell run-as <package-name> "cp databases/<db_name>.db /sdcard/ && exit"
adb pull /sdcard/<db_name>.db ~/Downloads/

From there, you can use sqlite3 for whatever operating system you're using (http://www.sqlite.org/download.html), or a sqlite browser such as "DB Browser for SQLite" (http://sqlitebrowser.org/)

Chris
  • 1,180
  • 1
  • 9
  • 17
0

You can do this with adb shell without issue.

In terminal or CMD (assuming you have the ADB path set and your phone has ROOT) type:

  1. $ adb shell
  2. $ cd data/data/com.nameofyourpackage/databases/
  3. $ ls to find the name of your database
  4. $ sqlite3 nameofyourdb.db

Then you can use .tables .schema to see the data you need to create the appropriate query.

kenju
  • 5,866
  • 1
  • 41
  • 41
Nick
  • 9,285
  • 33
  • 104
  • 147
  • I am getting Permission denied, when i am executing ls command to find database. what can be the problem ? – Harry Mad Nov 06 '14 at 11:44
  • 2
    You have to be on an emulator or rooted. – Nick Nov 06 '14 at 14:47
  • It would be nice to be able to run it from host. Eg: `adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db 'select * from "secure";'`. In my case it gets stack, I have to log into adb shell and run it from there. – pevik Nov 05 '15 at 11:16
0

I use Rajath's technique... Adb "Pull" the db from the emulator/device, work on it, then adb "push" it back onto/into the emulator device.

also: I use the free SQLite Editor from the Android Market. I have not rooted my LG Ally and therefor can only edit database tables on my sdcard with SQLite Editor.

Rajath suggests using the adb to push and pull the databases to and from the emulator/device. The work on the database with the windows (or whatever) sqlite3 program you have. He does not suggest pusing the windows sqlite3 onto the Android device, IMHO.

I note that java/android "query()" sends actual SQL commands programmacitacly to ones program with user input. I conclude that sqlite3 is in Android somewhere.

When using the emulator Dev Tools is available, and way down at the bottom of the list is the Terminal Emulator. This allows exploration of file structure of Android in the emulator. However using "adb shell" from the PC has root permissions.

good luck. cactus mitch