Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Fix reading boolean values.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejtrybilo committed Oct 18, 2016
1 parent 7b372ed commit bd882ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

2 changes: 1 addition & 1 deletion Sources/PostgreSQL/Node+Oid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension Node {
case .float4, .float8, .numeric:
self = .number(.double(Double(value) ?? 0))
case .bool:
self = .bool((value == "true") ? true : false)
self = .bool((value == "t") ? true : false)
case .unknown:
self = .null
}
Expand Down
11 changes: 7 additions & 4 deletions Tests/PostgreSQLTests/PostgreSQLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,31 @@ class PostgreSQLTests: XCTestCase {
func testTables() {
do {
try postgreSQL.execute("DROP TABLE IF EXISTS foo")
try postgreSQL.execute("CREATE TABLE foo (bar INT, baz VARCHAR(16))")
try postgreSQL.execute("INSERT INTO foo VALUES (42, 'Life')")
try postgreSQL.execute("INSERT INTO foo VALUES (1337, 'Elite')")
try postgreSQL.execute("INSERT INTO foo VALUES (9, NULL)")
try postgreSQL.execute("CREATE TABLE foo (bar INT, baz VARCHAR(16), bla BOOLEAN)")
try postgreSQL.execute("INSERT INTO foo VALUES (42, 'Life', true)")
try postgreSQL.execute("INSERT INTO foo VALUES (1337, 'Elite', false)")
try postgreSQL.execute("INSERT INTO foo VALUES (9, NULL, true)")

if let resultBar = try postgreSQL.execute("SELECT * FROM foo WHERE bar = 42").first {
XCTAssertEqual(resultBar["bar"]?.int, 42)
XCTAssertEqual(resultBar["baz"]?.string, "Life")
XCTAssertEqual(resultBar["bla"]?.bool, true)
} else {
XCTFail("Could not get bar result")
}

if let resultBaz = try postgreSQL.execute("SELECT * FROM foo where baz = 'Elite'").first {
XCTAssertEqual(resultBaz["bar"]?.int, 1337)
XCTAssertEqual(resultBaz["baz"]?.string, "Elite")
XCTAssertEqual(resultBaz["bla"]?.bool, false)
} else {
XCTFail("Could not get baz result")
}

if let resultBaz = try postgreSQL.execute("SELECT * FROM foo where bar = 9").first {
XCTAssertEqual(resultBaz["bar"]?.int, 9)
XCTAssertEqual(resultBaz["baz"]?.string, nil)
XCTAssertEqual(resultBaz["bla"]?.bool, true)
} else {
XCTFail("Could not get null result")
}
Expand Down

0 comments on commit bd882ab

Please sign in to comment.