From 040e5d9d87132ac9b3b34b36628aed3fe505c878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 28 Aug 2022 12:09:47 +0200 Subject: [PATCH] WITHOUT ROWID check: prefer PRAGMA table_list when available This avoids the undesired errors described in #945. --- GRDB/Core/Database+Schema.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/GRDB/Core/Database+Schema.swift b/GRDB/Core/Database+Schema.swift index 7fbb8e90e..c69f28ad7 100644 --- a/GRDB/Core/Database+Schema.swift +++ b/GRDB/Core/Database+Schema.swift @@ -366,7 +366,19 @@ extension Database { private func tableHasRowID(_ table: TableIdentifier) throws -> Bool { // No need to cache the result, because this information feeds // `PrimaryKeyInfo`, which is cached. - // + + // Prefer PRAGMA table_list if available +#if GRDBCUSTOMSQLITE || GRDBCIPHER + // Maybe SQLCipher is too old: check actual version + if sqlite3_libversion_number() >= 3037000 { + return try self.table(for: table)!.hasRowID + } +#else + if #available(iOS 15.4, macOS 12.4, tvOS 15.4, watchOS 8.5, *) { + return try self.table(for: table)!.hasRowID + } +#endif + // To check if the table has a rowid, we compile a statement that // selects the `rowid` column. If compilation fails, we assume that the // table is WITHOUT ROWID. This is not a very robust test (users may