Skip to content Skip to sidebar Skip to footer

Android Sqlite Dump Database From Code For Error Reporting

I'm working on a diagnostic tool for one of my android programs. In essence, if a user is having issues, I'd like to do something like an SQLite dump (reference: http://www.sqlite.

Solution 1:

I solved my own problem, by doing a dump of the database to a file, then reading the file into a string. For those interested, the following gives you the general idea:

StringdbPath="/data/data/com.company.project/databases/project.db";
    StringoutputPath="/data/data/com.company.project/databaseDump.txt";

    Processproc= Runtime.getRuntime().exec("sqlite3 " + dbPath + " '.dump' > " + outputPath);
    proc.waitFor();
    returnString = FileUtil.getStringFromFile(outputPath);

EDT

So the above had an issue and I didn't see it, because I ran the SQLite3 command from the adb.

It looks like SQLite3 is a command you can run from the adb, but it is not necessarily on the phone. Based on that I took a different approach. I used android's DatabaseUtils to help me build the result I needed, e.g. DatabaseUtils.dumpCursorToString(cursor). I did this for each of the tables I was interested in and built a return string.

Post a Comment for "Android Sqlite Dump Database From Code For Error Reporting"