2011-10-03 80 views
1

对于开发,有时我们需要更快的编程,即我们程序的SQLite数据库状态。但是我只能提取数据库,如果它在模拟器上,而不是移动的。我怎样才能看到SQLite数据库(无模拟器)?

那么我确切的问题是有没有办法看到android的sqlite数据库或一种方式来提取它?

如果对这个问题没有很好的答案。当你需要知道表的数据库状态时,如何处理这些编程问题?

+0

根您的设备....或管理nexsus 1或为此总是更好地尝试在em首先检查数据库是否正确,然后在设备上测试 – ingsaurabh

+0

对不起,但使用em不是我想做的事它更快 –

+0

你只需要探索创建的数据库? – Basil

回答

4

您可以使用

adb shell 

来获得设备的一个root shell,然后使用任何你喜欢直接在数据库中。导出,运行脚本等等等等

你可以看看这个链接的详细信息:

developer.android.com/studio/command-line/sqlite3.html

Abount SQLite的命令: http://www.sqlite.org/sqlite.html

+0

Thx为你的答案,你能给我的方式来提取或管理sqlite数据库为了打勾你? –

+0

@ A.Quiroga不客气。我添加了必要的链接到我的答案。 – vbence

+0

+1和一个易用性友好的解决方案 –

3

您可以从外壳提到vbence做到这一点。另一种方法是以编程方式将数据库文件复制到SD卡。称这种现象onStop()

File source = new File("data/data/com.ACME/databases/" + DATABASE_NAME); 
File dest = new File(Environment.getExternalStorageDirectory() + "/" + DATABASE_NAME + ".db"); 

public static void copyFile(File sourceFile, File destFile) { 

FileChannel source = null; 
FileChannel destination = null; 

    try { 
     if (!destFile.exists()) { 
      destFile.createNewFile(); 
     } 

    source = new FileInputStream(sourceFile).getChannel(); 
    destination = new FileOutputStream(destFile).getChannel(); 
    destination.transferFrom(source, 0, source.size()); 

    } catch (Exception e) { 
     /* handle exception... */ 
    } finally { 
    try { 
      if (source != null) { 
       source.close(); 
      } 
      if (destination != null) { 
       destination.close(); 
      } 
     } catch (Exception e) { 
      /* handle exception... */ 
     } 
    } 
} 
+0

+1为有用的答案。 –

-1

对于探索,你可以使用Mozilla Firefox的插件SQLite数据库命名SQLite Manager。运行应用程序后,使用文件浏览器将数据库拖到您的系统,然后打开firefox - > Tools - > SQLite Manager。一个窗口将会出现,并且有一个选项可以打开数据库,点击它并指向你已经拉出数据库的路径。打开该数据库,您可以看到创建的表格和您输入的值。您也可以选择添加,编辑,删除和更新值。

+0

Android上的SQLite –

相关问题