From a44a666a41978727fdfefde806dc6f75fd534192 Mon Sep 17 00:00:00 2001 From: Di Wu Date: Fri, 6 Sep 2024 13:45:14 -0700 Subject: [PATCH] fix(analytics): iterate sqlite rows with failableNext --- .../LocalStorage/AnalyticsEventSQLStorage.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift index c0597a6e98..8708109045 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/AnalyticsEventSQLStorage.swift @@ -142,12 +142,16 @@ class AnalyticsEventSQLStorage: AnalyticsEventStorage { ORDER BY timestamp ASC LIMIT ? """ - let rows = try dbAdapter.executeQuery(queryStatement, [limit]) + let rows = try dbAdapter.executeQuery(queryStatement, [limit]).makeIterator() var result = [PinpointEvent]() - for element in rows { - if let event = PinpointEvent.convertToEvent(element) { - result.append(event) + do { + while let element = try rows.failableNext() { + if let event = PinpointEvent.convertToEvent(element) { + result.append(event) + } } + } catch { + Self.log.debug("Failed to iterate event rows from SQLite, error: \(error)") } return result }