@@ -63,9 +63,9 @@ private struct SeededGenerator: RandomNumberGenerator {
6363/// Whether this SQLite build includes the R*Tree module (an optional compile-time
6464/// feature), determined by attempting to create an R*Tree virtual table in memory.
6565private let isRTreeAvailable : Bool = {
66- guard let connection = try ? Connection ( . inMemory) else { return false }
66+ guard let connection = try ? Connection ( path : . inMemory) else { return false }
6767 do {
68- try connection. execute ( " CREATE VIRTUAL TABLE rtree_probe USING rtree(id, minX, maxX) " )
68+ try connection. run ( " CREATE VIRTUAL TABLE rtree_probe USING rtree(id, minX, maxX) " )
6969 return true
7070 } catch {
7171 return false
@@ -300,14 +300,18 @@ func appManagedRTreePrefilter() async throws {
300300 let maxLon = referenceLongitude + lonDelta
301301
302302 // Query the app's R*Tree (through the app's own read connection) for candidate ids.
303- let reader = try Connection ( path, readonly : true )
304- let candidates = Set ( try reader. prepare ( """
303+ let reader = try Connection ( path: path , isReadOnly : true )
304+ let statement = try reader. prepare ( """
305305 SELECT m.site_id FROM " Site_rtree " r
306306 JOIN " Site_rtree_map " m ON m.rowid = r.id
307307 WHERE r.minLat <= ? AND r.maxLat >= ? AND r.minLon <= ? AND r.maxLon >= ?
308- """ , maxLat, minLat, maxLon, minLon) . compactMap { row in
309- ( row [ 0 ] as? String ) . map { ObjectID ( rawValue: $0) }
310- } )
308+ """ , [ maxLat. binding, minLat. binding, maxLon. binding, minLon. binding] )
309+ var candidates = Set < ObjectID > ( )
310+ while let row = try statement. failableNext ( ) {
311+ if let site = row [ 0 ] ? . textValue {
312+ candidates. insert ( ObjectID ( rawValue: site) )
313+ }
314+ }
311315
312316 // Combine the R*Tree candidate set with the exact distance filter via the library.
313317 let request = FetchRequest (
0 commit comments