M
M
MadeChaos2017-02-15 22:48:45
Android
MadeChaos, 2017-02-15 22:48:45

Why are insets overwritten?

Hello, I ran into a problem. Google did not help, when writing a certain collection in SQLite, the records in the database are overwritten. When calling getItemCount() it shows 1 item.
PS I shove 3 elements I
write a collection of objects:

public void pushData(SQLiteDatabase db){
        List<User> users = Main.createList(); // Тестовая коллекция
        for (int i = 0; i < users.size(); i++) {
            ContentValues value = new ContentValues();
            value.put(KEY_NAME, users.get(i).getName());
            value.put(KEY_GENDER, users.get(i).getGender());
            value.put(KEY_CITY, users.get(i).getCity());
            value.put(KEY_LATITUDE, users.get(i).getLocation().latitude);
            value.put(KEY_LONGITUDE, users.get(i).getLocation().longitude);
            db.insert(TABLE_NAME, null, value);
        }
    }

I get count:
public int getItemCount(){
        db = dbHelper.getReadableDatabase();
        cursor = db.query(DBHelper.TABLE_NAME,null,null,null,null,null,null);
        int cnt = cursor.getCount();
        cursor.close();
        close();
        return cnt;
    }

Checking:
Toast.makeText(getApplication(),"Количество записе в базе: " + db.getItemCount(), Toast.LENGTH_LONG).show();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MadeChaos, 2017-02-16
@MadeChaos

Sorry for your concern, the issue has been resolved, the request to create a table was written incorrectly, so some of the cells were not created, therefore the request to add did not pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question