Merge branch 'development'

This commit is contained in:
Gwendal Roué committed 2023-03-14 08:33:07 +01:00
commit be41d2dd03
8 files changed
+91 -32

No files matched your search

+9 -2
View File
@@ -7,7 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
#### 6.x Releases
- `6.9.x` Releases - [6.9.0](#690) - [6.9.1](#691)
- `6.9.x` Releases - [6.9.0](#690) - [6.9.1](#691) - [6.9.2](#692)
- `6.8.x` Releases - [6.8.0](#680)
- `6.7.x` Releases - [6.7.0](#670)
- `6.6.x` Releases - [6.6.0](#660) - [6.6.1](#661)
@@ -107,9 +107,16 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
---
## 6.9.2
Released March 14, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.9.1...v6.9.2)
- **Fixed**: [#1349](https://github.com/groue/GRDB.swift/pull/1349) by [@JonLz](https://github.com/JonLz): Fix Migrations.md example so it compiles
- **Fixed**: Avoid the risk for pathologically deep stack trace, or stack overflow, introduced by [#1348](https://github.com/groue/GRDB.swift/pull/1348).
## 6.9.1
Released March 12, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.8.0...v6.9.1)
Released March 12, 2023 • [diff](https://github.com/groue/GRDB.swift/compare/v6.9.0...v6.9.1)
- **Documentation Updates**: Moved more README chapters into DocC:
- [`RowAdapter`](https://swiftpackageindex.com/groue/grdb.swift/documentation/grdb/rowadapter)
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GRDB.swift'
s.version = '6.9.1'
s.version = '6.9.2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
+21 -9
View File
@@ -513,18 +513,19 @@ public final class Statement {
///
/// When arguments are set at the moment of execution, with an non-nil
/// `arguments` parameter, it is assumed that the statement won't be
/// reused with the same arguments. Execution is performed with
/// temporary SQLite bindings that avoid copying strings and blobs
/// arguments.
/// reused with the same arguments. When the number of arguments is
/// small, execution is performed with temporary SQLite bindings that
/// avoid copying strings and blobs arguments.
///
/// For more information, see [`SQLITE_STATIC` and `SQLITE_TRANSIENT`](https://www.sqlite.org/c3ref/c_static.html).
/// Compare:
///
/// ```swift
/// // Uses SQLITE_STATIC
/// // Uses SQLITE_STATIC if there are few arguments,
/// // SQLITE_TRANSIENT otherwise.
/// try statement.execute(arguments: ["Barbara"])
///
/// // Uses SQLITE_TRANSIENT
/// // Always uses SQLITE_TRANSIENT
/// try statement.setArguments(["Arthur"])
/// try statement.execute()
/// ```
@@ -537,10 +538,21 @@ public final class Statement {
/// - throws: A ``DatabaseError`` whenever an SQLite error occurs.
public func execute(arguments: StatementArguments? = nil) throws {
if let arguments {
// Assume that the statement won't be reused with the same
// arguments, and perform an optimized execution with temporary
// bindings in order to avoid copying strings and blobs.
try withArguments(arguments) {
// Assume that the statement won't be reused with the same arguments.
//
// Avoid a stack overflow, and don't perform an unbounded nesting
// of `withBinding(to:at:do:)` methods: only use temporary bindings
// for less than 20 arguments. This number 20 is completely
// arbitrary!
// See <https://forums.swift.org/t/avoiding-stack-overflow-when-nesting-string-withcstring-how-to-handle-an-arbitrary-number-of-temp-values-in-general/63663>
if sqliteArgumentCount <= 20 {
// Perform an optimized execution with temporary bindings
// in order to avoid copying strings and blobs.
try withArguments(arguments) {
try executeAllSteps()
}
} else {
try setArguments(arguments)
try executeAllSteps()
}
} else {
@@ -82,7 +82,7 @@ let player = try Player.fetchOne(selectStatement, arguments: ["Arthur"])
> Both perform exactly the same action, and most applications should not care about the difference. Yet:
>
> - ``setArguments(_:)`` performs a copy of string and blob arguments. It uses the low-level [`SQLITE_TRANSIENT`](https://www.sqlite.org/c3ref/c_static.html) option, and fits well the reuse of a given statement with the same arguments.
> - ``execute(arguments:)`` avoids a temporary allocation for string and blob arguments. It uses the low-level [`SQLITE_STATIC`](https://www.sqlite.org/c3ref/c_static.html) option, and fits well the reuse of a given statement with various arguments.
> - ``execute(arguments:)`` avoids a temporary allocation for string and blob arguments if the number of arguments is small. Instead of `SQLITE_TRANSIENT`, it uses the low-level [`SQLITE_STATIC`](https://www.sqlite.org/c3ref/c_static.html) option. This fits well the reuse of a given statement with various arguments.
>
> Don't make a blind choice, and monitor your app performance if it really matters!
+1 -1
View File
@@ -33,7 +33,7 @@ migrator.registerMigration("Add books and author.birthYear") { db in
t.column("title", .text).notNull()
}
try db.alter(table: "author") { t
try db.alter(table: "author") { t in
t.add(column: "birthYear", .integer)
}
}
+2 -2
View File
@@ -11,13 +11,13 @@
---
**Latest release**: March 12, 2023 • [version 6.9.1](https://github.com/groue/GRDB.swift/tree/v6.9.1) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md)
**Latest release**: March 14, 2023 • [version 6.9.2](https://github.com/groue/GRDB.swift/tree/v6.9.2) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md)
**Requirements**: iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 4.0+ &bull; SQLite 3.19.3+ &bull; Swift 5.7+ / Xcode 14+
| Swift version | GRDB version |
| -------------- | ----------------------------------------------------------- |
| **Swift 5.7+** | **v6.9.1** |
| **Swift 5.7+** | **v6.9.2** |
| Swift 5.3 | [v5.26.1](https://github.com/groue/GRDB.swift/tree/v5.26.1) |
| Swift 5.2 | [v5.12.0](https://github.com/groue/GRDB.swift/tree/v5.12.0) |
| Swift 5.1 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) |
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>6.9.1</string>
<string>6.9.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
+55 -15
View File
@@ -442,22 +442,23 @@ class UpdateStatementTests : GRDBTestCase {
}
}
// To be compared with testTemporaryBindings() and testNonTemporaryBindings()
func testArgumentsReuse() throws {
// MARK: - SQLITE_STATIC vs SQLITE_TRANSIENT
func test_SQLITE_STATIC_then_SQLITE_TRANSIENT() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.write { db in
try db.execute(literal: """
try db.execute(sql: """
CREATE TABLE t(a);
""")
func test(value: some DatabaseValueConvertible) throws {
defer { try! db.execute(sql: "DELETE FROM t") }
// Execute with temporary bindings
// Execute with temporary bindings (SQLITE_STATIC)
let statement = try db.makeStatement(sql: "INSERT INTO t VALUES (?)")
try statement.execute(arguments: [value])
// Execute with non temporary bindings
// Execute with non temporary bindings (SQLITE_TRANSIENT)
try statement.execute()
// Since bindings are not temporary, they are not cleared,
@@ -469,7 +470,7 @@ class UpdateStatementTests : GRDBTestCase {
// Test that we have inserted the value thrice.
try XCTAssertEqual(
DatabaseValue.fetchSet(db, sql: "SELECT a FROM t"),
[value.databaseValue, value.databaseValue, value.databaseValue])
[value.databaseValue])
}
try test(value: "Foo")
@@ -481,18 +482,17 @@ class UpdateStatementTests : GRDBTestCase {
}
}
// To be compared with testNonTemporaryBindings() and testArgumentsReuse()
func testTemporaryBindings() throws {
func test_SQLITE_STATIC() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.write { db in
try db.execute(literal: """
try db.execute(sql: """
CREATE TABLE t(a);
""")
func test(value: some DatabaseValueConvertible) throws {
defer { try! db.execute(sql: "DELETE FROM t") }
// Execute with temporary bindings
// Execute with temporary bindings (SQLITE_STATIC)
let statement = try db.makeStatement(sql: "INSERT INTO t VALUES (?)")
try statement.execute(arguments: [value])
@@ -516,18 +516,58 @@ class UpdateStatementTests : GRDBTestCase {
}
}
// To be compared with testTemporaryBindings() and testArgumentsReuse()
func testNonTemporaryBindings() throws {
func test_SQLITE_TRANSIENT_due_to_high_number_of_arguments() throws {
// SQLITE_STATIC optimization is disabled for more than 20 arguments.
let argumentCount = 21
let dbQueue = try makeDatabaseQueue()
try dbQueue.write { db in
try db.execute(literal: """
// "a0, a1, a2, ..."
let columns = (0..<argumentCount).map { "a\($0)" }.joined(separator: ",")
try db.execute(sql: """
CREATE TABLE t(\(columns));
""")
func test(value: some DatabaseValueConvertible) throws {
defer { try! db.execute(sql: "DELETE FROM t") }
// Execute with non temporary bindings (SQLITE_TRANSIENT),
// because there are more than 20 arguments
let statement = try db.makeStatement(sql: "INSERT INTO t VALUES (\(databaseQuestionMarks(count: argumentCount)))")
try statement.execute(arguments: StatementArguments(Array(repeating: value, count: argumentCount)))
// Since bindings are not temporary, they are not cleared,
// so insert the value again.
sqlite3_reset(statement.sqliteStatement)
sqlite3_step(statement.sqliteStatement)
sqlite3_reset(statement.sqliteStatement)
// Test that we have inserted the value twice.
try XCTAssertEqual(
DatabaseValue.fetchSet(db, sql: "SELECT a0 FROM t"),
[value.databaseValue])
}
try test(value: "Foo")
try test(value: "")
try test(value: "Hello".data(using: .utf8)!)
try test(value: Data())
try test(value: 42)
try test(value: 1.23)
}
}
func test_SQLITE_TRANSIENT() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.write { db in
try db.execute(sql: """
CREATE TABLE t(a);
""")
func test(value: some DatabaseValueConvertible) throws {
defer { try! db.execute(sql: "DELETE FROM t") }
// Execute with non temporary bindings
// Execute with non temporary bindings (SQLITE_TRANSIENT)
let statement = try db.makeStatement(sql: "INSERT INTO t VALUES (?)")
try statement.setArguments([value])
try statement.execute()
@@ -541,7 +581,7 @@ class UpdateStatementTests : GRDBTestCase {
// Test that we have inserted the value twice.
try XCTAssertEqual(
DatabaseValue.fetchSet(db, sql: "SELECT a FROM t"),
[value.databaseValue, value.databaseValue])
[value.databaseValue])
}
try test(value: "Foo")