从命令行访问SQLite数据库

时间:2012-01-15 21:27:36

标签: android sqlite adb

我正在尝试从我开发的Android应用程序的命令行访问SQLite数据库。我键入adb shell以连接到设备,然后sqlite3连接到数据库。 sqlite3给出了以下错误:  / system / bin / sh:sqlite3:找不到

2 个答案:

答案 0 :(得分:0)

尝试输入“adb shell type sqlite3”以查看您的设备中是否有sqlite3可用。

对于我的设备,它显示如下

$ adb shell type sqlite3     - > sqlite3是/ system / xbin / sqlite3

的跟踪别名

答案 1 :(得分:-1)

 // Below code works on windows platform.. tried on windows 7 and windows 8 
 // This is vb script code.. save with .vb extention. 
 // any problems in saving.. please copy paste any vb file from ur system,take that second file ,open it with notepad and clear all contents, paste the below code as i did same.
 // double click to run file. output shown will ur all tables. and u can continue with      the own sql statements

 // note : works with only one emulator. many emulator are supported. 
 // please dont try this code with mobile, you wont be able to access mobile database

// start of script


Set WshShell = WScript.CreateObject("WScript.Shell")
 // set ur path to platform tools in ur sdk
strApp = "E:\Android\sdk\platform-tools"

arrPath = Split(strApp, "\")

 For i = 0 to Ubound(arrPath)
  strAppPath = strAppPath & arrPath(i) & "\"
Next 



WshShell.CurrentDirectory = strAppPath

WshShell.Run ("cmd.exe")
WScript.Sleep 50
WshShell.SendKeys "adb shell" 
WshShell.SendKeys "{ENTER}"

// put ur package name and database name over here. please put ur db name with .db          extension



WshShell.SendKeys "sqlite3 /data/data/package_name/databases/database_name"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys ".tables"
WshShell.SendKeys "{ENTER}"
Set objShell = Nothing
// script ends