Android在adb上操作sqlite3修改表数据

add by 2015.05.08

在Ubuntu12.04上查看sqlite数据库工具,可以安装 

sudo apt-get install sqliteman
非常不错的桌面工具


在Window下可以使用:SQLite Expert

----------------------------------------------------------------------------


在调试过程中,需要修改数据库中的数据,此时就要用到sqlite3工具,可以方便我们调试

由于在界面上无法打开“数据连接”,只能通过修改数据库来打开

Android在adb上操作sqlite3修改表数据_第1张图片

下面先来看下如何修改表global中的mobile_data数据

dzt@dzt-All-Series:~$ adb root
adbd is already running as root
dzt@dzt-All-Series:~$ adb remount
remount succeeded
dzt@dzt-All-Series:~$ adb shell
root@GiONEE:/ # cd data/da                                                     
dalvik-cache/   data/           data_tmpfs_log/ 
root@GiONEE:/ # cd data/dat                                                    
data/           data_tmpfs_log/ 
root@GiONEE:/ # cd data/data/com.android.providers.settings                    
root@GiONEE:/data/data/com.android.providers.settings # ls
databases
lib
root@GiONEE:/data/data/com.android.providers.settings # cd databases           
root@GiONEE:/data/data/com.android.providers.settings/databases # ls
settings.db
settings.db-journal
qlite3 settings.db                                                            <
SQLite version 3.8.6 2014-08-15 11:46:33
Enter ".help" for usage hints.
sqlite> .table
android_metadata   bookmarks          secure           
bluetooth_devices  global             system           
sqlite> select * from global;    
1|airplane_mode_on|0
2|airplane_mode_radios|cell,bluetooth,wifi,nfc,wimax
3|airplane_mode_toggleable_radios|bluetooth,wifi,nfc
4|assisted_gps_enabled|1
5|auto_time|1
6|auto_time_zone|1
7|stay_on_while_plugged_in|0
8|wifi_sleep_policy|2
9|mode_ringer|2
10|package_verifier_enable|1
12|wifi_networks_available_notification_on|1
13|bluetooth_on|0
14|cdma_cell_broadcast_sms|1
15|data_roaming|0
18|netstats_enabled|1
19|install_non_market_apps|0
20|usb_mass_storage_enabled|1
21|wifi_max_dhcp_retry_count|9
22|wifi_display_on|0
23|lock_sound|/system/media/audio/ui/Lock.ogg
24|unlock_sound|/system/media/audio/ui/Unlock.ogg
25|trusted_sound|/system/media/audio/ui/Trusted.ogg
26|power_sounds_enabled|1
27|low_battery_sound|/system/media/audio/ui/LowBattery.ogg
28|dock_sounds_enabled|0
29|desk_dock_sound|/system/media/audio/ui/Dock.ogg
30|desk_undock_sound|/system/media/audio/ui/Undock.ogg
31|car_dock_sound|/system/media/audio/ui/Dock.ogg
32|car_undock_sound|/system/media/audio/ui/Undock.ogg
33|wireless_charging_started_sound|/system/media/audio/ui/WirelessChargingStarted.ogg
34|dock_audio_media_enabled|1
35|set_install_location|0
36|default_install_location|0
37|emergency_tone|0
38|call_auto_retry|0
40|subscription_mode|0
41|low_battery_sound_timeout|0
42|wifi_scan_always_enabled|1
43|heads_up_notifications_enabled|1
44|device_name|GN9006
45|guest_user_enabled|1
46|data_roaming_2|0
47|auto_time_gps|0
48|wifi_passpoint_on|1
49|wifi_auto_join|1
50|telephony_misc_feature_config|2
51|ims_switch|1
52|wifi_watchdog_on|1
53|wifi_display_display_toast_time|20
54|wifi_display_notification_time|60
55|wifi_display_sqc_info_on|0
56|wifi_display_qe_on|1
57|wifi_display_auto_channel_selection|0
58|wifi_display_max_resolution|2
59|wifi_display_power_saving_option|1
60|wifi_display_power_saving_delay|10
61|wifi_display_latency_profiling|2
62|wifi_display_chosen_capability|
63|wifi_display_wifi_info|0,0,0,0
64|wifi_display_wfd_latency|0,0,0
65|wifi_display_security_option|1
66|adb_enabled|1
67|network_scoring_provisioned|1
68|device_provisioned|1
69|world_phone_auto_select_mode|1
70|world_phone_fdd_modem_timer|60
71|multi_sim_common|1
72|multi_sim_sms|1
73|multi_sim_voice_call|1
75|audio_safe_volume_state|3
76|mobile_data|1
77|wifi_country_code|cn
81|multi_sim_data_call|1
85|require_password_to_decrypt|1
86|preferred_network_mode|9
87|user_preferred_network_mode|9
89|wifi_on|1
sqlite> 
sqlite> update global set value='0' where name='mobile_data';                
sqlite>                             
sqlite> select * from global;
1|airplane_mode_on|0
2|airplane_mode_radios|cell,bluetooth,wifi,nfc,wimax
3|airplane_mode_toggleable_radios|bluetooth,wifi,nfc
4|assisted_gps_enabled|1
5|auto_time|1
6|auto_time_zone|1
7|stay_on_while_plugged_in|0
8|wifi_sleep_policy|2
9|mode_ringer|2
10|package_verifier_enable|1
12|wifi_networks_available_notification_on|1
13|bluetooth_on|0
14|cdma_cell_broadcast_sms|1
15|data_roaming|0
18|netstats_enabled|1
19|install_non_market_apps|0
20|usb_mass_storage_enabled|1
21|wifi_max_dhcp_retry_count|9
22|wifi_display_on|0
23|lock_sound|/system/media/audio/ui/Lock.ogg
24|unlock_sound|/system/media/audio/ui/Unlock.ogg
25|trusted_sound|/system/media/audio/ui/Trusted.ogg
26|power_sounds_enabled|1
27|low_battery_sound|/system/media/audio/ui/LowBattery.ogg
28|dock_sounds_enabled|0
29|desk_dock_sound|/system/media/audio/ui/Dock.ogg
30|desk_undock_sound|/system/media/audio/ui/Undock.ogg
31|car_dock_sound|/system/media/audio/ui/Dock.ogg
32|car_undock_sound|/system/media/audio/ui/Undock.ogg
33|wireless_charging_started_sound|/system/media/audio/ui/WirelessChargingStarted.ogg
34|dock_audio_media_enabled|1
35|set_install_location|0
36|default_install_location|0
37|emergency_tone|0
38|call_auto_retry|0
40|subscription_mode|0
41|low_battery_sound_timeout|0
42|wifi_scan_always_enabled|1
43|heads_up_notifications_enabled|1
44|device_name|GN9006
45|guest_user_enabled|1
46|data_roaming_2|0
47|auto_time_gps|0
48|wifi_passpoint_on|1
49|wifi_auto_join|1
50|telephony_misc_feature_config|2
51|ims_switch|1
52|wifi_watchdog_on|1
53|wifi_display_display_toast_time|20
54|wifi_display_notification_time|60
55|wifi_display_sqc_info_on|0
56|wifi_display_qe_on|1
57|wifi_display_auto_channel_selection|0
58|wifi_display_max_resolution|2
59|wifi_display_power_saving_option|1
60|wifi_display_power_saving_delay|10
61|wifi_display_latency_profiling|2
62|wifi_display_chosen_capability|
63|wifi_display_wifi_info|0,0,0,0
64|wifi_display_wfd_latency|0,0,0
65|wifi_display_security_option|1
66|adb_enabled|1
67|network_scoring_provisioned|1
68|device_provisioned|1
69|world_phone_auto_select_mode|1
70|world_phone_fdd_modem_timer|60
71|multi_sim_common|1
72|multi_sim_sms|1
73|multi_sim_voice_call|1
75|audio_safe_volume_state|3
76|mobile_data|0
77|wifi_country_code|cn
81|multi_sim_data_call|1
85|require_password_to_decrypt|1
86|preferred_network_mode|9
87|user_preferred_network_mode|9
89|wifi_on|1
sqlite> 
上面的过程就把settings.db数据库表global中数据mobile_data从1改为0

