How can i see SQLite Database (No emulator)?

2020-07-25 13:14发布

For development , sometimes we need for a faster programming , the SQLite database state of our programs . But i can only extract database if it's on emulator , not mobile .

Then my exactly question is ¿Is there a way to see the android sqlite db or a way to extract it?

If there isn't a good answer to that question . How do you manage with that programming issues when you need to know the db state of the tables?

3条回答
够拽才男人
2楼-- · 2020-07-25 13:31

You can do this from shell as vbence mentioned. Another way is to copy the database file to sd card programatically. Call this in onStop():

File source =  new File("data/data/com.ACME/databases/" + DATABASE_NAME);
File dest =  new File(Environment.getExternalStorageDirectory() + "/" + DATABASE_NAME + ".db");

public static void copyFile(File sourceFile, File destFile) {

FileChannel source = null;
FileChannel destination = null;

    try {
        if (!destFile.exists()) {
            destFile.createNewFile();
        }

    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
    destination.transferFrom(source, 0, source.size());

    } catch (Exception e) {
        /* handle exception... */
    } finally {
    try {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        } catch (Exception e) {
            /* handle exception... */
        }
    }
}
查看更多
爷、活的狠高调
3楼-- · 2020-07-25 13:34

For exploring the SQLite database you can use the addon of mozilla firefox named SQLite Manager. And after running the app pull the database to your system using file explorer and open the firefox-->Tools-->SQLite Manager. A window will come and on that there is an option to open the database, click on that and direct to the path where you have pulled your DB. Open that DB you can see the tables created and the values you have entered. Also you have the option to add, edit, delete and update the values.

查看更多
我只想做你的唯一
4楼-- · 2020-07-25 13:40

You can use

adb shell

to get a root shell of the device, then use anything you like directly on the DB. Export it, run scripts etc etc.

You can check out this link for details:

developer.android.com/studio/command-line/sqlite3.html

Abount SQLite commands: http://www.sqlite.org/sqlite.html

查看更多
登录 后发表回答