From 036e236dc01d97e0167c90bd6960c249cab5beed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 28 Jun 2019 19:01:58 +0200 Subject: [PATCH 1/4] Failing test for #561 --- .../DatabasePoolCollationTests.swift | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/Tests/GRDBTests/DatabasePoolCollationTests.swift b/Tests/GRDBTests/DatabasePoolCollationTests.swift index 5a53822b5..ce0551253 100644 --- a/Tests/GRDBTests/DatabasePoolCollationTests.swift +++ b/Tests/GRDBTests/DatabasePoolCollationTests.swift @@ -15,24 +15,50 @@ class DatabasePoolCollationTests: GRDBTestCase { } dbPool.add(collation: collation1) - try dbPool.write { db in - try db.execute(sql: "CREATE TABLE items (text TEXT COLLATE collation1)") - try db.execute(sql: "INSERT INTO items (text) VALUES ('a')") - try db.execute(sql: "INSERT INTO items (text) VALUES ('b')") - try db.execute(sql: "INSERT INTO items (text) VALUES ('c')") - } - try dbPool.read { db in - XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text"), ["a", "b", "c"]) - XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"]) - } - let collation2 = DatabaseCollation("collation2") { (string1, string2) in return (string1 == string2) ? .orderedSame : ((string1 < string2) ? .orderedDescending : .orderedAscending) } dbPool.add(collation: collation2) + try dbPool.write { db in + // Both collations are available in writer + try db.execute(sql: """ + CREATE TABLE items (text TEXT COLLATE collation2); + INSERT INTO items (text) VALUES ('a'); + INSERT INTO items (text) VALUES ('b'); + INSERT INTO items (text) VALUES ('c'); + """) + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text"), ["c", "b", "a"]) + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"]) + } + try dbPool.read { db in + // Both collations are available in reader + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text"), ["c", "b", "a"]) + XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1"), ["a", "b", "c"]) XCTAssertEqual(try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation2"), ["c", "b", "a"]) } + + dbPool.remove(collation: collation1) + + do { + // collation1 is no longer available in writer + try dbPool.write { db in + _ = try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1") + } + } catch let error as DatabaseError { + XCTAssertEqual(error.resultCode, .SQLITE_ERROR) + XCTAssert(error.message!.contains("collation1")) + } + + do { + // collation1 is no longer available in reader + try dbPool.read { db in + _ = try String.fetchAll(db, sql: "SELECT text FROM items ORDER BY text COLLATE collation1") + } + } catch let error as DatabaseError { + XCTAssertEqual(error.resultCode, .SQLITE_ERROR) + XCTAssert(error.message!.contains("collation1")) + } } } From 7802eb356d8c3607eda3106c34f3240663cfc860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 28 Jun 2019 19:02:21 +0200 Subject: [PATCH 2/4] Fix failing test for #561 --- GRDB/Core/DatabaseCollation.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRDB/Core/DatabaseCollation.swift b/GRDB/Core/DatabaseCollation.swift index 530992caa..d94780412 100644 --- a/GRDB/Core/DatabaseCollation.swift +++ b/GRDB/Core/DatabaseCollation.swift @@ -50,6 +50,6 @@ extension DatabaseCollation: Hashable { /// :nodoc: public static func == (lhs: DatabaseCollation, rhs: DatabaseCollation) -> Bool { // See https://www.sqlite.org/c3ref/create_collation.html - return sqlite3_stricmp(lhs.name, lhs.name) == 0 + return sqlite3_stricmp(lhs.name, rhs.name) == 0 } } From fbc50dd2d18915986135045189e41e8c6ec97e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 28 Jun 2019 19:06:11 +0200 Subject: [PATCH 3/4] CHANGELOG --- CHANGELOG.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05df3dc0e..bc267f775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,9 @@ All notable changes to this project will be documented in this file. GRDB adheres to [Semantic Versioning](https://semver.org/), with one expection: APIs flagged [**:fire: EXPERIMENTAL**](README.md#what-are-experimental-features). Those are unstable, and may break between any two minor releases of the library. - + #### 4.x Releases @@ -51,9 +51,11 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one expection: - [0.110.0](#01100), ... - + +- [#562](https://github.com/groue/GRDB.swift/pull/537): Fix crash when using more than one DatabaseCollation + ## 4.1.1 From 498c65a64c9af1ae77c54be5d4a7fcd2b896d742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 28 Jun 2019 19:06:49 +0200 Subject: [PATCH 4/4] CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc267f775..6e6b4e37d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one expection: ## Next Release -- [#562](https://github.com/groue/GRDB.swift/pull/537): Fix crash when using more than one DatabaseCollation +- [#562](https://github.com/groue/GRDB.swift/pull/562): Fix crash when using more than one DatabaseCollation ## 4.1.1