Merge branch 'master' into Swift2.2

This commit is contained in:
Gwendal Roué committed 2016-03-21 23:09:02 +01:00
commit a6af89755d
6 files changed
+53 -8

No files matched your search

+7
View File
@@ -1,6 +1,13 @@
Release Notes
=============
## Next version
**New**
- `Row` adopts Equatable
## 0.51.2
Released March 14, 2016
+26 -1
View File
@@ -629,8 +629,33 @@ extension Row : CollectionType {
}
}
extension Row : Equatable { }
// MARK: - CustomStringConvertible
/// Returns true if and only if both rows have the same columns and values, in
/// the same order. Columns are compared in a case-sensitive way.
public func ==(lhs: Row, rhs: Row) -> Bool {
if lhs === rhs {
return true
}
guard lhs.count == rhs.count else {
return false
}
var lgen = lhs.generate()
var rgen = rhs.generate()
while let (lcol, lval) = lgen.next(), let (rcol, rval) = rgen.next() {
guard lcol == rcol else {
return false
}
guard lval == rval else {
return false
}
}
return true
}
/// Row adopts CustomStringConvertible.
extension Row: CustomStringConvertible {
+1 -1
View File
@@ -59,7 +59,7 @@ struct Migration {
//
// Let's turn any violation into an SQLITE_CONSTRAINT
// error, and rollback the transaction.
throw DatabaseError(code: SQLITE_CONSTRAINT, message: "FOREIGN KEY constraint failed", sql: "PRAGMA foreign_key_check", arguments: nil)
throw DatabaseError(code: SQLITE_CONSTRAINT, message: "FOREIGN KEY constraint failed", sql: nil, arguments: nil)
}
// > 11. Commit the transaction started in step 2.
+1 -1
View File
@@ -410,7 +410,7 @@ You can fetch database rows, plain values, and custom models aka "records".
**Rows** are the raw results of SQL queries:
```swift
for row in Row.fetchAll(db, "SELECT * FROM wines") {
for row in Row.fetch(db, "SELECT * FROM wines") {
let name: String = row.value(named: "name")
let color: Color = row.value(named: "color")
print(name, color)
+2
View File
@@ -1,3 +1,5 @@
- [ ] Write an app like http://www.appcoda.com/swiftydb/ ?
- [ ] Since commit e6010e334abdf98eb9f62c1d6abbb2a9e8cd7d19, one can not use the raw SQLite API without importing the SQLite module for the platform. We need to document that.
- [ ] Read https://sqlite.org/sharedcache.html
- [ ] Query builder
- [ ] SELECT readers.*, books.* FROM ... JOIN ...
@@ -110,20 +110,31 @@ class DatabaseMigratorTests : GRDBTestCase {
do {
try migrator.migrate(dbQueue)
XCTFail("Expected error")
} catch {
} catch let error as DatabaseError {
// Migration 1 and 2 should be committed.
// Migration 3 should not be committed.
XCTAssertEqual(error.code, 19) // SQLITE_CONSTRAINT
XCTAssertEqual(error.message!, "FOREIGN KEY constraint failed")
XCTAssertTrue(error.sql == nil)
XCTAssertEqual(error.description, "SQLite error 19: FOREIGN KEY constraint failed")
// Arthur inserted (migration 1), Barbara (migration 3) not inserted.
let rows = dbQueue.inDatabase { db in
Row.fetchAll(db, "SELECT * FROM persons")
}
var rows = Row.fetchAll(dbQueue, "SELECT * FROM persons")
XCTAssertEqual(rows.count, 1)
let row = rows.first!
var row = rows.first!
XCTAssertEqual(row.value(named: "name") as String, "Arthur")
// persons table has no "tmp" column (migration 2)
XCTAssertEqual(Array(row.columnNames), ["id", "name"])
// Bobby inserted (migration 1), not deleted by migration 2.
rows = Row.fetchAll(dbQueue, "SELECT * FROM pets")
XCTAssertEqual(rows.count, 1)
row = rows.first!
XCTAssertEqual(row.value(named: "name") as String, "Bobby")
} catch {
XCTFail("Error: \(error)")
}
}
}