简体   繁体   English

实际未插入的行

[英]Inserted rows are not actually inserted

I am downloading some data over network in JSON format and after retrieving it, I am storing it in SqlLiteDatabase. 我正在以JSON格式通过网络下载一些数据,并在检索到这些数据后,将其存储在SqlLiteDatabase中。 Earlier I use to fetch the data and display it in RecyclerView but now I am storing it in SqlLite Database and then displaying it in RecyclerView. 以前我用来获取数据并在RecyclerView中显示,但现在我将其存储在SqlLite数据库中,然后在RecyclerView中显示。 However the data get stored successfully as it return true but when I display the data, it shows nothing. 但是,数据成功存储,因为它返回true,但是当我显示数据时,它什么也没有显示。 To check if the data exist or not after being added, I get the number of count on available data and it returns 0. 为了在添加数据后检查数据是否存在,我获得了可用数据的数量,并且它返回0。

Here are the codes: 以下是代码:

public boolean create(List<PGCardItemReturn> objectPg) {

    SQLiteDatabase db = this.getWritableDatabase();

    PGCardItemReturn lastItem = null;;
    db.beginTransaction();
    String sql = "Insert or Replace into tenant_pg (id,furnishing,area,price,numberofbeds,image_url) values(?,?,?,?,?,?)";
    SQLiteStatement insert = db.compileStatement(sql);
    for(int i=0;i<objectPg.size();i++){
        PGCardItemReturn item = objectPg.get(i);
        if(i == (this.count()-1)){
            lastItem = item;
        }
        insert.bindString(1, item.getId());
        insert.bindString(2, item.getFurnishing());
        insert.bindString(3, item.getArea());
        insert.bindString(4, item.getPrice());
        insert.bindString(5, item.getNumberofbeds());
        insert.bindString(6, item.getImageUrl());

        insert.execute();
    }



    db.endTransaction();



    return true;
}

In Main Acvitiy: 在主要职责中:

boolean add = new TableControllerTenant_pg(getApplicationContext()).create(listPG);

You are calling beginTransaction() . 您正在调用beginTransaction() Its documentation says: 它的文档说:

The changes will be rolled back if any transaction is ended without being marked as clean (by calling setTransactionSuccessful ). 如果任何事务未标记为干净而结束(通过调用setTransactionSuccessful ),则更改将回滚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM