File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 22========================================
33
44* Fixed SQLCipher integration with read-only databases ([ #559 ] [ ] )
5+ * Fixed null pointer when fetching an empty BLOB ([ #561 ] [ ] )
56
670.11.1 (06-12-2016), [ diff] [ diff-0.11.1 ]
78========================================
2526[ #546 ] : https://github.com/stephencelis/SQLite.swift/issues/546
2627[ #553 ] : https://github.com/stephencelis/SQLite.swift/pull/553
2728[ #559 ] : https://github.com/stephencelis/SQLite.swift/pull/559
29+ [ #561 ] : https://github.com/stephencelis/SQLite.swift/issues/561
Original file line number Diff line number Diff line change @@ -244,7 +244,9 @@ public struct Cursor {
244244 let length = Int ( sqlite3_column_bytes ( handle, Int32 ( idx) ) )
245245 return Blob ( bytes: pointer, length: length)
246246 } else {
247- fatalError ( " sqlite3_column_blob returned NULL " )
247+ // The return value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
248+ // https://www.sqlite.org/c3ref/column_blob.html
249+ return Blob ( bytes: [ ] )
248250 }
249251 }
250252
Original file line number Diff line number Diff line change @@ -14,4 +14,13 @@ class StatementTests : SQLiteTestCase {
1414 let blob = statement. row [ 0 ] as Blob
1515 XCTAssertEqual ( " [email protected] " , String ( bytes
: blob
. bytes
, encoding
: . utf8
) !
) 1616 }
17+
18+ func test_zero_sized_blob_returns_null( ) {
19+ let blobs = Table ( " blobs " )
20+ let blobColumn = Expression < Blob > ( " blob_column " )
21+ try ! db. run ( blobs. create { $0. column ( blobColumn) } )
22+ try ! db. run ( blobs. insert ( blobColumn <- Blob ( bytes: [ ] ) ) )
23+ let blobValue = try ! db. scalar ( blobs. select ( blobColumn) . limit ( 1 , offset: 0 ) )
24+ XCTAssertEqual ( [ ] , blobValue. bytes)
25+ }
1726}
You can’t perform that action at this time.
0 commit comments