Skip to content

Commit

Permalink
Finalizing statement before completion with row error. Database lock …
Browse files Browse the repository at this point in the history
…test.
  • Loading branch information
DnV1eX committed May 5, 2021
1 parent cfaf55d commit af57ed7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/SQLiteCombine/SQLiteCombine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ extension SQLite.Publisher {
let input = try row()
demand += subscriber.receive(input)
} catch {
subscriber.receive(completion: .failure(error))
sqlite3_finalize(stmt)
subscriber.receive(completion: .failure(error))
self.stmt = nil
}
default:
Expand Down
20 changes: 19 additions & 1 deletion Tests/SQLiteCombineTests/SQLiteCombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class SQLiteCombineTests: XCTestCase {
let completionExpectation = expectation(description: "Drop Table completion")
let valueExpectation = expectation(description: "Drop Table value")
valueExpectation.isInverted = true
_ = db.publisher(sql: "DROP TABLE test")
_ = db.publisher(sql: "DROP TABLE IF EXISTS test")
.sink { completion in
if case let .failure(error) = completion { XCTFail(String(describing: error)) }
completionExpectation.fulfill()
Expand Down Expand Up @@ -286,6 +286,24 @@ final class SQLiteCombineTests: XCTestCase {

waitForExpectations(timeout: 0, handler: nil)
}


func testDatabaseLock() throws {

let completionExpectation = expectation(description: "Drop Table completion")
let valueExpectation = expectation(description: "Drop Table value")
valueExpectation.isInverted = true
_ = db.publisher(sql: "SELECT count(*) FROM test")
.catch { _ in self.db.publisher(sql: "DROP TABLE test") }
.sink { completion in
if case let .failure(error) = completion { XCTFail(String(describing: error)) }
completionExpectation.fulfill()
} receiveValue: {
valueExpectation.fulfill()
}

waitForExpectations(timeout: 0, handler: nil)
}
}


Expand Down

0 comments on commit af57ed7

Please sign in to comment.