Skip to content

Do not use .characters on Strings #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SQLite/Core/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public final class Connection {
} else if let result = result as? Int64 {
sqlite3_result_int64(context, result)
} else if let result = result as? String {
sqlite3_result_text(context, result, Int32(result.characters.count), SQLITE_TRANSIENT)
sqlite3_result_text(context, result, Int32(result.count), SQLITE_TRANSIENT)
} else if result == nil {
sqlite3_result_null(context)
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SQLite/Typed/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension Expressible {
public func asSQL() -> String {
let expressed = expression
var idx = 0
return expressed.template.characters.reduce("") { template, character in
return expressed.template.reduce("") { template, character in
let transcoded: String

if character == "?" {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SQLite/Typed/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ extension Connection {
private func columnNamesForQuery(_ query: QueryType) throws -> [String: Int] {
var (columnNames, idx) = ([String: Int](), 0)
column: for each in query.clauses.select.columns {
var names = each.expression.template.characters.split { $0 == "." }.map(String.init)
var names = each.expression.template.split { $0 == "." }.map(String.init)
let column = names.removeLast()
let namespace = names.joined(separator: ".")

Expand Down
2 changes: 1 addition & 1 deletion Sources/SQLite/Typed/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ extension Table {
fileprivate func indexName(_ columns: [Expressible]) -> Expressible {
let string = (["index", clauses.from.name, "on"] + columns.map { $0.expression.template }).joined(separator: " ").lowercased()

let index = string.characters.reduce("") { underscored, character in
let index = string.reduce("") { underscored, character in
guard character != "\"" else {
return underscored
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SQLiteTests/ConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class ConnectionTests : SQLiteTestCase {
}

func test_interrupt_interruptsLongRunningQuery() {
try! InsertUsers("abcdefghijklmnopqrstuvwxyz".characters.map { String($0) })
try! InsertUsers("abcdefghijklmnopqrstuvwxyz".map { String($0) })
db.createFunction("sleep") { args in
usleep(UInt32((args[0] as? Double ?? Double(args[0] as? Int64 ?? 1)) * 1_000_000))
return nil
Expand Down