how to change this logic to work with more than 170 rows.
// 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;
}
I want to select all rows by input string. It logic work perfectly with 150 rows but after 160 work slowly and crash on 170 rows
how to change this logic to work with more than 170 rows?
// Getting All test
public List<Test> getAllTests(String str) {
List<Test> testList = new ArrayList<Test>();
// Select All Query
//String selectQuery = "SELECT * FROM " + TABLE_TESTS;
String selectQuery = "SELECT id,result FROM " + TABLE_TESTS + " where name ='" + str + "'";
// Now you are saving memory of one column.
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
Test test = new Test();
// moved outside loop to prevent creating new object every time.
do {
//select rows by input string
//if(cursor.getString(1).equals(str)){
// No need for if Codition any more
test.setId(Integer.parseInt(cursor.getString(0)));
//test.setTest(cursor.getString(1));
test.setTest(str);
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With