Skip to content

Commit 7a2e3cd

Browse files
authored
Merge pull request #1170 from stephencelis/revert-blob-changes
Revert blob changes
2 parents 3161f06 + 1235d44 commit 7a2e3cd

File tree

14 files changed

+47
-72
lines changed

14 files changed

+47
-72
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.14.1 (01-11-2022), [diff][diff-0.14.1]
2+
========================================
3+
4+
* Reverted `Blob` changes (See [#1167][] for rationale).
5+
16
0.14.0 (27-10-2022), [diff][diff-0.14.0]
27
========================================
38
For breaking changes, see [Upgrading.md](Documentation/Upgrading.md).
@@ -129,6 +134,7 @@ For breaking changes, see [Upgrading.md](Documentation/Upgrading.md).
129134
[diff-0.13.2]: https://github.com/stephencelis/SQLite.swift/compare/0.13.1...0.13.2
130135
[diff-0.13.3]: https://github.com/stephencelis/SQLite.swift/compare/0.13.2...0.13.3
131136
[diff-0.14.0]: https://github.com/stephencelis/SQLite.swift/compare/0.13.3...0.14.0
137+
[diff-0.14.1]: https://github.com/stephencelis/SQLite.swift/compare/0.14.0...0.14.1
132138

133139
[#30]: https://github.com/stephencelis/SQLite.swift/issues/30
134140
[#142]: https://github.com/stephencelis/SQLite.swift/issues/142

Documentation/Index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ process of downloading, compiling, and linking dependencies.
9090

9191
```swift
9292
dependencies: [
93-
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.0")
93+
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.1")
9494
]
9595
```
9696

@@ -111,7 +111,7 @@ install SQLite.swift with Carthage:
111111
2. Update your Cartfile to include the following:
112112

113113
```ruby
114-
github "stephencelis/SQLite.swift" ~> 0.14.0
114+
github "stephencelis/SQLite.swift" ~> 0.14.1
115115
```
116116

117117
3. Run `carthage update` and [add the appropriate framework][Carthage Usage].
@@ -141,7 +141,7 @@ install SQLite.swift with Carthage:
141141
use_frameworks!
142142
143143
target 'YourAppTargetName' do
144-
pod 'SQLite.swift', '~> 0.14.0'
144+
pod 'SQLite.swift', '~> 0.14.1'
145145
end
146146
```
147147

@@ -155,7 +155,7 @@ with the OS you can require the `standalone` subspec:
155155

156156
```ruby
157157
target 'YourAppTargetName' do
158-
pod 'SQLite.swift/standalone', '~> 0.14.0'
158+
pod 'SQLite.swift/standalone', '~> 0.14.1'
159159
end
160160
```
161161

@@ -165,7 +165,7 @@ dependency to sqlite3 or one of its subspecs:
165165

166166
```ruby
167167
target 'YourAppTargetName' do
168-
pod 'SQLite.swift/standalone', '~> 0.14.0'
168+
pod 'SQLite.swift/standalone', '~> 0.14.1'
169169
pod 'sqlite3/fts5', '= 3.15.0' # SQLite 3.15.0 with FTS5 enabled
170170
end
171171
```
@@ -181,7 +181,7 @@ If you want to use [SQLCipher][] with SQLite.swift you can require the
181181
target 'YourAppTargetName' do
182182
# Make sure you only require the subspec, otherwise you app might link against
183183
# the system SQLite, which means the SQLCipher-specific methods won't work.
184-
pod 'SQLite.swift/SQLCipher', '~> 0.14.0'
184+
pod 'SQLite.swift/SQLCipher', '~> 0.14.1'
185185
end
186186
```
187187

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Swift code.
131131

132132
```swift
133133
dependencies: [
134-
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.0")
134+
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.1")
135135
]
136136
```
137137

@@ -155,7 +155,7 @@ install SQLite.swift with Carthage:
155155
2. Update your Cartfile to include the following:
156156

157157
```ruby
158-
github "stephencelis/SQLite.swift" ~> 0.14.0
158+
github "stephencelis/SQLite.swift" ~> 0.14.1
159159
```
160160

161161
3. Run `carthage update` and

SQLite.swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "SQLite.swift"
3-
s.version = "0.14.0"
3+
s.version = "0.14.1"
44
s.summary = "A type-safe, Swift-language layer over SQLite3."
55

66
s.description = <<-DESC

Sources/SQLite/Core/Blob.swift

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,64 +21,36 @@
2121
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
// THE SOFTWARE.
2323
//
24-
import Foundation
2524

26-
public final class Blob {
25+
public struct Blob {
2726

28-
public let data: NSData
27+
public let bytes: [UInt8]
2928

30-
public var bytes: UnsafePointer<UInt8> {
31-
data.bytes.assumingMemoryBound(to: UInt8.self)
29+
public init(bytes: [UInt8]) {
30+
self.bytes = bytes
3231
}
3332

34-
public var length: Int {
35-
data.count
36-
}
37-
38-
public convenience init(bytes: [UInt8]) {
39-
guard bytes.count > 0 else {
40-
self.init(data: NSData())
41-
return
42-
}
43-
self.init(data: NSData(bytes: bytes, length: bytes.count))
44-
}
45-
46-
public convenience init(bytes: UnsafeRawPointer, length: Int) {
47-
self.init(data: NSData(bytes: bytes, length: length))
48-
}
49-
50-
public init(data: NSData) {
51-
precondition(!(data is NSMutableData), "Blob cannot be initialized with mutable data")
52-
self.data = data
33+
public init(bytes: UnsafeRawPointer, length: Int) {
34+
let i8bufptr = UnsafeBufferPointer(start: bytes.assumingMemoryBound(to: UInt8.self), count: length)
35+
self.init(bytes: [UInt8](i8bufptr))
5336
}
5437

5538
public func toHex() -> String {
56-
guard length > 0 else { return "" }
57-
58-
var hex = ""
59-
for idx in 0..<length {
60-
let byte = bytes.advanced(by: idx).pointee
61-
if byte < 16 {
62-
hex += "0"
63-
}
64-
hex += String(byte, radix: 16, uppercase: false)
65-
}
66-
return hex
39+
bytes.map {
40+
($0 < 16 ? "0" : "") + String($0, radix: 16, uppercase: false)
41+
}.joined(separator: "")
6742
}
6843
}
6944

7045
extension Blob: CustomStringConvertible {
71-
7246
public var description: String {
7347
"x'\(toHex())'"
7448
}
75-
7649
}
7750

7851
extension Blob: Equatable {
79-
8052
}
8153

8254
public func ==(lhs: Blob, rhs: Blob) -> Bool {
83-
lhs.data == rhs.data
55+
lhs.bytes == rhs.bytes
8456
}

Sources/SQLite/Core/Connection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ extension Context {
741741
func set(result: Binding?) {
742742
switch result {
743743
case let blob as Blob:
744-
sqlite3_result_blob(self, blob.bytes, Int32(blob.length), nil)
744+
sqlite3_result_blob(self, blob.bytes, Int32(blob.bytes.count), nil)
745745
case let double as Double:
746746
sqlite3_result_double(self, double)
747747
case let int as Int64:

Sources/SQLite/Core/Statement.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ public final class Statement {
103103
switch value {
104104
case .none:
105105
sqlite3_bind_null(handle, Int32(idx))
106-
case let value as Blob where value.length == 0:
106+
case let value as Blob where value.bytes.count == 0:
107107
sqlite3_bind_zeroblob(handle, Int32(idx), 0)
108108
case let value as Blob:
109-
sqlite3_bind_blob(handle, Int32(idx), value.bytes, Int32(value.length), SQLITE_TRANSIENT)
109+
sqlite3_bind_blob(handle, Int32(idx), value.bytes, Int32(value.bytes.count), SQLITE_TRANSIENT)
110110
case let value as Double:
111111
sqlite3_bind_double(handle, Int32(idx), value)
112112
case let value as Int64:

Sources/SQLite/Extensions/Cipher.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension Connection {
3232
}
3333

3434
public func key(_ key: Blob, db: String = "main") throws {
35-
try _key_v2(db: db, keyPointer: key.bytes, keySize: key.length)
35+
try _key_v2(db: db, keyPointer: key.bytes, keySize: key.bytes.count)
3636
}
3737

3838
/// Same as `key(_ key: String, db: String = "main")`, running "PRAGMA cipher_migrate;"
@@ -53,7 +53,7 @@ extension Connection {
5353

5454
/// Same as `[`keyAndMigrate(_ key: String, db: String = "main")` accepting byte array as key
5555
public func keyAndMigrate(_ key: Blob, db: String = "main") throws {
56-
try _key_v2(db: db, keyPointer: key.bytes, keySize: key.length, migrate: true)
56+
try _key_v2(db: db, keyPointer: key.bytes, keySize: key.bytes.count, migrate: true)
5757
}
5858

5959
/// Change the key on an open database. NB: only works if the database is already encrypted.
@@ -68,7 +68,7 @@ extension Connection {
6868
}
6969

7070
public func rekey(_ key: Blob, db: String = "main") throws {
71-
try _rekey_v2(db: db, keyPointer: key.bytes, keySize: key.length)
71+
try _rekey_v2(db: db, keyPointer: key.bytes, keySize: key.bytes.count)
7272
}
7373

7474
/// Converts a non-encrypted database to an encrypted one.

Sources/SQLite/Foundation.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ extension Data: Value {
3131
}
3232

3333
public static func fromDatatypeValue(_ dataValue: Blob) -> Data {
34-
dataValue.data as Data
34+
Data(dataValue.bytes)
3535
}
3636

3737
public var datatypeValue: Blob {
38-
Blob(data: self as NSData)
38+
withUnsafeBytes { (pointer: UnsafeRawBufferPointer) -> Blob in
39+
Blob(bytes: pointer.baseAddress!, length: count)
40+
}
3941
}
4042

4143
}

Tests/SPM/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let package = Package(
1515
// for testing from same repository
1616
.package(path: "../..")
1717
// normally this would be:
18-
// .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.0")
18+
// .package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.14.1")
1919
],
2020
targets: [
2121
.target(

0 commit comments

Comments
 (0)