Skip to content

Commit a3036fe

Browse files
committed
Merge branch 'development' into sqlcipher-spm-upstream
2 parents 14d4c84 + 81a699c commit a3036fe

22 files changed

Lines changed: 152 additions & 21 deletions

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"editor.formatOnSave": false,
3+
"editor.insertSpaces": true,
4+
"editor.tabSize": 4,
5+
"editor.detectIndentation": false,
6+
"editor.trimAutoWhitespace": false
7+
}

GRDB/Core/DispatchQueueActor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#if os(Linux)
2+
@preconcurrency import Dispatch
3+
#else
14
import Dispatch
5+
#endif
26

37
/// An actor that runs in a DispatchQueue.
48
///

GRDB/Core/Support/CoreGraphics/CGFloat.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#if canImport(CoreGraphics)
22
import CoreGraphics
3+
#elseif !canImport(Darwin)
4+
import Foundation
5+
#endif
36

47
/// CGFloat adopts DatabaseValueConvertible
58
extension CGFloat: DatabaseValueConvertible {
@@ -15,4 +18,3 @@ extension CGFloat: DatabaseValueConvertible {
1518
return CGFloat(double)
1619
}
1720
}
18-
#endif

GRDB/Core/Support/Foundation/Date.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import GRDBSQLite
1212

1313
import Foundation
1414

15-
#if !os(Linux)
1615
/// NSDate is stored in the database using the format
1716
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
1817
extension NSDate: DatabaseValueConvertible {
@@ -41,7 +40,6 @@ extension NSDate: DatabaseValueConvertible {
4140
return cast(date)
4241
}
4342
}
44-
#endif
4543

4644
/// Date is stored in the database using the format
4745
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.

GRDB/Core/Support/Foundation/Decimal.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if !os(Linux)
21
// Import C SQLite functions
32
#if GRDBCIPHER // CocoaPods (SQLCipher subspec)
43
import SQLCipher
@@ -68,4 +67,3 @@ extension Decimal: StatementColumnConvertible {
6867

6968
@usableFromInline
7069
let _posixLocale = Locale(identifier: "en_US_POSIX")
71-
#endif

GRDB/Core/Support/Foundation/NSData.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if !os(Linux)
21
import Foundation
32

43
/// NSData is convertible to and from DatabaseValue.
@@ -24,4 +23,3 @@ extension NSData: DatabaseValueConvertible {
2423
return cast(data)
2524
}
2625
}
27-
#endif

GRDB/Core/Support/Foundation/NSNumber.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !os(Linux) && !os(Windows)
1+
#if !os(Windows)
22
import Foundation
33

44
private let integerRoundingBehavior = NSDecimalNumberHandler(
@@ -81,10 +81,18 @@ extension NSNumber: DatabaseValueConvertible {
8181
/// Otherwise, returns nil.
8282
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
8383
switch dbValue.storage {
84+
case .int64(let int64) where self is NSDecimalNumber.Type:
85+
let number = NSDecimalNumber(value: int64)
86+
return number as? Self
8487
case .int64(let int64):
85-
return self.init(value: int64)
88+
let number = NSNumber(value: int64)
89+
return number as? Self
90+
case .double(let double) where self is NSDecimalNumber.Type:
91+
let number = NSDecimalNumber(value: double)
92+
return number as? Self
8693
case .double(let double):
87-
return self.init(value: double)
94+
let number = NSNumber(value: double)
95+
return number as? Self
8896
case let .string(string):
8997
// Must match Decimal.fromDatabaseValue(_:)
9098
guard let decimal = Decimal(string: string, locale: posixLocale) else { return nil }

GRDB/Core/Support/Foundation/NSString.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if !os(Linux)
21
import Foundation
32

43
/// NSString adopts DatabaseValueConvertible
@@ -24,4 +23,3 @@ extension NSString: DatabaseValueConvertible {
2423
return self.init(string: string)
2524
}
2625
}
27-
#endif

GRDB/Core/Support/Foundation/URL.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import Foundation
22

3-
#if !os(Linux) && !os(Windows)
3+
#if !os(Windows)
44
/// NSURL stores its absoluteString in the database.
55
extension NSURL: DatabaseValueConvertible {
66

77
/// Returns a TEXT database value containing the absolute URL.
88
public var databaseValue: DatabaseValue {
9-
absoluteString?.databaseValue ?? .null
9+
#if !canImport(Darwin)
10+
absoluteString.databaseValue
11+
#else
12+
absoluteString?.databaseValue ?? .null
13+
#endif
1014
}
1115

1216
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {

GRDB/Core/Support/Foundation/UUID.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import GRDBSQLite
1212

1313
import Foundation
1414

15-
#if !os(Linux) && !os(Windows)
15+
#if !os(Windows)
1616
/// NSUUID adopts DatabaseValueConvertible
1717
extension NSUUID: DatabaseValueConvertible {
1818
/// Returns a BLOB database value containing the uuid bytes.
@@ -36,10 +36,17 @@ extension NSUUID: DatabaseValueConvertible {
3636
switch dbValue.storage {
3737
case .blob(let data) where data.count == 16:
3838
return data.withUnsafeBytes {
39-
self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress)
39+
#if canImport(Darwin)
40+
self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress)
41+
#else
42+
guard let uuidBytes = $0.bindMemory(to: UInt8.self).baseAddress else {
43+
return nil as Self?
44+
}
45+
return NSUUID(uuidBytes: uuidBytes) as? Self
46+
#endif
4047
}
4148
case .string(let string):
42-
return self.init(uuidString: string)
49+
return NSUUID(uuidString: string) as? Self
4350
default:
4451
return nil
4552
}
@@ -91,8 +98,8 @@ extension UUID: StatementColumnConvertible {
9198
self.init(uuid: uuid.uuid)
9299
case SQLITE_BLOB:
93100
guard sqlite3_column_bytes(sqliteStatement, index) == 16,
94-
let blob = sqlite3_column_blob(sqliteStatement, index) else
95-
{
101+
let blob = sqlite3_column_blob(sqliteStatement, index)
102+
else {
96103
return nil
97104
}
98105
self.init(uuid: blob.assumingMemoryBound(to: uuid_t.self).pointee)

0 commit comments

Comments
 (0)