come modificare questa logica per lavorare con più di 170 righe.SQLite Android si è bloccato dopo 170 righe
// Getting All test
public List<Test> getAllTests(String str) {
List<Test> testList = new ArrayList<Test>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_TESTS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
//select rows by input string
if(cursor.getString(1).equals(str)){
Test test = new Test();
test.setId(Integer.parseInt(cursor.getString(0)));
test.setTest(cursor.getString(1));
test .setResult(Integer.parseInt(cursor.getString(2)));
// Adding test to list
testList.add(test);
}
} while (cursor.moveToNext());
}
//close database
db.close();
//return list data
return testList;
}
Desidero selezionare tutte le righe per stringa di input. E 'il lavoro logica perfettamente con 150 righe, ma dopo 160 lavoro lento e crash su 170 righe
Perché non hai usato una clausola WHERE nella tua richiesta? –
Provo con Cursore cursor = db.rawQuery ("SELECT * FROM" + TABLE_TESTS + "WHERE name =" + str, null); ma si è schiantato –
Qual è l'incidente che stai vedendo? Dalla descrizione "dopo 160 lavori lentamente e crash su 170 righe" indicherebbe che l'applicazione non risponde e in quel caso il problema è probabilmente altrove, o solo che stai chiamando il codice del database sul thread dell'interfaccia utente. – laalto