下面来看下查看数据库的一些命令:

.database 查看数据库信息

sqlite> .database
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main             /data/data/com.android.providers.media/databases/external.
sqlite> 
.table 查看表名称
sqlite> .table
album_art              audio_genres           log                  
album_info             audio_genres_map       search               
albums                 audio_genres_map_noid  searchhelpertitle    
android_metadata       audio_meta             thumbnails           
artist_info            audio_playlists        video                
artists                audio_playlists_map    videothumbnails      
artists_albums_map     files                
audio                  images               
sqlite> 

.schema 命令可以查看创建数据表时的SQL命令

sqlite> .schema
CREATE TABLE album_art (album_id INTEGER PRIMARY KEY,_data TEXT);
CREATE TABLE albums (album_id INTEGER PRIMARY KEY,album_key TEXT NOT NULL UNIQUE,album TEXT NOT NULL, album_pinyin_key TEXT);
CREATE TABLE android_metadata (locale TEXT);
CREATE TABLE artists (artist_id INTEGER PRIMARY KEY,artist_key TEXT NOT NULL UNIQUE,artist TEXT NOT NULL, artist_pinyin_key TEXT);
CREATE TABLE audio_genres (_id INTEGER PRIMARY KEY,name TEXT NOT NULL);
CREATE TABLE "audio_genres_map" (_id INTEGER PRIMARY KEY,audio_id INTEGER NOT NULL,genre_id INTEGER NOT NULL,UNIQUE (audio_id,genre_id) ON CONFLICT IGNORE);
CREATE TABLE audio_playlists_map (_id INTEGER PRIMARY KEY,audio_id INTEGER NOT NULL,playlist_id INTEGER NOT NULL,play_order INTEGER NOT NULL);
CREATE TABLE "files" (_id INTEGER PRIMARY KEY AUTOINCREMENT,_data TEXT UNIQUE COLLATE NOCASE,_size INTEGER,format INTEGER,parent INTEGER,date_added INTEGER,date_modified INTEGER,mime_type TEXT,title TEXT,description TEXT,_display_name TEXT,picasa_id TEXT,orientation INTEGER,latitude DOUBLE,longitude DOUBLE,datetaken INTEGER,mini_thumb_magic INTEGER,bucket_id TEXT,bucket_display_name TEXT,isprivate INTEGER,title_key TEXT,artist_id INTEGER,album_id INTEGER,composer TEXT,track INTEGER,year INTEGER CHECK(year!=0),is_ringtone INTEGER,is_music INTEGER,is_alarm INTEGER,is_notification INTEGER,is_podcast INTEGER,album_artist TEXT,duration INTEGER,bookmark INTEGER,artist TEXT,album TEXT,resolution TEXT,tags TEXT,category TEXT,language TEXT,mini_thumb_data TEXT,name TEXT,media_type INTEGER,old_id INTEGER,storage_id INTEGER,is_drm INTEGER,width INTEGER, height INTEGER,drm_content_uri TEXT,drm_offset INTEGER,drm_dataLen INTEGER,drm_rights_issuer TEXT,drm_content_name TEXT,drm_content_description TEXT,drm_content_vendor TEXT,drm_icon_uri TEXT,drm_method INTEGER,title_pinyin_key TEXT,name_pinyin_key TEXT,file_name TEXT,file_type INTEGER DEFAULT 0,group_id INTEGER DEFAULT 0,group_index INTEGER DEFAULT 0,focus_value_high INTEGER DEFAULT 0,focus_value_low INTEGER DEFAULT 0,is_best_shot INTEGER DEFAULT 0,group_count INTEGER DEFAULT 0,is_live_photo INTEGER DEFAULT 0, slow_motion_speed TEXT, is_record INTEGER DEFAULT 0);
CREATE TABLE "log" (time DATETIME, message TEXT);
CREATE TABLE thumbnails (_id INTEGER PRIMARY KEY,_data TEXT,image_id INTEGER,kind INTEGER,width INTEGER,height INTEGER);
CREATE TABLE videothumbnails (_id INTEGER PRIMARY KEY,_data TEXT,video_id INTEGER,kind INTEGER,width INTEGER,height INTEGER);
CREATE VIEW album_info AS SELECT audio.album_id AS _id, album, album_key, album_pinyin_key,MIN(year) AS minyear, MAX(year) AS maxyear, artist, artist_id, artist_key, artist_pinyin_key,count(*) AS numsongs,album_art._data AS album_art FROM audio LEFT OUTER JOIN album_art ON audio.album_id=album_art.album_id WHERE is_music=1 GROUP BY audio.album_id;
CREATE VIEW artist_info AS SELECT artist_id AS _id, artist, artist_key, artist_pinyin_key,COUNT(DISTINCT album_key) AS number_of_albums, COUNT(*) AS number_of_tracks FROM audio WHERE is_music=1 GROUP BY artist_key;
CREATE VIEW artists_albums_map AS SELECT DISTINCT artist_id, album_id FROM audio_meta;
CREATE VIEW audio as SELECT * FROM audio_meta LEFT OUTER JOIN artists ON audio_meta.artist_id=artists.artist_id LEFT OUTER JOIN albums ON audio_meta.album_id=albums.album_id;
CREATE VIEW audio_genres_map_noid AS SELECT audio_id,genre_id from audio_genres_map;
CREATE VIEW audio_meta AS SELECT _id,_data,_display_name,_size,mime_type,date_added,is_drm,date_modified,title,title_key,duration,artist_id,composer,album_id,track,year,is_ringtone,is_music,is_alarm,is_notification,is_podcast,bookmark,album_artist,drm_content_uri,drm_offset,drm_dataLen,drm_rights_issuer,drm_content_name,drm_content_description,drm_content_vendor,drm_icon_uri,drm_method,title_pinyin_key,is_record FROM files WHERE media_type=2;
CREATE VIEW audio_playlists AS SELECT _id,_data,name,date_added,date_modified,name_pinyin_key FROM files WHERE media_type=4;
CREATE VIEW images AS SELECT _id,_data,_size,_display_name,mime_type,title,date_added,date_modified,description,picasa_id,isprivate,latitude,longitude,datetaken,orientation,mini_thumb_magic,bucket_id,bucket_display_name,width,height,is_drm,drm_content_uri,drm_offset,drm_dataLen,drm_rights_issuer,drm_content_name,drm_content_description,drm_content_vendor,drm_icon_uri,drm_method,group_id,group_index,focus_value_high,focus_value_low,is_best_shot,group_count FROM files WHERE media_type=1;
CREATE VIEW search AS SELECT _id,'artist' AS mime_type,artist,NULL AS album,NULL AS title,artist AS text1,NULL AS text2,number_of_albums AS data1,number_of_tracks AS data2,artist_key AS match,'content://media/external/audio/artists/'||_id AS suggest_intent_data,1 AS grouporder FROM artist_info WHERE (artist!='') UNION ALL SELECT _id,'album' AS mime_type,artist,album,NULL AS title,album AS text1,artist AS text2,NULL AS data1,NULL AS data2,artist_key||' '||album_key AS match,'content://media/external/audio/albums/'||_id AS suggest_intent_data,2 AS grouporder FROM album_info WHERE (album!='') UNION ALL SELECT searchhelpertitle._id AS _id,mime_type,artist,album,title,title AS text1,artist AS text2,NULL AS data1,NULL AS data2,artist_key||' '||album_key||' '||title_key AS match,'content://media/external/audio/media/'||searchhelpertitle._id AS suggest_intent_data,3 AS grouporder FROM searchhelpertitle WHERE (title != '');
CREATE VIEW searchhelpertitle AS SELECT * FROM audio ORDER BY title_key;
CREATE VIEW video AS SELECT _id,_data,_display_name,_size,mime_type,date_added,date_modified,title,duration,artist,album,resolution,description,isprivate,tags,category,language,mini_thumb_data,latitude,longitude,datetaken,mini_thumb_magic,bucket_id,bucket_display_name,bookmark,width,height,is_drm,drm_content_uri,drm_offset,drm_dataLen,drm_rights_issuer,drm_content_name,drm_content_description,drm_content_vendor,drm_icon_uri,drm_method,is_live_photo,slow_motion_speed,orientation FROM files WHERE media_type=3;
CREATE INDEX album_id_idx ON files(album_id);
CREATE INDEX album_idx on albums(album);
CREATE INDEX albumkey_index on albums(album_key);
CREATE INDEX albumpinyinkey_index on albums(album_pinyin_key);
CREATE INDEX artist_id_idx ON files(artist_id);
CREATE INDEX artist_idx on artists(artist);
CREATE INDEX artistkey_index on artists(artist_key);
CREATE INDEX artistpinyinkey_index on artists(artist_pinyin_key);
CREATE INDEX bucket_index on files(bucket_id,media_type,datetaken, _id);
CREATE INDEX bucket_name on files(bucket_id,media_type,bucket_display_name);
CREATE INDEX format_index ON files(format);
CREATE INDEX image_id_index on thumbnails(image_id);
CREATE INDEX media_type_index ON files(media_type);
CREATE INDEX parent_index ON files(parent);
CREATE INDEX path_index ON files(_data);
CREATE INDEX sort_index ON files(datetaken ASC, _id ASC);
CREATE INDEX title_idx ON files(title);
CREATE INDEX titlekey_index ON files(title_key);
CREATE INDEX video_id_index on videothumbnails(video_id);
CREATE TRIGGER albumart_cleanup1 DELETE ON albums BEGIN DELETE FROM album_art WHERE album_id = old.album_id;END;
CREATE TRIGGER albumart_cleanup2 DELETE ON album_art BEGIN SELECT _DELETE_FILE(old._data);END;
CREATE TRIGGER audio_genres_cleanup DELETE ON audio_genres BEGIN DELETE FROM audio_genres_map WHERE genre_id = old._id;END;
CREATE TRIGGER audio_playlists_cleanup DELETE ON files WHEN old.media_type=4 BEGIN DELETE FROM audio_playlists_map WHERE playlist_id = old._id;SELECT _DELETE_FILE(old._data);END;
CREATE TRIGGER files_cleanup DELETE ON files BEGIN SELECT _OBJECT_REMOVED(old._id);END;
sqlite> 
.schema table_name 查看创建表table_name时的SQL的命令

