现在的位置: 首页 > 综合 > 正文

查看android数据库sqlite3中的表及数据、手机上直接编辑数据库

2013年02月17日 ⁄ 综合 ⁄ 共 4104字 ⁄ 字号 评论关闭

找到一篇关于Sqlite的好文章,擅自保存下来,希望作者不要怪罪。。大笑

转自: http://www.apkbus.com/android-60977-1-1.html


最近涉及到数据库的操作,要察看手机数据库中的表是否创建成功,表中的信息是否插入成功了,因此,如何在terminal中察看呢?我用的ubuntu11.10,4G.

下面是查到的网址:

今天突然又发现,在手机上早就已经支持可以直接看数据库,对数据库进行管理了。最早是在这个网址发现的:http://www.iteye.com/topic/1117930。然后就去看了看,再看这个网址:http://aaa.andsen.dk/aSQLiteManager.html,里面有个aShell等都是可以在手机上直接查看数据库的。这个aSqliteManager也是可以直接管理的。不过我安装完之后,我手机没有sd卡,因此不能用,就是说,这款软件必须得有sd卡才能使用。大家可以自己去Google
Market上下载这两个或者同类的应用。确实很方便的。


两个原因, 促使开发人员必须直接进入sqlite3 核对表及查看相关数据: (1)为了节约时间,开发人员不一定每次写入数据后,重新读出到屏幕显示,因为这样费时费力。而数据库本身的数量统计核对等功能则可以很轻松完成这样的任务;
(2)很多开发都有直接进入数据库操作表操作数据的习惯,这样才有淋漓尽致的感觉。举一个例子,在测试批量数据的情况下,直接往数据库里插入数据,比从contentprovider insert 数据来得方便快速。

本文以Ubuntu为例,演示一下如何利用google android自带的adb工具,以在Android开发过程中,直接进入sqlit3。
当然,看完本文就了解了如何运行android的shell了。

一个前提: 0.
以下命令都基于一个前提, 那就是必须在开发环境里运行application, android仿真器必须跑起来。 这个应该很容易理解,因为仿真器没有运行的话,你的电脑上是不存在android这个环境(硬件+操作系统)。 


具体的操作过程如下:1.
找到adb, 一般位于android sdk的的tools/(老版本)或者 platform-tools/ (新版本) ,如果没有后者,则可以通过 SDK and AVD Manager 来安装 "Android SDK Platform-tools", 本文 为例: 该工具位于 /data/software/android-sdk-linux_x86/platform-tools/

2. 切换到该目录,运行 ./adb help 查看帮助 或者 ./adb shell 直接进入 android shell 管理界面, 
3. ls 命令,获取根目录下的文件列表信息, 如下所示。 可以看到,很多文件都与常见的linux系统相同,作用也大同小异,具体可以参考手册。
# ls
config
cache
sdcard
acct
mnt
d
etc
system
sys
sbin
proc
init.rc
init.goldfish.rc
init
default.prop
data
root
dev
4. 通过cd命令进入数据库表。 一般包括数据库在内的数据信息都位于data目录下。 作为对比,各位看官可以把手中的开发工具ADT切换到DDMS视图, 利用File Explorer 查看文件, 两者应该是一致的。
# cd /data

# ls

misc
local
app-private
backup
property
anr
data
dontpanic
system
app
dalvik-cache
lost+found
5. 进入 /data/data获取 contentprovider信息。 
# cd ./data/

/data/data

# ls

com.***.contactsearcher
com.android.providers.userdictionary
com.android.inputmethod.latin
com.android.quicksearchbox
jp.co.omronsoft.openwnn
com.android.inputmethod.pinyin
com.android.spare_parts
com.android.fallback
com.android.gallery
com.android.htmlviewer
com.android.certinstaller
com.android.wallpaper.livepicker
com.android.netspeed
com.android.packageinstaller
android.tts
com.android.cardock
com.android.development
com.android.defcontainer
com.android.server.vpn
com.android.soundrecorder
com.svox.pico
com.android.sdksetup
com.android.term
com.example.android.livecubes
com.example.android.softkeyboard
com.example.android.apis
com.android.gesture.builder
com.android.phone
com.android.providers.contacts
com.android.providers.applications
com.android.customlocale
com.android.providers.subscribedfeeds
com.android.providers.drm
com.android.providers.settings
com.android.launcher
com.android.speechrecorder
com.android.music
com.android.providers.telephony
com.android.calculator2
com.android.providers.media
com.android.mms
com.android.email
com.android.providers.downloads
com.android.contacts
com.android.browser
com.SC.Android.client
com.android.settings
com.android.alarmclock
com.android.camera
com.android.carhome
com.android.protips
6. 进入目标文件,获取数据库
# cd com.SC.Android.client

# ls

databases

lib

# cd databases

# ls

sc.db



7. 运行数据库, enjoy yourself! 
# sqlite3 SC.db
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from entries;
1|201236|0|welcome to go here|||||||1320504306564|1320504306564


另外,sqlite3几条关键的常用命令:sqlite>
.help 帮助信息;

sqlite> .tables 显示数据库表;
android_metadata entries 
sqlite> .show 显示数据库的属性信息;
echo: off
explain: off
headers: off
mode: list
nullvalue: ""
output: stdout
separator: "|"
width: 
sqlite> .schema entries 查询单个表结构,另外查询所有表的结构信息: select * from sqlite_master where type = "table";
.database 查看当前数据库;
.output 文件名 将查询结果输出的该文件; 而后运行查询语句, 查询将结果输出的该文件;
.output stdout 把查询结果用屏幕输出 




sqlite3 查询数据库表结构(转)

2011-05-09 14:03:22| 分类:数据库|字号
[url=]订阅[/url]





遇有未知结构的数据库时,可以通过以下方法来或许数据库中详细信息。


1. .table命令 可以查询当前数据库中所有的表名


2. select * from sqlite_master WHERE type = "table"; 可以查询到当前数据库中所有表的详细结构信息


[test@localhost ~]$ sqlite3 py.db


SQLite version 3.6.17


Enter ".help" for instructions


Enter SQL statements terminated with a ";"


sqlite> .table


py_phrase py_pinyin py_shengmu


sqlite> select * from sqlite_master WHERE type = "table";


table|py_pinyin|py_pinyin|2|CREATE TABLE py_pinyin (pinyin TEXT PREMARY KEY)


table|py_shengmu|py_shengmu|3|CREATE TABLE py_shengmu (shengmu TEXT PREMARY KEY)


table|py_phrase|py_phrase|4|CREATE TABLE py_phrase (


ylen INTEGER,


y0 INTEGER, y1 INTEGER, y2 INTEGER, y3 INTEGER, yx TEXT,


s0 INTEGER, s1 INTEGER, s2 INTEGER, s3 INTEGER,


phrase TEXT,


freq INTEGER, user_freq INTEGER)


sqlite>


1)创建数据库文件: 

抱歉!评论已关闭.