In the Android development environment, ADB is our most frequently used debugging tool for Android development, and its use is of course what our Android developers have to master.
ADB overview
Android Debug Bridge,android Debug Bridge, abbreviated as ADB, is a universal tool for managing emulator or real state, using the client-server model, consisting of three parts:
1, the client part, running on the development of the computer, you can run the ADB command on the command line to invoke the client, such as ADB plug-ins and Ddms such as Android tools can also invoke the ADB client.
2, the service side portion, is running in the development uses the computer the background process, manages the client to communicate with the daemon which runs in the simulator or the real machine.
3, the daemon part, runs in the simulator or the handset backstage.
Using the ADB command
The use of the ADB command from the command line or script file of the development computer is:
adb [-d|-e|-s <serialnumber>] <command>
When used, the program calls the ADB client. Because the ADB client does not need to be associated with any emulator, if more than one emulator or phone is running, you need to use the-D parameter to specify which one to manipulate.
ADB devices
The result of the execution is that ADB outputs the following status information for each device:
CD Command List
The following table lists all the commands supported by ADB and their descriptions:
Category |
Command |
Description |
Note |
Options available |
-D |
command is only valid for USB devices |
If there are multiple USB devices, an error is returned |
-E |
command is valid only for running emulators |
If there are multiple running emulators, an error is returned |
-S <serialNumber> |
The command is valid only for an emulator or phone with a specific serial number associated with the ADB (for example, "emulator-5556"). |
If you do not specify a device, an error is returned |
General items |
Devices |
Output a list of all associated emulators or mobile devices |
See querying for Emulator/device Instances for more information. |
Help |
Output ADB-supported commands |
|
Version |
Version number of the output adb |
|
Debug items |
Logcat [<option>] [<filter-specs>] |
Output log information on the screen |
|
Bugreport |
To report a bug, output dumpsys,dumpstate and logcat data on the screen |
|
Jdwp |
Output valid JDWP process information |
You can use the forward jdwp:<pid> transform port to connect to the specified JDWP process, for example: ADB forward tcp:8000 jdwp:472 Jdb-attach localhost:8000 |
Data item |
Install <path-to-apk> |
Install the application (Specify the. apk file with the full path) |
|
Pull <remote> <local> |
From the file specified by the development machine copy to the emulator or phone |
|
Push <local> <remote> |
From the emulator or phone copy file to the development machine |
|
Ports and network items |
Forward <local> <remote> |
Connect to the specified port of the emulator or phone from the local port conversion |
The port can be expressed in the following format: L tcp:<portnum> L Local:<unix Domain Socket name> L Dev:<character Device name> L jdwp:<pid> |
PPP <tty> [Parm] ... |
Run UPP via USB L <TTY>-PPP the TTY in the stream. For example:/dev/omap_csmi_ttyl. l [parm]...-0 to multiple PPP/PPPD options, such as Defaultroute, Local, Notty, and more. Note Do not start the PPP connection automatically |
|
Script entry |
Get-serialno |
Serial number of the output ADB object |
See querying for Emulator/device instances for more information. |
Get-state |
Status of the output ADB device |
Wait-for-device |
Blocking is performed until the device is connected, that is, the device status is devices. |
This can be added before other commands, so the ADB waits for the emulator or mobile device to be connected before executing the command, for example: Note that the command does not wait for the system to start completely, so commands that need to be fully booted before the system can be executed, such as the Install command, require Android Package Manager support, but it must be valid after the system is fully booted. The following command The install will be executed after the emulator or phone has been connected to ADB, but the system is not fully booted, causing an error. |
Service-Side items |
Start-server |
Detects if the ADB service process is started and starts it if it is not started. |
|
Kill-server |
Terminating the service-side process |
|
Shell |
Shell |
Start the remote shell on the target simulator or phone |
See issuing Shell commands for more information. |
Shell [<shellcommand>] |
Execute Shellcommand on the target emulator or phone and exit the remote shell |
SqliteCommand
This chapter will explain the simple but useful commands that SQLite programmers use. These commands are called SQLite point commands, which differ in that they do not end with semicolons (;).
Let's type a simple sqlite3 command at the command prompt, and you can use various SQLite commands at the SQLite command prompt.
$sqlite 3SQLite3.3. 6Enter". Help"for instructionssqlite>
To get a list of available point commands, you can enter ". Help" at any time. For example:
SQLite;. Help
The above command displays a list of the various important SQLite point commands, as follows:
Command |
Description |
. backup? Db? FILE |
Back up the DB database (the default is "main") to the file. |
. Bail on| OFF |
Stop after an error occurs. The default is OFF. |
. databases |
Lists the name and file of the attached database. |
. Dump? TABLE? |
Dumps the database in SQL text format. If table tables are specified, only table tables matching the like pattern are dumped. |
. Echo on| OFF |
Turns the echo command on or off. |
. exit |
Exit the SQLite prompt. |
. Explain on| OFF |
Turn on or off the output mode that is appropriate for the EXPLAIN. If there is no parameter, then EXPLAIN on, and EXPLAIN on. |
. Header (s) on| OFF |
Turns the head display on or off. |
. Help |
Displays the message. |
. Import FILE TABLE |
Import data from file files into table tables. |
. Indices? TABLE? |
Displays the names of all indexes. If table tables are specified, only the indexes of table tables that match the like pattern are displayed. |
. Load FILE? ENTRY? |
Load an extension library. |
. Log File|off |
Turn the log on or off. File files can be stderr (standard error)/stdout (standard output). |
. Mode mode |
To set the output mode, mode can be one of the following:
csv comma-separated values
Column left-aligned columns
HTML HTML <table> Code
Insert SQL Insert (INSERT) statements for table tables
Line one value per row
list values separated by the. Separator string
tabs A Tab-delimited value
Tcl TCL list elements
|
. Nullvalue STRING |
Outputs a string string in place of a NULL value. |
. Output FILENAME |
Send output to filename file. |
. Output stdout |
Send output to screen. |
. Print STRING ... |
Outputs a string literal, literally. |
. prompt MAIN CONTINUE |
Replace the standard prompt. |
. Quit |
Exit the SQLite prompt. |
. Read FILENAME |
Executes the SQL in the filename file. |
. Schema? TABLE? |
Displays the CREATE statement. If table tables are specified, only table tables matching the like pattern are displayed. |
. Separator STRING |
Change the delimiter used by the output mode and. Import. |
. Show |
Displays the current values for the various settings. |
. Stats on| OFF |
Turn statistics on or off. |
. Tables? PATTERN? |
Lists the names of the tables that match the like pattern. |
. Timeout MS |
Try to open the locked table for MS microseconds. |
. width num num |
Sets the column width for the "column" mode. |
. Timer on| OFF |
Turn on or off the CPU timer measurement. |
Let's try using the . Show command to see the default settings for the SQLite command prompt.
Sqlite>.show echo:off explain:off headers:off mode:columnnullvalue: "" output: Stdoutseparator: "|" Width:sqlite>
Make sure there are no spaces between the sqlite> prompt and the point command, otherwise it will not work correctly.
Formatted output
You can use the following point commands to format the output as listed below for this tutorial:
SQLite;. Header Onsqlite;. Mode Columnsqlite;. Timer Onsqlite>
The above settings will produce output in the following format:
ID NAME age ADDRESS SALARY---------- ---------- ---------- ---------- -------- --1 Paul California 20000.02 Allen Texas 15000.03 Teddy Norway 20000.04 Mark rich-mond 65000.05 David Texas 85000.06 Kim south-hall 45000.07 James Houston 10000.0CPU time:user 0.000000 sys 0.000000
Sqlite_master form
The primary table holds the key information for the database table and names it as sqlite_master. To view a summary of a table, you can do this as follows:
Sqlite>.schema Sqlite_master
This will produce the following results:
CREATE TABLE sqlite_master ( type text, name text, tbl_name text, rootpage integer, sql text);
SqliteGrammar
SQLite follows a unique set of rules and guidelines called grammar. This tutorial lists all the basic SQLite grammars and gives you a quick start to SQLite.
SQLite statements
All SQLite statements can start with any keyword, such as SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, and so on, all of the statements end with a semicolon (;).
SQLite ANALYZE Statement:
Analyze;oranalyze Database_name;oranalyze Database_name.table_name;
SQLite and/or clause:
SELECT column1, Column2....columnnfrom table_namewhere CONDITION-1 {and|or} CONDITION-2;
SQLite ALTER TABLE Statement:
ALTER TABLE table_name ADD COLUMN column_def ...;
SQLite ALTER TABLE Statement (Rename):
ALTER TABLE table_name RENAME to new_table_name;
SQLite ATTACH DATABASE Statement:
ATTACH DATABASE ' DatabaseName ' as ' alias-name ';
SQLite BEGIN TRANSACTION Statement:
Begin;orbegin EXCLUSIVE TRANSACTION;
SQLite between clause:
SELECT column1, Column2....columnnfrom table_namewhere column_name between Val-1 and Val-2;
SQLite COMMIT Statement:
COMMIT;
SQLite CREATE INDEX Statement:
CREATE INDEX Index_nameon table_name (column_name COLLATE nocase);
SQLite CREATE UNIQUE INDEX statement:
CREATE UNIQUE INDEX Index_nameon table_name (column1, Column2,... columnn);
SQLite CREATE TABLE Statement:
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, ... .. COLUMNN datatype, PRIMARY KEY (one or more columns));
SQLite CREATE TRIGGER Statement:
CREATE TRIGGER Database_name.trigger_name before INSERT on table_name for each rowbegin STMT1; STMT2; .... END;
SQLite CREATE VIEW Statement:
CREATE VIEW database_name.view_name asselect statement ...;
SQLite CREATE VIRTUAL TABLE statement:
CREATE virtual table Database_name.table_name USING weblog (access.log); orcreate virtual Table Database_name.table_name USING Fts3 ();
SQLite COMMIT TRANSACTION Statement:
COMMIT;
SQLite COUNT clause:
SELECT COUNT (column_name) from table_namewhere CONDITION;
SQLite DELETE Statement:
DELETE from Table_namewhere {CONDITION};
SQLite DETACH DATABASE Statement:
DETACH DATABASE ' Alias-name ';
SQLite DISTINCT clause:
SELECT DISTINCT column1, Column2....columnnfrom table_name;
SQLite DROP INDEX Statement:
DROP INDEX Database_name.index_name;
SQLite DROP TABLE Statement:
DROP TABLE Database_name.table_name;
SQLite DROP VIEW Statement:
DROP INDEX Database_name.view_name;
SQLite DROP TRIGGER Statement:
DROP INDEX Database_name.trigger_name;
SQLite EXISTS clause:
Select Column1, Column2....columnnfrom table_namewhere column_name EXISTS (SELECT * FROM table_name);
SQLite EXPLAIN Statement:
EXPLAIN INSERT statement...;or EXPLAIN QUERY PLAN SELECT statement ...;
SQLite GLOB clause:
SELECT column1, Column2....columnnfrom table_namewhere column_name GLOB {PATTERN};
SQLite GROUP BY clause:
SELECT SUM (column_name) from table_namewhere conditiongroup by column_name;
SQLite has a clause:
SELECT SUM (column_name) from table_namewhere conditiongroup by column_namehaving (arithematic function condition);
SQLite INSERT into statement:
INSERT into table_name (column1, COLUMN2....COLUMNN) VALUES (value1, Value2....valuen);
SQLite in clause:
SELECT column1, Column2....columnnfrom table_namewhere column_name in (val-1, Val-2,... val-n);
SQLite LIKE clause:
SELECT column1, Column2....columnnfrom table_namewhere column_name like {PATTERN};
SQLite not IN clause:
SELECT column1, Column2....columnnfrom table_namewhere column_name not in (Val-1, Val-2,... val-n);
SQLite ORDER BY clause:
SELECT column1, Column2....columnnfrom table_namewhere Conditionorder by column_name {asc| DESC};
SQLite PRAGMA Statement:
PRAGMA Pragma_name; For Example:pragma Page_size; PRAGMA cache_size = 1024; PRAGMA Table_info (table_name);
SQLite RELEASE savepoint Statement:
RELEASE savepoint_name;
SQLite REINDEX Statement:
REINDEX collation_name; REINDEX Database_name.index_name; REINDEX Database_name.table_name;
SQLite ROLLBACK Statement:
Rollback;orrollback to SavePoint Savepoint_name;
SQLite savepoint Statement:
SavePoint savepoint_name;
SQLite SELECT Statement:
SELECT column1, Column2....columnnfrom table_name;
SQLite UPDATE Statement:
UPDATE table_nameset column1 = value1, Column2 = value2....columnn=valuen[WHERE CONDITION];
SQLite VACUUM Statement:
VACUUM;
SQLite WHERE clause:
SELECT column1, Column2....columnnfrom table_namewhere CONDITION;
ANDROID-ADB Common Commands and SQLite