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

14 files changed

+47
-72
lines changed

Diff for: CHANGELOG.md

+6
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

Diff for: Documentation/Index.md

+6-6
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

Diff for: README.md

+2-2
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

Diff for: SQLite.swift.podspec

+1-1
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

Diff for: Sources/SQLite/Core/Blob.swift

+11-39
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
}

Diff for: Sources/SQLite/Core/Connection.swift

+1-1
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:

Diff for: Sources/SQLite/Core/Statement.swift

+2-2
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:

Diff for: Sources/SQLite/Extensions/Cipher.swift

+3-3
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.

Diff for: Sources/SQLite/Foundation.swift

+4-2
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
}

Diff for: Tests/SPM/Package.swift

+1-1
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(

Diff for: Tests/SQLiteTests/Core/BlobTests.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class BlobTests: XCTestCase {
2525

2626
func test_init_array() {
2727
let blob = Blob(bytes: [42, 43, 44])
28-
XCTAssertEqual([UInt8](blob.data), [42, 43, 44])
28+
XCTAssertEqual(blob.bytes, [42, 43, 44])
2929
}
3030

3131
func test_init_unsafeRawPointer() {
3232
let pointer = UnsafeMutablePointer<UInt8>.allocate(capacity: 3)
3333
pointer.initialize(repeating: 42, count: 3)
3434
let blob = Blob(bytes: pointer, length: 3)
35-
XCTAssertEqual([UInt8](blob.data), [42, 42, 42])
35+
XCTAssertEqual(blob.bytes, [42, 42, 42])
3636
}
3737

3838
func test_equality() {
@@ -44,8 +44,4 @@ class BlobTests: XCTestCase {
4444
XCTAssertEqual(blob1, blob2)
4545
XCTAssertNotEqual(blob1, blob3)
4646
}
47-
48-
func XXX_test_init_with_mutable_data_fails() {
49-
_ = Blob(data: NSMutableData())
50-
}
5147
}

Diff for: Tests/SQLiteTests/Core/StatementTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class StatementTests: SQLiteTestCase {
2222
let statement = try db.prepare("SELECT email FROM users")
2323
XCTAssert(try statement.step())
2424
let blob = statement.row[0] as Blob
25-
XCTAssertEqual("[email protected]", String(data: blob.data as Data, encoding: .utf8)!)
25+
XCTAssertEqual("[email protected]", String(bytes: blob.bytes, encoding: .utf8)!)
2626
}
2727

2828
func test_zero_sized_blob_returns_null() throws {
@@ -31,7 +31,7 @@ class StatementTests: SQLiteTestCase {
3131
try db.run(blobs.create { $0.column(blobColumn) })
3232
try db.run(blobs.insert(blobColumn <- Blob(bytes: [])))
3333
let blobValue = try db.scalar(blobs.select(blobColumn).limit(1, offset: 0))
34-
XCTAssertEqual([], [UInt8](blobValue.data))
34+
XCTAssertEqual([], blobValue.bytes)
3535
}
3636

3737
func test_prepareRowIterator() throws {

Diff for: Tests/SQLiteTests/Extensions/CipherTests.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CipherTests: XCTestCase {
1919

2020
// db2
2121
let key2 = keyData()
22-
try db2.key(Blob(data: key2))
22+
try db2.key(Blob(bytes: key2.bytes, length: key2.length))
2323

2424
try db2.run("CREATE TABLE foo (bar TEXT)")
2525
try db2.run("INSERT INTO foo (bar) VALUES ('world')")
@@ -47,7 +47,7 @@ class CipherTests: XCTestCase {
4747

4848
func test_data_rekey() throws {
4949
let newKey = keyData()
50-
try db2.rekey(Blob(data: newKey))
50+
try db2.rekey(Blob(bytes: newKey.bytes, length: newKey.length))
5151
XCTAssertEqual(1, try db2.scalar("SELECT count(*) FROM foo") as? Int64)
5252
}
5353

@@ -79,12 +79,11 @@ class CipherTests: XCTestCase {
7979
// sqlite> CREATE TABLE foo (bar TEXT);
8080
// sqlite> INSERT INTO foo (bar) VALUES ('world');
8181
guard let cipherVersion: String = db1.cipherVersion,
82-
cipherVersion.starts(with: "3.") || cipherVersion.starts(with: "4.")
83-
else { return }
82+
cipherVersion.starts(with: "3.") || cipherVersion.starts(with: "4.") else { return }
8483

8584
let encryptedFile = cipherVersion.starts(with: "3.") ?
86-
fixture("encrypted-3.x", withExtension: "sqlite") :
87-
fixture("encrypted-4.x", withExtension: "sqlite")
85+
fixture("encrypted-3.x", withExtension: "sqlite") :
86+
fixture("encrypted-4.x", withExtension: "sqlite")
8887

8988
try FileManager.default.setAttributes([FileAttributeKey.immutable: 1], ofItemAtPath: encryptedFile)
9089
XCTAssertFalse(FileManager.default.isWritableFile(atPath: encryptedFile))

Diff for: Tests/SQLiteTests/FoundationTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class FoundationTests: XCTestCase {
55
func testDataFromBlob() {
66
let data = Data([1, 2, 3])
77
let blob = data.datatypeValue
8-
XCTAssertEqual([1, 2, 3], [UInt8](blob.data))
8+
XCTAssertEqual([1, 2, 3], blob.bytes)
99
}
1010

1111
func testBlobToData() {

0 commit comments

Comments
 (0)