mirror of
				https://github.com/SimpleMobileTools/Simple-Calendar.git
				synced 2025-06-05 21:59:17 +02:00 
			
		
		
		
	make sure we close the cursor after db operations
This commit is contained in:
		| @@ -188,11 +188,16 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V | ||||
|  | ||||
|     private fun getEvents(selection: String): List<Event> { | ||||
|         val events = ArrayList<Event>() | ||||
|         val cursor = getEventsCursor(selection, null) | ||||
|         var cursor: Cursor? = null | ||||
|         try { | ||||
|             cursor = getEventsCursor(selection, null) | ||||
|             if (cursor != null) { | ||||
|                 val currEvents = fillEvents(cursor) | ||||
|                 events.addAll(currEvents) | ||||
|             } | ||||
|         } finally { | ||||
|             cursor?.close() | ||||
|         } | ||||
|  | ||||
|         return events | ||||
|     } | ||||
| @@ -208,7 +213,7 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V | ||||
|         val builder = SQLiteQueryBuilder() | ||||
|         builder.tables = "$MAIN_TABLE_NAME LEFT OUTER JOIN $META_TABLE_NAME ON $COL_EVENT_ID = $MAIN_TABLE_NAME.$COL_ID" | ||||
|         val projection = allColumns | ||||
|         return builder.query(mDb, projection, selection, selectionArgs, "$MAIN_TABLE_NAME.COL_ID", null, COL_START_TS) | ||||
|         return builder.query(mDb, projection, selection, selectionArgs, "$MAIN_TABLE_NAME.$COL_ID", null, COL_START_TS) | ||||
|     } | ||||
|  | ||||
|     private val allColumns: Array<String> | ||||
| @@ -216,10 +221,8 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V | ||||
|  | ||||
|     private fun fillEvents(cursor: Cursor?): List<Event> { | ||||
|         val events = ArrayList<Event>() | ||||
|         if (cursor == null) | ||||
|             return events | ||||
|  | ||||
|         if (cursor.moveToFirst()) { | ||||
|         try { | ||||
|             if (cursor != null && cursor.moveToFirst()) { | ||||
|                 do { | ||||
|                     val id = cursor.getIntValue(COL_ID) | ||||
|                     val startTS = cursor.getIntValue(COL_START_TS) | ||||
| @@ -231,7 +234,9 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V | ||||
|                     events.add(Event(id, startTS, endTS, title, description, reminderMinutes, repeatInterval)) | ||||
|                 } while (cursor.moveToNext()) | ||||
|             } | ||||
|         cursor.close() | ||||
|         } finally { | ||||
|             cursor?.close() | ||||
|         } | ||||
|         return events | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user