Android的SQLite数据库 - 复制表从资产到本地应用程序数据库 [英] Android SQLite Database - Copying Table From Assets to Local App Database

查看:335
本文介绍了Android的SQLite数据库 - 复制表从资产到本地应用程序数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有资产的文件夹的数据库。我复制此当应用程序第一次运行结束。该数据库包含无关的三个表。

然而,我按钮对每个列表(其中,数据存储在一个表)重置的数据,所以有可能删除当前表,然后复制整个存储的一个?或沿着这些线路的东西,也许用新的覆盖旧桌子吗? (我愿做这种方式的原因是因为它快得多复制了开展上百插入操作!)

目前的方法我到目前为止有:

在DatabaseHelper类:

 公共无效recreateTable(字符串tableName值){
    //逻辑的删除旧表,并插入新的放在这里
}

在类编辑列表中显示

 公共无效resetList(){
    DatabaseHelper DBHP =新DatabaseHelper(本);
    dbhp.open();
    recreateTable(STC);
    Toast.makeText(generalContext!列表复位,Toast.LENGTH_LONG).show();
    dbhp.close();
}


解决方案

请参阅的http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/.

您可以precreate数据库和复制precreated版本,一旦用户重新设置表。

希望这有助于。

感谢。

So I have a database in the assets folder. I copy this over when the app is first run. The database contains three tables unrelated.

However, I have buttons to reset data for each list (where data is stored in a table), so is it possible to delete the current table and then copy the stored one across? Or something along those lines, maybe overwrite the old table with the new one? (The reason I wish to do it this way is because it's much quicker to copy that to carry out hundreds of insert operations!)

The current methods I have so far are:

In the DatabaseHelper class:

public void recreateTable(String tableName) {
    // Logic for removing old table and inserting new one goes here     
}

In the class for editing the list displayed

public void resetList() {
    DatabaseHelper dbhp = new DatabaseHelper(this);
    dbhp.open();
    recreateTable("STC");
    Toast.makeText(generalContext, "List Reset!", Toast.LENGTH_LONG).show();
    dbhp.close();
}

解决方案

Please see http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/.

You can precreate your database and copy the precreated version, once the user resets the table.

Hope this helps.

Thanks.

这篇关于Android的SQLite数据库 - 复制表从资产到本地应用程序数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