Skip to content

Commit

Permalink
Merge pull request #11 from sroebert/bugfix/utf8-binding
Browse files Browse the repository at this point in the history
Fixed correct utf8 length when binding string
  • Loading branch information
tanner0101 authored Oct 24, 2016
2 parents 49288db + 964470b commit 45ca240
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/SQLite/SQLite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ extension SQLite {
}

public func bind(_ value: String) throws {
let strlen = Int32(value.utf8CString.count)
let strlen = Int32(value.utf8.count)
if sqlite3_bind_text(pointer, nextBindPosition, value, strlen, SQLITE_TRANSIENT) != SQLITE_OK {
throw SQLiteError.bind(database.errorMessage)
}
Expand Down
13 changes: 9 additions & 4 deletions Tests/SQLiteTests/SQLite3Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ class SQLite3Tests: XCTestCase {
try _ = database.execute("INSERT INTO `foo` VALUES(?)") { statement in
try statement.bind(unicode)
}

if let results = try database.execute("SELECT * FROM `foo`").first {
XCTAssertEqual(results.data["bar"], unicode)
}

let selectAllResults = try database.execute("SELECT * FROM `foo`").first
XCTAssertNotNil(selectAllResults)
XCTAssertEqual(selectAllResults!.data["bar"], unicode)

let selectWhereResults = try database.execute("SELECT * FROM `foo` WHERE bar = '\(unicode)'").first
XCTAssertNotNil(selectWhereResults)
XCTAssertEqual(selectWhereResults!.data["bar"], unicode)

} catch {
XCTFail(error.localizedDescription)
}
Expand Down

0 comments on commit 45ca240

Please sign in to comment.