stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.73k stars 1.57k forks source link

Crash when FTS searching with symbols/special characters #855

Closed erikbye closed 3 years ago

erikbye commented 6 years ago

I use FTS5 and I get a crash when attempting to search with various symbols, for instance, equal symbol (=).

Error message: Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: fts5: syntax error near "=" (code: 1)

Same thing with forward and backslash: Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: fts5: syntax error near "\" (code: 1)

File: Statement.swift

extension FailableIterator {
    public func next() -> Element? {
        return try! failableNext()
    }
}

My code:

let fts_results = DBManager.shared.cliptext_virtual.filter(DBManager.shared.cliptext_virtual.match("clip_text: \(searchString)*"))

I also tried without the variable searchString. Just "clip_text: =", escaping the = sign, wrapping it in single quotes, etc.

If I write the query as such: .match("clip_text: \"\(searchString)\"*")) I no longer get a crash when searching for =, but I don't get a match either, only for words.

bindings: [Optional("clip_text: \"=\"*")]))

How should I go about searching for an exact phrase, containing characters like = and /? Say, the phrase "sum= /"

SQLite.swift version: 0.11.5

ghost commented 4 years ago

Any news about this?

BirkhoffLee commented 3 years ago

Same in here, please update.

jberkel commented 3 years ago

The input is not automatically you quoted, you need to do this yourself. See #305