Functions that fetch no longer throw (they crash), but the low-level Database.selectStatement(_:bindings:unsafe:).

This commit is contained in:
Gwendal Roué committed 2015-07-02 12:27:11 +02:00
1 parent 13817d864d
commit 343a239905
4 files changed
+14 -5

No files matched your search

+2 -2
View File
@@ -31,7 +31,7 @@ class DatabaseMigratorTests: GRDBTests {
assertNoError {
try migrator.migrate(dbQueue)
try dbQueue.inDatabase { db in
dbQueue.inDatabase { db in
XCTAssertTrue(db.tableExists("persons"))
XCTAssertTrue(db.tableExists("pets"))
}
@@ -43,7 +43,7 @@ class DatabaseMigratorTests: GRDBTests {
assertNoError {
try migrator.migrate(dbQueue)
try dbQueue.inDatabase { db in
dbQueue.inDatabase { db in
XCTAssertTrue(db.tableExists("persons"))
XCTAssertFalse(db.tableExists("pets"))
}
+1 -1
View File
@@ -428,7 +428,7 @@ class DatabaseTests: GRDBTests {
// Fetching rows and values:
try dbQueue.inDatabase { db in
dbQueue.inDatabase { db in
for row in db.fetchRows("SELECT * FROM persons") {
// Leverage Swift type inference
let name: String? = row.value(atIndex: 1)
+10
View File
@@ -39,6 +39,16 @@ public class DatabaseQueue {
}
}
public func inDatabase(block: (db: Database) -> Void) {
guard databaseQueueID != dispatch_get_specific(DatabaseQueue.databaseQueueIDKey) else {
fatalError("inDatabase(_:) was called reentrantly on the same queue, which would lead to a deadlock")
}
dispatch_sync(queue) { () -> Void in
block(db: self.database)
}
}
public func inDatabase<R>(block: (db: Database) -> R) -> R {
guard databaseQueueID != dispatch_get_specific(DatabaseQueue.databaseQueueIDKey) else {
fatalError("inDatabase(_:) was called reentrantly on the same queue, which would lead to a deadlock")
+1 -2
View File
@@ -66,7 +66,7 @@ try dbQueue.inTransaction { db in
// Fetching rows and values:
try dbQueue.inDatabase { db in
dbQueue.inDatabase { db in
for row in db.fetchRows("SELECT * FROM persons") {
// Leverage Swift type inference
let name: String? = row.value(atIndex: 1)
@@ -94,5 +94,4 @@ let names = dbQueue.inDatabase { db in
db.fetchValues("SELECT name FROM persons ORDER BY name", type: String.self).map { $0! }
}
// names is [String]: ["Arthur", "Barbara"]
```