@@ -355,7 +355,8 @@ public Cursor executeSelectQuery(String query)
355355 try
356356 {
357357 // query execution
358- Cursor cursor = db .getReadableDatabase ().rawQuery (query , null );
358+ Cursor cursor = db .getWritableDatabase ().rawQuery (query , null );
359+ db .close ();
359360
360361 // if cursor is not null then moving the position to first
361362 // and returning the cursor
@@ -450,7 +451,8 @@ public Cursor executeSelectQuery(String tableName, String values,
450451 }
451452
452453 // executing query
453- cursor = db .getReadableDatabase ().rawQuery (query , null );
454+ cursor = db .getWritableDatabase ().rawQuery (query , null );
455+ db .close ();
454456
455457 // if cursor is not null then moving the position to first
456458 // and returning the cursor
@@ -553,7 +555,8 @@ public <T> ArrayList<T> executeSelectQuery(String tableName, String values,
553555 }
554556
555557 // executing query
556- cursor = db .getReadableDatabase ().rawQuery (query , null );
558+ cursor = db .getWritableDatabase ().rawQuery (query , null );
559+ db .close ();
557560
558561 // if cursor is not null then moving the position to first
559562 // and returning the cursor
@@ -767,7 +770,8 @@ public boolean isTableExists(String tableName)
767770 String query = "SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name = '" + tableName + "'" ;
768771
769772 // executing the query using cursor
770- Cursor cursor = db .getReadableDatabase ().rawQuery (query , null );
773+ Cursor cursor = db .getWritableDatabase ().rawQuery (query , null );
774+ db .close ();
771775
772776 // checking if cursor is not null
773777 if (cursor != null )
@@ -826,7 +830,8 @@ public int getMaxId(String field, String tableName)
826830 }
827831
828832 String query = "SELECT MAX(" + field + ") AS ID FROM " + tableName ;
829- Cursor cursor = db .getReadableDatabase ().rawQuery (query , null );
833+ Cursor cursor = db .getWritableDatabase ().rawQuery (query , null );
834+ db .close ();
830835
831836 if (cursor != null )
832837 {
@@ -1957,7 +1962,8 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
19571962 Log .e (TAG , "getAllRecords: Select query for getting all records is: " + query );
19581963
19591964 // executing generated select query
1960- cursor = db .getReadableDatabase ().rawQuery (query , null );
1965+ cursor = db .getWritableDatabase ().rawQuery (query , null );
1966+ db .close ();
19611967
19621968 // checking if cursor is not null and cursor has moved to first position
19631969 if (cursor != null && cursor .moveToFirst ())
@@ -2140,7 +2146,8 @@ public <T> ArrayList<T> getAllRecords(String tableName, boolean isAscending,
21402146 Log .e (TAG , "getAllRecords: Select query for getting all records is: " + query );
21412147
21422148 // executing generated select query
2143- cursor = db .getReadableDatabase ().rawQuery (query , null );
2149+ cursor = db .getWritableDatabase ().rawQuery (query , null );
2150+ db .close ();
21442151
21452152 // checking if cursor is not null and cursor has moved to first position
21462153 if (cursor != null && cursor .moveToFirst ())
0 commit comments