This article mainly introduces how to view the data in the SQLite database and the common commands of Sqlite3 in the development of Android.
1. Original View SQLite data method
Eclipse Menu Window-open Perspective-ddms into Ddms view. Then, in file Explorer view, expand Path/data/data/package_name/databases/, save the DB file pull from device to your computer, and then use Navicat, Sqlitespy or other software to open the view, the whole process is quite complex, and the data changes once again need to be re-operated.
Then can not be in the window mode real-time view of SQLite data, but we can in the command line mode in real-time view of the data in SQLite
2. Real-time viewing of SQLite data
You don't have to knock dozens of characters at a time, just one batch file can go into the database each time, new file Enterdb.bat, content is
ADB Shell Sqlite3/data/data/package_name/databases/dbname
Indicates the first execution of the ADB shell into the shell mode, and then execute sqlite3/data/data/package_name/databases/dbname into the dbname This database, is not a key to complete, ^_*.
Detailed instructions for each command are described below
(1) Shell mode entering the AVD
Open the command line and enter
ADB shell
Enter shell mode and, if ADB is not bound to path, run this command in the Platform-tools directory of ANDROID-SDK.
If more than one AVD exists at the same time, you need to specify the device number. Available through
-S emulator-5554 Shell
ADB devices means to view all current devices, adb-s emulator-5554 shell-specific device, where emulator-5554 is the device ID
(2) Enter the database directory to view the database
Cd/data/data/package_name;ls
The package_name is the package name of the app, which is the androidmanifest.xml of the manifest node in the Packages property value.
(3) Operation database
3. Common commands for Sqlite3
. Tables Show All Tables
. Schema shows the schema of the database
. Schema table_name The schema of the display table
. Headers on displays the title bar, the field name bar, such as when viewing data in data, the default SELECT * FROM table_name does not display the field name.
ALTER TABLE modifies tables. Change table name-ALTER TABLE name RENAME to new table name; Add a column-ALTER table name add column name data type qualifier
SELECT * from Sqlite_master where type= "table"; Show the structure of all tables
SELECT * from Sqlite_master where type= "table" and name= "table_name"; Show the structure of a table
DROP TABLE table_name Delete tables
. Quit quit
. read filename Executes the SQL in the filename
Standard SQL statements can also be used, but must end with semicolons , as follows
SELECT statement;
Delete statement;
UPDATE statement;
INSERT statement;
Android One-click Direct view of SQLite database data