When using sqlite3 through adb shell arrow keys, instead of moving the cursor to the desired position or summoning the history facility, the following is showed in the screen: ^[[A, ^[[B, ^[[C, ^[[D.
I'm using Mac OS X and I have tried Terminal and iTerm terminal emulators.
Does anybody know how to fix this?
To allow editing and history in the input of a console program, that program must be linked with the readline library.
The sqlite3 tool does support readline, but on Android, readline support has been disabled.
(Probably because readline is licensed only under the GPL.)
A workaround would be to use a local version of SQLite with readline support.
Copy a database file from your device to your local machine:
adb pull <database-file-on-device>
Use your local version of SQLite to access the database file:
sqlite3 <database-file-on-local>
If you made changes you can transfer them to the device. Copy your local database file from your local machine to your device:
sqlite3 <database-file-on-local> <database-file-on-device>
You can use the previous command functionality in the adb shell. So just adb shell. Then cd to the /data/data//databases directory. From here run (for example): sqlite3 "select * from "
Then you can use up arrow to redo that command. Kind of a hack, but way better than having to retype the command inside the sqlite3 interactive prompt.
Working off of Khanad's answer: I wrote a shell script on the device and I send my sqlite commands through it.
First create a script file on the device and make it executable:
# get on the device
$ adb shell
# get write access on the device (this will also put you in the data/data directory)
$ run-as com.YOUR_PACKAGE.YOUR_APP_NAME
# create the script file
$ touch qlite
# make it executable
$ chmod +x qlite
Then add this code to the script. Remember to put your actual app name in there. (The echoes just add a little breathing room to the output.)
echo
sqlite3 databases/YOUR_APP_NAME -cmd ".mode column" ".headers on" "$1;"
echo
Then you just have to do something like:
./qlite "select * from table limit 1"
The script will pass the sqlite command through, tack on the semi-colon, pretty print it with column names and you can use the up arrow to get your last command. And because you have write access you can make updates directly to the DB on the device.
I hope this makes someone's life easier!
Use ADB shell instead of sqlite3 shell to get the advantage of the readline package.
generic_x86:/data/data/com.example.musicplayer/databases $ sqlite3 music_player_database -line 'select * from lastplayedsong;'
Just make sure you are in the correct package and don't put .db at the end of the database name otherwise a new database would be created and the query would return you no result.
P.S: source
Related
i have created a database using SQliteCursor in android. but non of my queries work and it always give me no such table exception.so i want to see the database to check if it is even created?!
so here is my question:how can i see my created database with code as the program is running???
I saw so many answers but they all assume there is a database in DDMS perspective.
is there any tool I can use? what can I do?
besides I am using cursor to enter queries.
thanks.
You can pull the database from the device to your local disk by executing following commands:
First make your database file accessible by running chmod using run-as command of adb
adb shell "run-as package.name chmod 666 /data/data/package.name/databases/file"
Then try to pull that file in your local disk
adb pull /data/data/package.name/databases/file
Just make sure that you have marked the application to debuggable=true in the manifest.
To view this database you can download a mozilla plugin i.e SqliteManager and can view the full schema of DB. I always use this and it is really good.
I made a executable file for this process please add below lines in a file with .exe or sh extension depending on your system OS:
adb shell "run-as yourpackagename chmod 666 databases/yourdbname.db"
adb shell "cp /data/data/yourpackagename/databases/yourdbname.db /sdcard/"
adb shell "run-as yourpackagename chmod 600 databases/yourdbname.db"
adb pull /sdcard/yourdbname.db
Replace yourdbname with your Db name and yourpackagename with the package name of your app.
Please post if you got stuck somewhere in the steps.
Please paste some code for better understanding.
or try this
Go to DDMS => data => data => here you have to find your project like com.example.example. In this you will easily get database file and you can save it or check whether it is created or not.
I am developing an automation on android platform and got stuck at the db part of the app.
I need to clear all the data from a table "tablename" through adb commands. I have got the following commands that do the job manually but I cannot automate it.
adb shell sqlite /data/data/.../databases/log.db
delete * from tablename
When I create a batch file for this the
sqlite>
had opened but the delete command was not executed. How can I achieve this?
batch file data:
adb shell sqlite3 /data/data/.../databases/activitylog.db
delete * from events;
The SQL command to execute must be a single parameter, so you have to quote it:
adb shell sqlite3 .../activitylog.db 'delete from events'
And I took the liberty of correcting the SQL syntax.
Your Device needs to be rooted for this.
Way one:
Run your sqlite3 command after "su".
I prefer the following way:
adb shell
su
cd <toYourDbDir>
sqlite3 /data/data/com.symantec.mobilesecurity/databases/activitylog.db delete * from events
If you have to do this again, just use the up-arrow to get the last command and execute it with enter.
Way two:
Install sqlite Database Editor, open the Db and edit what you want.
I need get SQLite database from Android app from Genesis device where user has populated by hand.
How I can create another app or any other way to get this db and save in place where I can get?
obs.: the device has root
Thanks
Steps from .../platform-tools of Android on cmd:
1) type adb shell
2) run-as com.your.package
3) type ls
cache
databases
lib
You can find Your Database Here...Also You didn't even have to root the Device
Hope this could helpful for you...
Provided you have the device attached to a box with adb on the PATH you can use this command:
adb -d shell 'run-as your.package.name.here cat /data/data/your.package.name.here/databases/your_db_name_here.sqlite > /sdcard/recovered_db.sqlite'
Or you can use Ecliplse DDMS file explorer.
VERY EASY WAY TO DO IT
In the latest releases of Android Studio (I am using AS v3.1.2) the Google team has made it really straight forward. You just have to open the Device File Explorer window which should be at the bottom of the right vertical toolbar, if you cannot find it you can also open it this way:
View -> Tool Windows -> Device File Explorer
Once you have Device File Explorer window open, use your mouse to navigate to the following path:
data -> data -> your.package.name -> databases
Inside the databases folder you should see the database you want to explore, do a right click and Save As... select your desired computer destination folder and voila!!
You can either include the Stetho library on your app,
http://facebook.github.io/stetho/
which will allow you to access your DB using Chrome's Web Debug tools
or use the following shell script:
#!/bin/bash
echo "Requesting data from Android"
adb backup -f data.ab -noapk YOUR.APK.NAME
echo "Decoding...."
dd if=data.ab skip=24 iflag=skip_bytes | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -
rm data.ab
echo "Done"
```
None of the methods above require your device to be rooted and the latter works even on apps that you did not write yourself, as long as the ApplicationManifest.xml does not contain "backup=false"
After trying dozens of commands that didn't work for me on Marshmallow, I've found this one that works (for debuggable apps at least):
adb shell "run-as your.package.name cp /data/data/your.package.name/databases/you-db-name /sdcard/file_to_write"
Then you simply can view the DB with aSQLiteManager for instance.
You can use this script.
humpty.sh
You should know the application package name and sqlite database name.
You can check the available databases.
$ adb shell
$ run-as <package-name>
$ ls databases/
To dump database or other file.
./humpty.sh -d <package-name> databases/<db-name>
I've got Android 2.2 on my phone and I'm doing some DB development. I've been trying to query my DB using sqlite3, but it looks like sqlite3 is missing from my phone. So then I tried a few other commands (su, find etc) and they ALL seem to be missing.
Can anyone tell me where they have gone please? I read somewhere that sqlite3 at least might have been accidentally left out of 2.2, but surely they can't all have been missed off can they?
Thanks
With the new release, adb has moved to platform-tools while all other tools are still under tools folder.
You can either copy them or add them to the Windows Path (if you are using windows).
Try:
$ adb -s <serialno> shell type sqlite3
sqlite3 is /system/xbin/sqlite3
to determine if sqlite3 is available or not on you device.
The command you entered in one of your comments is malformed, it should be (after you determined that sqlite3 is available):
$ adb -s <serialno> shell sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
Those aren't adb commands those are binaries usually installed on rooted devices. If your device isn't rooted you aren't going to be able to install them either.
However, what you can do to get into your apps database. Use the activity manager command set-debug-app [options] <PACKAGE> This will let you access your apps database without being rooted, then you can pull it to your desktop and use sqlite3 from there.
Something like this:
adb shell
am set-debug-app com.example.appname
exit ##exit adb shell
adb pull data/data/com.example.appname/databases/exampledb.db exampledb.db
sqlite3 exampledb.db
Your app needs to be set to debugging true in the manifest for this to work.
I've read the answer to a question as to how to access the contents of the databases, however I cannot seem to get it to work on my machine. Here is the shell log:
C:\android-sdk-windows\tools>adb -s emulator-5554 shell
# sqlite3 /data/data/com.android.demo.notepad2/databases/notes
sqlite3 /data/data/com.android.demo.notepad2/databases/notes
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
.tables
sqlite> ^C
C:\android-sdk-windows\tools>
SQLite simply echos my commands back to me, even although the Eclipse file browser tells me it exists. If I use the sqlite3 tool and use ".tables" the commands are accepted.
Is the SQLite syntax different through the emulator is am I missing something?
(Sorry for so many questions, there doesn't seem to be much coherent documentation on Android!)
Thanks!
I can tell you that it works fine for me on Android 2.0.1:
$ adb shell
# cd /data/data/apt.tutorial
# ls
lib
databases
shared_prefs
# cd databases
# ls
lunchlist.db
# sqlite3 lunchlist.db
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
android_metadata restaurants
sqlite> .exit
# exit
You can always download the database file using DDMS or adb pull and use a desktop SQLite client to examine it. For example, I use the SQLite Manager plugin for Firefox.
Also, bear in mind that SQLite has no default file extension, so if your database is not notes but notes.db or notes.sqlite or something, you'll need to specify the extension.
Also also, I have not tried this on Windows, and there's a possibility that there is something goofy with the Windows command prompt and the limited shell available on Android devices that is causing your difficulty.
If you want to issue sqlite3 statements from command line use something like
$ adb -e shell sqlite3 -batch /data/data/com.example.dbsample/databases/db '.tables'
android_metadata
$ adb -e shell sqlite3 -batch /data/data/com.example.dbsample/databases/db 'select * from android_metadata;'
en_US
the obvious advantages are that you can rely on your shell history and you can use this in scripts.
I had the same problem and discovered that contrary to the documentation you shouldn't put the ".db" extension on the database file name.
Note: I'm using win7 and 2.1 emulator.
I had the same issue ,spent almost an hour ,posting here so that it will save someone else time ,check if you have given the correct filename along with the extension, there are two files under the databases folder myDB.db and myDB.db-journal and when i ran
"sqlite3 /data/data/com.my.package/databases/myDB"
and
.tables listed nothing, sqlite3 created a new db with the name myDB , it did not open myDB.db