您的位置:首页 > 数据库

区别与网上的数据库备份恢复:使用内存集合list或者map

2016-03-16 18:14 357 查看
网上流传较多的是:数据库文件的备份存储和文件还原 :也就是数据库操作之前保存一份原来的文件 需要还原的时候 用这份文件替换操作了的数据库文件

但是对于条数有限制的数据库 表格 需要还原:只需要保存原来的一份数据库表中的 数据 需要还原的时候 还原回来就可以了

但是 不能使用下列的方法

从数据库表中取出全部数据 放到一个集合1中 然后 new 一个新集合2 2.addall(1)

//特别注意:集合中保存的是对象的地址引用:操作1 改变了 同时2中相同对象也发生改变:所以就不再具备使用2来还原的功能

所以上述方法是错误的

那么:实际是

在遍历数据库表 得到cursor的时候:new对象的时候 new 两个对象 一个网 集合1中存 一个往集合2中存 改变中改变 集合1 集合2为恢复数据库表做准备

//获取数据库的集合

Cursor cursor= App.getSqlManager().seleteAll(tableName,new String[]{“id”,”name”,”mobile”,”identitycard”,”agent”},”id desc”);

if (cursor!=null&&cursor.getCount()>0){

Log.e(“jxf”, “customer数据库有数据”);

while(cursor.moveToNext()) {

BuyTicketInfo bean=new BuyTicketInfo();

BuyTicketInfo bean1=new BuyTicketInfo();

bean.id=cursor.getInt(0);

bean1.id=cursor.getInt(0);

bean.name=cursor.getString(1);

bean1.name=cursor.getString(1);

bean.mobile=cursor.getString(2);

bean1.mobile=cursor.getString(2);

bean.identityCard=cursor.getString(3);

bean1.identityCard=cursor.getString(3);

bean.agent=cursor.getString(4);

bean1.agent=cursor.getString(4);

//默认的勾选框是不勾选的

bean.isCheck=false;

//1 新学员 2 复训

bean.identify=1;

sqlCustomers.add(bean);

tempBackUpSql.add(bean1);

}

cursor.close();

// if (sqlCustomers.size()>40){

// int id=sqlCustomers.get(39).id;

// App.getSqlManager().deleteOne(tableName, “id
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息