sqlite> .schema files     
CREATE TABLE "files" (_id INTEGER PRIMARY KEY AUTOINCREMENT,_data TEXT UNIQUE COLLATE NOCASE,_size INTEGER,format INTEGER,parent INTEGER,date_added INTEGER,date_modified INTEGER,mime_type TEXT,title TEXT,description TEXT,_display_name TEXT,picasa_id TEXT,orientation INTEGER,latitude DOUBLE,longitude DOUBLE,datetaken INTEGER,mini_thumb_magic INTEGER,bucket_id TEXT,bucket_display_name TEXT,isprivate INTEGER,title_key TEXT,artist_id INTEGER,album_id INTEGER,composer TEXT,track INTEGER,year INTEGER CHECK(year!=0),is_ringtone INTEGER,is_music INTEGER,is_alarm INTEGER,is_notification INTEGER,is_podcast INTEGER,album_artist TEXT,duration INTEGER,bookmark INTEGER,artist TEXT,album TEXT,resolution TEXT,tags TEXT,category TEXT,language TEXT,mini_thumb_data TEXT,name TEXT,media_type INTEGER,old_id INTEGER,storage_id INTEGER,is_drm INTEGER,width INTEGER, height INTEGER,drm_content_uri TEXT,drm_offset INTEGER,drm_dataLen INTEGER,drm_rights_issuer TEXT,drm_content_name TEXT,drm_content_description TEXT,drm_content_vendor TEXT,drm_icon_uri TEXT,drm_method INTEGER,title_pinyin_key TEXT,name_pinyin_key TEXT,file_name TEXT,file_type INTEGER DEFAULT 0,group_id INTEGER DEFAULT 0,group_index INTEGER DEFAULT 0,focus_value_high INTEGER DEFAULT 0,focus_value_low INTEGER DEFAULT 0,is_best_shot INTEGER DEFAULT 0,group_count INTEGER DEFAULT 0,is_live_photo INTEGER DEFAULT 0, slow_motion_speed TEXT, is_record INTEGER DEFAULT 0);
CREATE INDEX album_id_idx ON files(album_id);
CREATE INDEX artist_id_idx ON files(artist_id);
CREATE INDEX bucket_index on files(bucket_id,media_type,datetaken, _id);
CREATE INDEX bucket_name on files(bucket_id,media_type,bucket_display_name);
CREATE INDEX format_index ON files(format);
CREATE INDEX media_type_index ON files(media_type);
CREATE INDEX parent_index ON files(parent);
CREATE INDEX path_index ON files(_data);
CREATE INDEX sort_index ON files(datetaken ASC, _id ASC);
CREATE INDEX title_idx ON files(title);
CREATE INDEX titlekey_index ON files(title_key);
CREATE TRIGGER audio_playlists_cleanup DELETE ON files WHEN old.media_type=4 BEGIN DELETE FROM audio_playlists_map WHERE playlist_id = old._id;SELECT _DELETE_FILE(old._data);END;
CREATE TRIGGER files_cleanup DELETE ON files BEGIN SELECT _OBJECT_REMOVED(old._id);END;
sqlite> 
.quit 退出命令行接口
sqlite> .quit
root@GiONEE:/data/data/com.android.providers.media/databases # 

你可能感兴趣的:(Android进阶)