Skip to content

Commit

Permalink
Remove unnecessary NSString bridge. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen authored Nov 23, 2023
1 parent 6218a81 commit af18d13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/Hotenka/HotenkaChineseConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public class HotenkaChineseConverter {
public func query(dict dictType: DictType, key searchKey: String) -> String? {
guard ptrSQL != nil else { return dict[dictType.rawKeyString]?[searchKey] }
let sqlQuery = "SELECT * FROM DATA_HOTENKA WHERE dict=\(dictType.rawValue) AND theKey='\(searchKey)';"
sqlite3_prepare_v2(ptrSQL, (sqlQuery as NSString).utf8String, -1, &ptrStatement, nil)
sqlite3_prepare_v2(ptrSQL, sqlQuery, -1, &ptrStatement, nil)
// 此處只需要用到第一筆結果。
while sqlite3_step(ptrStatement) == SQLITE_ROW {
guard let rawValue = sqlite3_column_text(ptrStatement, 2) else { continue }
Expand Down
10 changes: 5 additions & 5 deletions Tests/HotenkaTests/HotenkaTests_SQLite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension HotenkaTests {
"HOTENKA: SQLite Database Initialization Error."
)
XCTAssertTrue(
sqlite3_exec(ptrSQL, ("PRAGMA synchronous = OFF;" as NSString).utf8String, nil, nil, nil) == SQLITE_OK,
sqlite3_exec(ptrSQL, "PRAGMA synchronous = OFF;", nil, nil, nil) == SQLITE_OK,
"HOTENKA: SQLite synchronous OFF failed."
)

Expand All @@ -63,11 +63,11 @@ extension HotenkaTests {
"""

XCTAssertTrue(
sqlite3_exec(ptrSQL, (sqlMakeTableHotenka as NSString).utf8String, nil, nil, nil) == SQLITE_OK,
sqlite3_exec(ptrSQL, sqlMakeTableHotenka, nil, nil, nil) == SQLITE_OK,
"HOTENKA: SQLite Table Creation Failed."
)

assert(sqlite3_exec(ptrSQL, ("begin;" as NSString).utf8String, nil, nil, nil) == SQLITE_OK)
assert(sqlite3_exec(ptrSQL, "begin;", nil, nil, nil) == SQLITE_OK)

var ptrStatement: OpaquePointer?

Expand All @@ -77,7 +77,7 @@ extension HotenkaTests {
let sqlInsertion = "INSERT INTO DATA_HOTENKA (dict, theKey, theValue) VALUES (\(dictID), '\(key)', '\(value)')"
assert(
sqlite3_prepare_v2(
ptrSQL, (sqlInsertion as NSString).utf8String, -1, &ptrStatement, nil
ptrSQL, sqlInsertion, -1, &ptrStatement, nil
) == SQLITE_OK,
"HOTENKA: Failed from preparing: \(sqlInsertion)"
)
Expand All @@ -88,7 +88,7 @@ extension HotenkaTests {
}
}

assert(sqlite3_exec(ptrSQL, ("commit;" as NSString).utf8String, nil, nil, nil) == SQLITE_OK)
assert(sqlite3_exec(ptrSQL, "commit;", nil, nil, nil) == SQLITE_OK)

sqlite3_close_v2(ptrSQL)
}
Expand Down

0 comments on commit af18d13

Please sign in to comment.